]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF29138] : measure CPU/Mem even in OutOfProcess mode
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 23 Apr 2024 07:23:56 +0000 (09:23 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 23 Apr 2024 07:23:56 +0000 (09:23 +0200)
src/Container/SALOME_PyNode.py
src/Launcher/Test/testCrashProofContainer.py

index ed19bb3063796f25742fbb73cd58f52d2f94270e..e7f3cb62587864d177b96e5cb75e0e0f607d1c4b 100644 (file)
@@ -528,12 +528,21 @@ def CPUMemoryMonitoring( intervalInMs, outFileName = None ):
       f.write("""import psutil
 pid = {}
 process = psutil.Process( pid )
+def getChargeOf( p ):
+  a,b = p.cpu_percent(), p.memory_info().rss
+  try:
+    for c in p.children():
+      a += c.cpu_percent(interval=0.01) ; b += c.memory_info().rss
+  except:
+    pass
+  return a,b
 import time
 with open("{}","a") as f:
   f.write( "{{}}\\n".format( "{}" ) )
   while True:
-    f.write( "{{}}\\n".format( str( process.cpu_percent() ) ) )
-    f.write( "{{}}\\n".format( str( process.memory_info().rss  ) ) )
+    cpu,mem_rss = getChargeOf( process )
+    f.write( "{{}}\\n".format( str( cpu ) ) )
+    f.write( "{{}}\\n".format( str( mem_rss  ) ) )
     f.flush()
     time.sleep( {} / 1000.0 )
 """.format(pid, tempOutFile, intervalInMs, intervalInMs))
index 027cf790473a22590bd6eb9c96b52b53621a6274..7bad4740753401db1259c42f099aef06f5c90dcd 100644 (file)
@@ -47,6 +47,12 @@ j = 8 * i
 my_log_4_this_session.addFreestyleAndFlush( ("a",777) ) # to check that hidden var is still accessible
 """
 
+heatCPUCode = """import KernelBasis
+nbcore = 3
+cst = KernelBasis.GetTimeAdjustmentCst()
+KernelBasis.HeatMarcel(5 * nbcore * cst,nbcore)
+j = 8*i"""
+
 class testPerfLogManager1(unittest.TestCase):
     def test0(self):
         """
@@ -116,6 +122,37 @@ class testPerfLogManager1(unittest.TestCase):
                 os.unlink( zeFile )
         cont.Shutdown()
 
+    def test2(self):
+        """
+        Aim of test is to check that CPU/mem retrieved in log is OK even in OutOfProcessNoReplay mode.
+        """
+        salome.salome_init()
+        salome.logm.clear()
+        assert(isinstance(KernelBasis.GetAllPyExecutionModes(),tuple))
+        KernelBasis.SetPyExecutionMode("OutOfProcessNoReplay") # the aim of test is here
+        hostname = "localhost"
+        PROXY_THRES = "-1"
+        #
+        salome.cm.SetOverrideEnvForContainersSimple(env = [("SALOME_BIG_OBJ_ON_DISK_THRES",PROXY_THRES)])
+        salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 250 )
+        cp = pylauncher.GetRequestForGiveContainer(hostname,"container_cpu_mem_out_process_test")
+        cont = salome.cm.GiveContainer(cp)
+        poa = salome.orb.resolve_initial_references("RootPOA")
+        obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["i"],{"i": 3} ) )) ; id_o = poa.activate_object(obj) ; refPtr = poa.id_to_reference(id_o)
+        pyscript2 = cont.createPyScriptNode("testScript3",heatCPUCode)
+        pyscript2.executeFirst(refPtr)
+        ret = pyscript2.executeSecond(["j"])
+        ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() )
+        self.assertEqual(ret,24)
+        pyscript2.UnRegister()
+        a = salome.logm.NaiveFetch()
+        cpu_mem_to_test = a[0][1][0].get()._cpu_mem_during_exec.data # normally even in OutOfProcessNoReplay mode the CPU must report somehing greater than 100
+        self.assertGreater(len(cpu_mem_to_test),10) # 5 second of run 250 ms of interval between measures -> 20. In case of problem in HeatMarcel -> 10
+        logging.debug("CPU mem measured (even in OutOfProcessNoReplay) : {}".format(cpu_mem_to_test))
+        greater_than_100 = [a for a,b in cpu_mem_to_test if a > 100]
+        self.assertGreater(len(greater_than_100),1) # At minimum one measure must report CPU load > 100%
+        cont.Shutdown()
+
 if __name__ == '__main__':
     from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose
     salome.standalone()