From 17a2e702a5223049f08f664991557913d8760137 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20DAVID?= Date: Mon, 26 Jun 2017 21:48:43 +0200 Subject: [PATCH] * scicos_log() support options parameters to retrieve model statistics. Change-Id: I729ac5d13114b9da1ff35726d9cfd62c559f0ecd --- scilab/CHANGES.md | 1 + .../scicos/sci_gateway/cpp/sci_scicos_log.cpp | 43 +++++++++++++++++- .../modules/scicos/tests/unit_tests/scicos_log.tst | 48 ++++++++++++++++++++ .../scilab_utilities_functions/scicos_log.xml | 24 +++++++++- 4 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 scilab/modules/scicos/tests/unit_tests/scicos_log.tst diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 72ec64c..2b400ca 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -92,6 +92,7 @@ Data Structures Xcos ---- +* scicos_log() support options parameters to retrieve model statistics. API modification ---------------- diff --git a/scilab/modules/scicos/sci_gateway/cpp/sci_scicos_log.cpp b/scilab/modules/scicos/sci_gateway/cpp/sci_scicos_log.cpp index 395c404..165b146 100644 --- a/scilab/modules/scicos/sci_gateway/cpp/sci_scicos_log.cpp +++ b/scilab/modules/scicos/sci_gateway/cpp/sci_scicos_log.cpp @@ -19,6 +19,7 @@ #include "types.hxx" #include "string.hxx" +#include "double.hxx" #include "mlist.hxx" #include "list.hxx" #include "function.hxx" @@ -77,6 +78,46 @@ types::Function::ReturnValue sci_scicos_log(types::typed_list &in, int _iRetCoun return types::Function::Error; } + /* + * specific usages : + */ + + // "refCounters" will return reference counters per object, per kind + if (std::wstring(L"refCounters") == strLevel->get(0)) + { + Controller controller; + + std::vector objects; + std::vector tmp; + + tmp = controller.getAll(BLOCK); + objects.insert(objects.end(), tmp.begin(), tmp.end()); + tmp = controller.getAll(DIAGRAM); + objects.insert(objects.end(), tmp.begin(), tmp.end()); + tmp = controller.getAll(LINK); + objects.insert(objects.end(), tmp.begin(), tmp.end()); + tmp = controller.getAll(ANNOTATION); + objects.insert(objects.end(), tmp.begin(), tmp.end()); + + types::Double* refCounts = new types::Double((int) objects.size(), 3); + + for (int i = 0; i < objects.size(); ++i) + { + model::BaseObject* o = controller.getObject(objects[i]); + + refCounts->set(i, 0, o->id()); + refCounts->set(i, 1, o->kind()); + refCounts->set(i, 2, o->refCount()); + } + + out.push_back(refCounts); + return types::Function::OK; + } + + /* + * default usage: log level setting + */ + enum LogLevel logLevel = LoggerView::indexOf(strLevel->get(0)); if (logLevel < 0) { @@ -88,7 +129,7 @@ types::Function::ReturnValue sci_scicos_log(types::typed_list &in, int _iRetCoun } buffer << LoggerView::toString(LOG_FATAL); - Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the set {%ls}.\n"), funame.data(), 1, buffer.str().data()); + Scierror(999, _("%s: Wrong value for input argument #%d: Must be one of %ls.\n"), funame.data(), 1, buffer.str().data()); return types::Function::Error; } diff --git a/scilab/modules/scicos/tests/unit_tests/scicos_log.tst b/scilab/modules/scicos/tests/unit_tests/scicos_log.tst new file mode 100644 index 0000000..f0f0021 --- /dev/null +++ b/scilab/modules/scicos/tests/unit_tests/scicos_log.tst @@ -0,0 +1,48 @@ +// ============================================================================= +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2017 - ESI Group - Clement David +// +// This file is distributed under the same license as the Scilab package. +// ============================================================================= + +// <-- CLI SHELL MODE --> +// <-- NO CHECK REF --> + +loadXcosLibs(); + +// check input value +for s=["FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"] + scicos_log(s); +end + +// check output value +assert_checkequal(scicos_log("TRACE"), "TRACE"); + + +// model objects + +// allocate a Block +o = scicos_block(); +assert_checkequal(scicos_log("refCounters"), [1 0 0]); +clear o; +assert_checkequal(scicos_log("refCounters"), []); + +// allocate a Diagram +scs_m = scicos_diagram(); +assert_checkequal(scicos_log("refCounters"), [2 1 0]); +clear scs_m; +assert_checkequal(scicos_log("refCounters"), []); + +// allocate a Link +o = scicos_link(); +assert_checkequal(scicos_log("refCounters"), [3 2 0]); +clear o; +assert_checkequal(scicos_log("refCounters"), []); + +// allocate an Annotation +o = TEXT_f("define"); +assert_checkequal(scicos_log("refCounters"), [4 3 0]); +clear o; +assert_checkequal(scicos_log("refCounters"), []); + + diff --git a/scilab/modules/xcos/help/en_US/scilab_utilities_functions/scicos_log.xml b/scilab/modules/xcos/help/en_US/scilab_utilities_functions/scicos_log.xml index 1c395f8..2f30ea6 100644 --- a/scilab/modules/xcos/help/en_US/scilab_utilities_functions/scicos_log.xml +++ b/scilab/modules/xcos/help/en_US/scilab_utilities_functions/scicos_log.xml @@ -9,6 +9,7 @@ log=scicos_log(log); log=scicos_log(log, msg); + refCounters=scicos_log("refCounters"); @@ -17,7 +18,7 @@ log - String, logger value. The supported values are : "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE" + String, logger value. The supported log modifiers are : "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE" @@ -28,6 +29,12 @@ + + refCounters + + a double vector, with a [uid, kind, reference counter] line per object. + + @@ -35,6 +42,9 @@ This function implements a logger for scicos operation. This function lets the user choose the right level of information to print while loading a model, compiling and simulating it. + + It is also used to produce statistics or global analysis for specific flags. For exemple, passing
"refCounters"
will return uid, kind and reference count of all objects. +
Examples @@ -42,6 +52,12 @@ scicos_log("TRACE"), scicos_log("TRACE", "this is a trace message"); ]]> + See also @@ -49,6 +65,12 @@ scicos_log("TRACE", "this is a trace message"); scicos_debug + + scicos_block + + + loadXcosLibs + -- 1.7.9.5