1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2024 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
37 def unProxyfy( objs ):
39 objs is a list of SenderByte
42 fileNamesProxyOut = []
44 ret3 = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret2).data() )
46 fileNameProxyOut = None
47 if SALOME_PyNode.GetBigObjectOnDiskThreshold() != -1:
48 if isinstance( ret3, SALOME_PyNode.BigObjectOnDiskBase ):
51 raise RuntimeError("Oooops")
52 ret3.unlinkOnDestructor()
53 fileNameProxyOut = ret3.getFileName()
54 logging.debug("Prxy file : {}".format( fileNameProxyOut ))
56 fileNamesProxyOut.append( fileNameProxyOut )
57 return ret, fileNamesProxyOut
59 class testPerfLogManager1(unittest.TestCase):
60 def testPerfLogManager0(self):
62 [EDF29150] : This test checks measure performance methods
64 hostname = "localhost"
65 cp = pylauncher.GetRequestForGiveContainer(hostname,"container_test")
68 with tempfile.TemporaryDirectory() as tmpdirname:
69 val_for_big_obj = str( tmpdirname )
70 os.environ["SALOME_FILE_BIG_OBJ_DIR"] = val_for_big_obj
71 # Override environement for all containers launched
72 salome.cm.SetOverrideEnvForContainersSimple(env = [("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",PROXY_THRES)])
73 salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 250 )
74 cont = salome.cm.GiveContainer(cp)
75 logging.debug("{} {}".format(40*"*",cont.getPID()))
80 cst = KernelBasis.GetTimeAdjustmentCst()
81 logging.debug("constant = {}".format(cst))
83 print("coucou {} {}".format(len(zeinput0),len(zeinput1)))
84 logging.debug("debug or not debug")
85 ob = [ [ bytes(3000000) ] ]
86 pihm, ts = KernelBasis.HeatMarcel(1 * nbcore * cst,nbcore)
87 print("Time ellapse spent : {} s".format(ts))
88 ob2 = [ [ bytes(100000) ] ]
89 pihm, ts = KernelBasis.HeatMarcel(1 * nbcore * cst,nbcore)
90 print("Time ellapse spent : {} s".format(ts))
91 sys.stderr.write("fake error message\\n")
93 poa = salome.orb.resolve_initial_references("RootPOA")
94 zeinput0 = [ bytes(100000000) ]
95 if SALOME_PyNode.GetBigObjectOnDiskThreshold() != -1:
96 zeinput0 = SALOME_PyNode.ProxyfyPickeled( zeinput0 )
97 zeinput0.unlinkOnDestructor()
98 obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["zeinput0"],{"zeinput0": [zeinput0], "zeinput1": [ [zeinput0], [zeinput0] ] }) ))
99 id_o = poa.activate_object(obj)
100 refPtr = poa.id_to_reference(id_o)
101 pyscript2 = cont.createPyScriptNode("testScript2",script_st)
102 pyscript2.executeFirst(refPtr)
103 ret2 = pyscript2.executeSecond(["ob","ob2"])# generate a DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats on debian11 ?
104 ret3, fileNamesProxyOut = unProxyfy( ret2 )
105 logging.getLogger().debug("test logging 1")
106 logging.debug("test logging 2")
107 logging.debug( salome.orb.object_to_string( salome.logm ) )
108 a = salome.logm.NaiveFetch()
110 logging.debug(a[0][1][0])
111 logging.debug( a[0][1][0].get()._input_hdd_mem._data[0]._data[0]._hdd_mem ) # important
112 logging.debug( a[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
113 fileNameProxyIn = a[0][1][0].get()._input_hdd_mem._data[0]._data[0]._file_name
114 logging.debug( fileNameProxyIn )
117 import gc ; gc.collect()
118 if fileNameProxyIn is not None:
119 if os.path.exists(fileNameProxyIn):
120 raise RuntimeError("Oooops 2")
121 for fileNameProxyOut in fileNamesProxyOut:
122 if fileNameProxyOut is not None:
123 if os.path.exists(fileNameProxyOut):
124 raise RuntimeError("Oooops 3")
126 # execution #2 inside last
130 logging.debug("Execution 2")
134 obj2 = SALOME_PyNode.SenderByte_i(poa,pickle.dumps((["a"],{"a":3})))
135 id2_o = poa.activate_object(obj2)
136 refPtr2 = poa.id_to_reference(id2_o)
137 pyscript2.assignNewCompiledCode(script_st2)
138 pyscript2.executeFirst(refPtr2)
139 ret2_0 = pyscript2.executeSecond(["b"])
140 ret2_1, fileNamesProxyOut2 = unProxyfy( ret2_0 )
141 logging.debug( fileNamesProxyOut2 )
142 a = salome.logm.NaiveFetch()
144 import gc ; gc.collect()
145 for fileNameProxyOut in fileNamesProxyOut2:
146 if fileNameProxyOut is not None:
147 if os.path.exists(fileNameProxyOut):
148 raise RuntimeError("Oooops 3")
150 fname = os.path.join(str( tmpdirname ),"perf.log")
151 salome.logm.DumpInFile( fname )
152 logManagerInst0 = salome.logm.LoadFromFile( fname )
153 logging.debug( logManagerInst0[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
154 logManagerInst = salome.logm.Fetch(True)
155 logManagerInst2 = salome.logm.Fetch(True)
156 logging.debug( logManagerInst[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
157 self.assertTrue( logManagerInst2[0][1][0].get() is None )
158 self.assertTrue( logManagerInst[0][1][1].get()._output_hdd_mem._data[0]._file_name == fileNamesProxyOut2[0] )
159 logging.debug( logManagerInst[0][1][1].log() )
162 if __name__ == '__main__':
163 from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose
166 setVerboseLevel(logging.DEBUG)
167 positionVerbosityOfLoggerRegardingState()