]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF29150] : WIP
authorAnthony Geay <anthony.geay@edf.fr>
Sun, 4 Feb 2024 16:46:03 +0000 (17:46 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Sun, 4 Feb 2024 16:46:03 +0000 (17:46 +0100)
src/Container/SALOME_PyNode.py
src/Launcher/Test/testPerfLogManager1.py

index 941c52fa2b25589ac1e928daa61d99de80623559..a82c2fc896448b9270da4379dece1fc5c1341e27 100644 (file)
@@ -452,7 +452,7 @@ def FileSystemMonitoring(intervalInMs, dirNameToInspect, outFileName = None):
     import logging
     import KernelBasis
     # outFileNameSave stores the content of outFileName during phase of dumping
-    with tempfile.NamedTemporaryFile(prefix=os.path.basename(dirNameToInspect2),dir=os.path.dirname(dirNameToInspect2)) as f:
+    with tempfile.NamedTemporaryFile(prefix="fs_monitor_",suffix=".txt") as f:
       outFileNameSave = f.name
     with tempfile.NamedTemporaryFile(prefix="fs_monitor_",suffix=".py") as f:
       tempPyFile = f.name
@@ -467,9 +467,10 @@ import os
 import time
 import datetime
 with open("{tempOutFile}","a") as f:
+  f.write( "{{}}\\n".format( "{dirNameToInspect2}" ) )
   while(True):
-    nbinodes = sp.check_output("{{}} | wc -l".format( " ".join(["find",os.path.dirname( "{dirNameToInspect2}" )]),  ), shell = True).decode().strip()
-    szOfDirStr = re.split("[\s]+",sp.check_output(["du","-sh",os.path.dirname( "{dirNameToInspect2}" )]).decode())[0]
+    nbinodes = sp.check_output("{{}} | wc -l".format( " ".join(["find","{dirNameToInspect2}"]),  ), shell = True).decode().strip()
+    szOfDirStr = re.split("[\s]+",sp.check_output(["du","-sh","{dirNameToInspect2}"]).decode())[0]
     f.write( "{{}}\\n".format( str( datetime.datetime.now().timestamp() ) ) )
     f.write( "{{}}\\n".format( str( nbinodes  ) ) )
     f.write( "{{}}\\n".format( str( szOfDirStr ) ) )
@@ -482,8 +483,7 @@ with open("{tempOutFile}","a") as f:
       outFileName = FileDeleter( tempOutFile )
     else:
       outFileName = FileHolder(outFileName)
-    pid = KernelBasis.LaunchMonitoring( tempPyFile )
-    return MonitoringInfo(pyFileName,outFileName,pid)
+    return MonitoringInfo(pyFileName,outFileName,None)
 
 def CPUMemoryMonitoring( intervalInMs, outFileName = None ):
   """
@@ -577,14 +577,44 @@ def ReadCPUMemInfo( monitoringInfo ):
   """
   return ReadCPUMemInfoInternal( monitoringInfo.outFileName.filename )
 
+class InodeSizeInfo:
+  def __init__(self, dirNameMonitored, timeStamps, nbInodes, volumeOfDir):
+    """
+    Args:
+    ----
+    timeStamps (list<datetimestruct>)
+    nbInodes (list<int>)
+    volumeOfDir (list<str>)
+    """
+    self._dir_name_monitored = dirNameMonitored
+    self._data = [(t,a,b) for t,a,b in zip(timeStamps,nbInodes,volumeOfDir)]
+  def __str__(self):
+    st = """Filename monitored : {self.dirNameMonitored}
+Data : ${self.data}
+""".format( **locals() )
+    return st
+  @property
+  def dirNameMonitored(self):
+    return self._dir_name_monitored
+  @property
+  def data(self):
+    """
+    list of triplets. First param of triplet is datetimestruct
+                                      Second param of triplet is #inodes.
+                                      Thirst param of triplet is size.
+    """
+    return self._data
+
 def ReadInodeSizeInfoInternal( fileName ):
   import datetime
+  import os
   with open(fileName, "r") as f:
     coarseData = [ elt.strip() for elt in f.readlines() ]
+  dirNameMonitored = coarseData[0] ; coarseData = coarseData[1:]
   tss = [ datetime.datetime.fromtimestamp( float(elt) ) for elt in coarseData[::3] ]
   nbInodes = [int(elt) for elt in coarseData[1::3]]
   volumeOfDir = coarseData[2::3]
-  return [(t,a,b) for t,a,b in zip(tss,nbInodes,volumeOfDir)]
+  return InodeSizeInfo(dirNameMonitored,tss,nbInodes,volumeOfDir)
 
 def ReadInodeSizeInfo( monitoringInfo ):
   """
@@ -596,9 +626,7 @@ def ReadInodeSizeInfo( monitoringInfo ):
 
   Returns
   -------
-    list<datetime,int,str> : list of triplets. First param of triplet is datetimestruct
-                                      Second param of triplet is #inodes.
-                                      Thirst param of triplet is size.
+    InodeSizeInfo
   """
   return ReadInodeSizeInfoInternal( monitoringInfo.outFileName.filename )
 
index d5e2163659b8079106ae1641239f84fc969a4a00..7df51a851918b4375c2b905f411f75db47e50a77 100644 (file)
@@ -68,7 +68,7 @@ class testPerfLogManager1(unittest.TestCase):
         salome.logm.clear()
         #PROXY_THRES = "-1"
         PROXY_THRES = "1"
-        with SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.FileSystemMonitoring(1000,salome.__file__) ) as monitoringParamsForFileMaster:
+        with SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.FileSystemMonitoring(1000,os.path.dirname( salome.__file__ )) ) as monitoringParamsForFileMaster:
             with SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.CPUMemoryMonitoring(1000) ) as monitoringParamsMaster:
                 with tempfile.TemporaryDirectory() as tmpdirnameMonitoring:
                     monitoringFile = os.path.join( str( tmpdirnameMonitoring ), "zeHtop.pckl" )
@@ -216,7 +216,7 @@ time.sleep(1)
         with tempfile.TemporaryDirectory() as tmpdirnameMonitoring:
             fsMonitoringFile = os.path.join( str( tmpdirnameMonitoring ), "zeFS.txt" )
             cpuMemMonitoringFile = os.path.join( str( tmpdirnameMonitoring ), "zeCPUMem.txt" )
-            with SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.FileSystemMonitoring(1000,salome.__file__,fsMonitoringFile) ) as monitoringParamsForFileMaster:
+            with SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.FileSystemMonitoring(1000,os.path.dirname( salome.__file__ ),fsMonitoringFile) ) as monitoringParamsForFileMaster:
                 with SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.CPUMemoryMonitoring(1000,cpuMemMonitoringFile) ) as monitoringParamsMaster:
                     monitoringFile = os.path.join( str( tmpdirnameMonitoring ), "zeHtop.pckl" )
                     monitoringFileTwo = os.path.join( str( tmpdirnameMonitoring ), "zeHtopTwo.pckl" )