From 242b923ef2b8a7d51e3bcdc56c28e97c648d3118 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Sun, 4 Feb 2024 17:46:03 +0100 Subject: [PATCH] [EDF29150] : WIP --- src/Container/SALOME_PyNode.py | 46 +++++++++++++++++++----- src/Launcher/Test/testPerfLogManager1.py | 4 +-- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index 941c52fa2..a82c2fc89 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -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) + nbInodes (list) + volumeOfDir (list) + """ + 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 : 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 ) diff --git a/src/Launcher/Test/testPerfLogManager1.py b/src/Launcher/Test/testPerfLogManager1.py index d5e216365..7df51a851 100644 --- a/src/Launcher/Test/testPerfLogManager1.py +++ b/src/Launcher/Test/testPerfLogManager1.py @@ -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" ) -- 2.39.2