]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF29150] : ease concurent access to logm during processing
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 10 Jan 2024 07:32:04 +0000 (08:32 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 10 Jan 2024 07:32:04 +0000 (08:32 +0100)
src/KERNEL_PY/__init__.py
src/Launcher/Test/testPerfLogManager1.py

index f163a808596d75de6179f4db4866385e43e6380f..1aad6951641fd56bc766eedd68164dc873fa93a4 100644 (file)
@@ -271,7 +271,6 @@ def salome_init_without_session(path=None, embedded=False, iorfakensfile=None):
     type(logm).NaiveFetch = LogManagerNaiveFetch
     type(logm).Fetch = LogManagerFetch
     type(logm).DumpInFile = LogManagerDumpInFile
-    type(logm).LoadFromFile = LogManagerLoadFromFile
     type(logm).LaunchMonitoringDumpFile = LogManagerLaunchMonitoringDumpFile
     type(logm).GetLatestMonitoringDumpFile = LogManagerGetLatestMonitoringDumpFile
     #
@@ -474,11 +473,6 @@ def LogManagerDumpInFile(self,fileName,clearMemory = False):
     with open(fileName,"wb") as f:
         f.write( self.getAllStruct( clearMemory ) )
 
-def LogManagerLoadFromFile(self,fileName):
-    from SALOME_ContainerHelper import unserializeLogManager
-    with open(fileName,"rb") as f:
-        data = f.read()
-    return unserializeLogManager( data )
 
 class LogManagerLaunchMonitoringFileCtxMgr:
     def __init__(self, intervalInMs, outFileName):
@@ -543,6 +537,31 @@ while(True):
     pid = KernelBasis.LaunchMonitoring( tempPyFile )
     return SALOME_PyNode.MonitoringInfo(pyFileName,None,pid)
 
+def LogManagerLoadFromFile(fileName):
+    from SALOME_ContainerHelper import unserializeLogManager
+    with open(fileName,"rb") as f:
+        data = f.read()
+    return unserializeLogManager( data )
+
+def LogManagerLoadFromIORFile( iorFile ):
+    global orb
+    def LoadAndWrite(logm,tempFileName):
+        import SALOME_PyNode
+        print( tempFileName )
+        logm.putStructInFileAtomic( False, tempFileName )
+        tempFileAuto = SALOME_PyNode.FileDeleter( tempFileName )
+        ret = LogManagerLoadFromFile( tempFileAuto.filename )
+        return ret
+    with open(iorFile,"r") as f:
+        ior = f.read()
+    import Engines
+    import tempfile
+    salome_init_without_session()
+    logm = orb.string_to_object( ior )
+    with tempfile.NamedTemporaryFile(dir=os.path.expanduser("~")) as f:
+        tempFileName = f.name
+    return LoadAndWrite( logm, tempFileName )
+
 def LogManagerGetLatestMonitoringDumpFile(self):
     import shutil
     import logging
index 739376a8eef52624812a0dc3b9c56fefc16e2941..df06f726baa7f000bc5ad0fbc9fb65188e0a00ff 100644 (file)
@@ -69,6 +69,7 @@ class testPerfLogManager1(unittest.TestCase):
         with tempfile.TemporaryDirectory() as tmpdirnameMonitoring:
             monitoringFile = os.path.join( str( tmpdirnameMonitoring ), "zeHtop.pckl" )
             monitoringFileTwo = os.path.join( str( tmpdirnameMonitoring ), "zeHtopTwo.pckl" )
+            iorLogm = os.path.join( str( tmpdirnameMonitoring ), "logm.ior" )
             logging.debug("Monitoring file : {}".format(monitoringFile))
             with tempfile.TemporaryDirectory() as tmpdirname:
                 with salome.LogManagerLaunchMonitoringFileCtxMgr(250,monitoringFile) as monitoringParams:
@@ -156,12 +157,12 @@ time.sleep(1)
                     #
                     fname = os.path.join(str( tmpdirname ),"perf.log")
                     salome.logm.DumpInFile( fname )
-                    logManagerInst0 = salome.logm.LoadFromFile( fname )
+                    logManagerInst0 = salome.LogManagerLoadFromFile( fname )
                     logging.debug( logManagerInst0[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
                     logManagerInst = salome.logm.Fetch(True)
                     logManagerInst2 = salome.logm.Fetch(True)
                     salome.logm.putStructInFileAtomic(False,monitoringFileTwo)
-                    logging.debug( salome.logm.LoadFromFile(monitoringFileTwo)[0][1][0].get() )
+                    logging.debug( salome.LogManagerLoadFromFile(monitoringFileTwo)[0][1][0].get() )
                     logging.debug( logManagerInst[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
                     self.assertTrue( logManagerInst2[0][1][0].get() is None )
                     self.assertTrue( logManagerInst[0][1][1].get()._output_hdd_mem._data[0]._file_name == fileNamesProxyOut2[0] )
@@ -172,7 +173,7 @@ time.sleep(1)
                     pass
                 #self.assertEqual(monitoringFileSafe, monitoringFile)
                 self.assertEqual( len( glob.glob("{}*".format(monitoringFile) ) ) , 1 )
-                logging.debug( salome.logm.LoadFromFile(monitoringFile)[0][1][0].get() )
+                logging.debug( salome.LogManagerLoadFromFile(monitoringFile)[0][1][0].get() )
                 del monitoringParams
                 import gc ; gc.collect()
                 self.assertFalse( os.path.exists(pyFileContainingCodeOfMonitoring) )