Salome HOME
[EDF29576] : log cleaning + driver python enhancement
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 22 Feb 2024 13:44:28 +0000 (14:44 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 22 Feb 2024 13:44:28 +0000 (14:44 +0100)
src/runtime/SalomeContainerHelper.cxx
src/yacsloader/driver.py

index 4a6e9f4a202f7476615b0de754db6a4046838b3b..56c33016cbf3c20060978e6c28d8902d9f1bb707 100644 (file)
@@ -20,7 +20,8 @@
 #include "SalomeContainerHelper.hxx"
 
 #include "ServiceNode.hxx"
-#include "YacsTrace.hxx"
+
+#include "utilities.h"
 
 #include <sstream>
 #include <iostream>
@@ -92,15 +93,13 @@ void SalomeContainerMonoHelper::shutdown()
     return ;
   try
   {
-      DEBTRACE("shutdown SALOME container: " );
       CORBA::String_var containerName=_trueCont->name();
-      DEBTRACE(containerName);
+      INFO_MESSAGE("shutdown SALOME container: " << containerName);
       _trueCont->Shutdown();
-      std::cerr << "shutdown SALOME container: " << containerName << std::endl;
   }
   catch(...)
   {
-      DEBTRACE("Unknown exception ignored." );
+      ERROR_MESSAGE("Unknown exception ignored." );
   }
   _trueCont=Engines::Container::_nil();
 }
@@ -201,19 +200,17 @@ void SalomeContainerMultiHelper::shutdown()
   {
     try
     {
-        DEBTRACE("shutdown SALOME container: " );
         CORBA::String_var containerName=it->second->name();
-        DEBTRACE(containerName);
+        INFO_MESSAGE("shutdown SALOME container: " << containerName);
         it->second->Shutdown();
-        std::cerr << "shutdown SALOME container: " << containerName << std::endl;
     }
     catch(CORBA::Exception&)
     {
-        DEBTRACE("Unexpected CORBA failure detected." );
+        ERROR_MESSAGE("Unexpected CORBA failure detected." );
     }
     catch(...)
     {
-        DEBTRACE("Unknown exception ignored." );
+        ERROR_MESSAGE("Unknown exception ignored." );
     }
   }
   _containersForTasks.clear();
@@ -222,19 +219,18 @@ void SalomeContainerMultiHelper::shutdown()
     {
       try
       {
-          DEBTRACE("shutdown SALOME container: " );
           CORBA::String_var containerName=it->second->name();
-          DEBTRACE(containerName);
+          INFO_MESSAGE("shutdown SALOME container: " << containerName);
           it->second->Shutdown();
           std::cerr << "shutdown SALOME container: " << containerName << std::endl;
       }
       catch(CORBA::Exception&)
       {
-          DEBTRACE("Unexpected CORBA failure detected." );
+          ERROR_MESSAGE("Unexpected CORBA failure detected." );
       }
       catch(...)
       {
-          DEBTRACE("Unknown exception ignored." );
+          ERROR_MESSAGE("Unknown exception ignored." );
       }
     }
   _containersForComponents.clear();
index e41f9619425c2aecee579c67624e898ac5dacbc5..2670af71218949214c6a464d937224b1b415f256 100644 (file)
 import loader
 import SALOMERuntime
 import salome
+import logging
+
+"""
+struct arguments
+{
+  char *args[1];
+  int display = 0;
+  int verbose = 0;
+  int stop = 0;
+  std::string dumpErrorFile;
+  std::string finalDump;
+  int dump = 0;
+  std::string xmlSchema;
+  std::string loadState;
+  int shutdown = 10; # done
+  int reset = 0;
+  int killPort = 0;
+  bool squeezeMemory = true;
+  std::list<std::string> init_ports;
+};
+
+    {"display",         'd', "level", 0,                   "Display dot files: 0=never to 3=very often (default 0)"},
+    {"verbose",         'v', 0,       0,                   "Produce verbose output" },
+    {"stop-on-error",   's', 0,       0,                   "Stop on first error" },
+    {"dump-on-error",   'e', "file",  OPTION_ARG_OPTIONAL, "Stop on first error and dump state"},
+    {"dump-final",      'f', "file",  OPTION_ARG_OPTIONAL, "dump final state"},
+    {"dump",            'g', "nbsec", OPTION_ARG_OPTIONAL, "dump state"},
+    {"load-state",      'l', "file",  0,                   "Load State from a previous partial execution"},
+    {"save-xml-schema", 'x', "file",  OPTION_ARG_OPTIONAL, "dump xml schema"},
+    {"shutdown",        't', "level", 0,                   "Shutdown the schema: 0=no shutdown to 3=full shutdown (default 1)"},
+    {"reset",           'r', "level", 0,                   "Reset the schema before execution: 0=nothing, 1=reset error nodes to ready state (default 0)"},
+    {"kill-port",       'k', "port",  0,                   "Kill Salome application running on the specified port if the driver process is killed (with SIGINT or SIGTERM)"},
+    {"init_port",       'i', "value", OPTION_ARG_OPTIONAL, "Initialisation value of a port, specified as bloc.node.port=value."},
+    {"donotsqueeze",    'z', "value", 0,                   "Desactivate squeeze memory optimization."},
+
+"""
 
 my_runtime_yacs = None
 
@@ -30,15 +66,19 @@ def initializeSALOME():
     import SALOMERuntime
     global my_runtime_yacs
     if my_runtime_yacs:
-        return
+      return
     salome.salome_init()
-    SALOMERuntime.RuntimeSALOME.setRuntime()
+    flags = SALOMERuntime.RuntimeSALOME.UsePython + SALOMERuntime.RuntimeSALOME.UseCorba + SALOMERuntime.RuntimeSALOME.UseXml + SALOMERuntime.RuntimeSALOME.UseCpp + SALOMERuntime.RuntimeSALOME.UseSalome
+    SALOMERuntime.RuntimeSALOME.setRuntime( flags )
     my_runtime_yacs = SALOMERuntime.getSALOMERuntime()
+    anIOR = salome.orb.object_to_string ( salome.modulcat )
+    aCatalog = my_runtime_yacs.loadCatalog( "session", anIOR )
+    my_runtime_yacs.addCatalog( aCatalog )
 
 def SALOMEInitializationNeeded(func):
     def decaratedFunc(*args,**kwargs):
-        initializeSALOME()
-        return func(*args,**kwargs)
+      initializeSALOME()
+      return func(*args,**kwargs)
     return decaratedFunc
 
 @SALOMEInitializationNeeded
@@ -55,9 +95,30 @@ def loadGraph( xmlFileName ):
     """
     l=loader.YACSLoader()
     p=l.load( xmlFileName )
-    print(type(p))
     return p
 
+def patchGraph( proc, squeezeMemory):
+    """
+    Args:
+    -----
+
+    proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated
+    squeezeMemory ( bool ) : squeezememory to be activated
+
+    Returns
+    -------
+
+
+
+    """
+    if squeezeMemory:
+      logging.info("SqueezeMemory requested -> update proc")
+      allNodes = proc.getAllRecursiveNodes()
+      for node in allNodes:
+        if isinstance(proc,SALOMERuntime.PythonNode):
+          node.setSqueezeStatus( True )
+
+
 @SALOMEInitializationNeeded
 def executeGraph( proc ):
     """
@@ -72,16 +133,37 @@ def executeGraph( proc ):
     ex.RunW(proc,0)
     pass
 
-def destroyElementsGeneratedByExecutionOfGraph():
-    salome.cm
+@SALOMEInitializationNeeded
+def destroyElementsGeneratedByExecutionOfGraph( proc, shutdown ):
+    """
+    Args:
+    -----
+
+    shutdown (int) : shutdown level
+
+    """
+    if shutdown < 999:
+      proc.shutdown(shutdown)
+    salome.dsm.shutdownScopes()
     my_runtime_yacs.fini( False )
 
 if __name__ == "__main__":
+    from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose
     import argparse
     parser = argparse.ArgumentParser()
-    parser.add_argument('xmlfilename',help="XML file containing YACS schema to be executed")
+    parser.add_argument('xmlfilename',help = "XML file containing YACS schema to be executed")
+    parser.add_argument("-v", "--verbose", dest = "verbose",help="Produce verbose output", action='store_true')
+    parser.add_argument("-kt", "--kerneltrace", dest = "kerneltrace",help="Produce verbose of SALOME/KERNEL", action='store_true')
+    parser.add_argument("--shutdown", dest = 'shutdown', type=int , default=1, help="Shutdown the schema: 0=no shutdown to 3=full shutdown")
+    parser.add_argument("-z","--donotsqueeze", dest = "donotsqueeze", help = "Desactivate squeeze memory optimization.", action='store_true')
     args = parser.parse_args()
+    #
+    if args.verbose:
+      setVerbose( args.kerneltrace )
+      setVerboseLevel(logging.INFO)
+      positionVerbosityOfLoggerRegardingState()
+    #
     proc = loadGraph( args.xmlfilename )
+    patchGraph( proc, not args.donotsqueeze)
     executeGraph( proc )
-    destroyElementsGeneratedByExecutionOfGraph()
-
+    destroyElementsGeneratedByExecutionOfGraph( proc, args.shutdown )