* scicos_log() support options parameters to retrieve model statistics. 09/19309/5
Clément DAVID [Mon, 26 Jun 2017 19:48:43 +0000 (21:48 +0200)]
Change-Id: I729ac5d13114b9da1ff35726d9cfd62c559f0ecd

scilab/CHANGES.md
scilab/modules/scicos/sci_gateway/cpp/sci_scicos_log.cpp
scilab/modules/scicos/tests/unit_tests/scicos_log.tst [new file with mode: 0644]
scilab/modules/xcos/help/en_US/scilab_utilities_functions/scicos_log.xml

index 72ec64c..2b400ca 100644 (file)
@@ -92,6 +92,7 @@ Data Structures
 Xcos
 ----
 
+* scicos_log() support options parameters to retrieve model statistics.
 
 API modification
 ----------------
index 395c404..165b146 100644 (file)
@@ -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<ScicosID> objects;
+        std::vector<ScicosID> 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 (file)
index 0000000..f0f0021
--- /dev/null
@@ -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"), []);
+
+
index 1c395f8..2f30ea6 100644 (file)
@@ -9,6 +9,7 @@
         <synopsis>
             log=scicos_log(log);
             log=scicos_log(log, msg);
+            refCounters=scicos_log("refCounters");
         </synopsis>
     </refsynopsisdiv>
     <refsection>
@@ -17,7 +18,7 @@
             <varlistentry>
                 <term>log</term>
                 <listitem>
-                    <para>String, logger value. The supported values are : "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"</para>
+                    <para>String, logger value. The supported log modifiers are : "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"</para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                     </para>
                 </listitem>
             </varlistentry>
+            <varlistentry>
+                <term>refCounters</term>
+                <listitem>
+                    <para>a double vector, with a [uid, kind, reference counter] line per object.</para>
+                </listitem>
+            </varlistentry>
         </variablelist>
     </refsection>
     <refsection>
@@ -35,6 +42,9 @@
         <para>
             This function implements a logger for <literal>scicos</literal> operation. This function lets the user choose the right level of information to print while loading a model, compiling and simulating it.
         </para>
+        <para>
+            It is also used to produce statistics or global analysis for specific flags. For exemple, passing <pre>"refCounters"</pre> will return uid, kind and reference count of all objects.
+        </para>
     </refsection>
     <refsection>
         <title>Examples</title>
 scicos_log("TRACE"),
 scicos_log("TRACE", "this is a trace message");
  ]]></programlisting>
+        <programlisting role="example"><![CDATA[
+loadXcosLibs();
+scicos_log("refCounters")
+b = scicos_block();
+scicos_log("refCounters")
+ ]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
@@ -49,6 +65,12 @@ scicos_log("TRACE", "this is a trace message");
             <member>
                 <link linkend="scicos_debug">scicos_debug</link>
             </member>
+            <member>
+                <link linkend="scicos_block">scicos_block</link>
+            </member>
+            <member>
+                <link linkend="loadXcosLibs">loadXcosLibs</link>
+            </member>
         </simplelist>
     </refsection>
 </refentry>