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 # Override environement for all containers launched
71 salome.cm.SetOverrideEnvForContainersSimple(env = [("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",PROXY_THRES)])
72 salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 250 )
73 cont = salome.cm.GiveContainer(cp)
74 logging.debug("{} {}".format(40*"*",cont.getPID()))
79 cst = KernelBasis.GetTimeAdjustmentCst()
80 logging.debug("constant = {}".format(cst))
82 print("coucou {} {}".format(len(zeinput0),len(zeinput1)))
83 logging.debug("debug or not debug")
84 ob = [ [ bytes(3000000) ] ]
85 pihm, ts = KernelBasis.HeatMarcel(1 * nbcore * cst,nbcore)
86 print("Time ellapse spent : {} s".format(ts))
87 ob2 = [ [ bytes(100000) ] ]
88 pihm, ts = KernelBasis.HeatMarcel(1 * nbcore * cst,nbcore)
89 print("Time ellapse spent : {} s".format(ts))
90 sys.stderr.write("fake error message\\n")
92 poa = salome.orb.resolve_initial_references("RootPOA")
93 zeinput0 = [ bytes(100000000) ]
94 if SALOME_PyNode.GetBigObjectOnDiskThreshold() != -1:
95 zeinput0 = SALOME_PyNode.ProxyfyPickeled( zeinput0 )
96 zeinput0.unlinkOnDestructor()
97 obj = SALOME_PyNode.SenderByte_i(poa,pickle.dumps( (["zeinput0"],{"zeinput0": [zeinput0], "zeinput1": [ [zeinput0], [zeinput0] ] }) ))
98 id_o = poa.activate_object(obj)
99 refPtr = poa.id_to_reference(id_o)
100 pyscript2 = cont.createPyScriptNode("testScript2",script_st)
101 pyscript2.executeFirst(refPtr)
102 ret2 = pyscript2.executeSecond(["ob","ob2"])# generate a DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats on debian11 ?
103 ret3, fileNamesProxyOut = unProxyfy( ret2 )
104 logging.getLogger().debug("test logging 1")
105 logging.debug("test logging 2")
106 logging.debug( salome.orb.object_to_string( salome.logm ) )
107 a = salome.logm.NaiveFetch()
109 logging.debug(a[0][1][0])
110 logging.debug( a[0][1][0].get()._input_hdd_mem._data[0]._data[0]._hdd_mem ) # important
111 logging.debug( a[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
112 fileNameProxyIn = a[0][1][0].get()._input_hdd_mem._data[0]._data[0]._file_name
113 logging.debug( fileNameProxyIn )
116 import gc ; gc.collect()
117 if fileNameProxyIn is not None:
118 if os.path.exists(fileNameProxyIn):
119 raise RuntimeError("Oooops 2")
120 for fileNameProxyOut in fileNamesProxyOut:
121 if fileNameProxyOut is not None:
122 if os.path.exists(fileNameProxyOut):
123 raise RuntimeError("Oooops 3")
125 # execution #2 inside last
129 logging.debug("Execution 2")
133 obj2 = SALOME_PyNode.SenderByte_i(poa,pickle.dumps((["a"],{"a":3})))
134 id2_o = poa.activate_object(obj2)
135 refPtr2 = poa.id_to_reference(id2_o)
136 pyscript2.assignNewCompiledCode(script_st2)
137 pyscript2.executeFirst(refPtr2)
138 ret2_0 = pyscript2.executeSecond(["b"])
139 ret2_1, fileNamesProxyOut2 = unProxyfy( ret2_0 )
140 logging.debug( fileNamesProxyOut2 )
141 a = salome.logm.NaiveFetch()
143 import gc ; gc.collect()
144 for fileNameProxyOut in fileNamesProxyOut2:
145 if fileNameProxyOut is not None:
146 if os.path.exists(fileNameProxyOut):
147 raise RuntimeError("Oooops 3")
149 fname = os.path.join(str( tmpdirname ),"perf.log")
150 salome.logm.DumpInFile( fname )
151 logManagerInst0 = salome.logm.LoadFromFile( fname )
152 logging.debug( logManagerInst0[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
153 logManagerInst = salome.logm.Fetch(True)
154 logManagerInst2 = salome.logm.Fetch(True)
155 logging.debug( logManagerInst[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important
156 self.assertTrue( logManagerInst2[0][1][0].get() is None )
157 self.assertTrue( logManagerInst[0][1][1].get()._output_hdd_mem._data[0]._file_name == fileNamesProxyOut2[0] )
158 logging.debug( logManagerInst[0][1][1].log() )
161 if __name__ == '__main__':
162 from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose
165 setVerboseLevel(logging.DEBUG)
166 positionVerbosityOfLoggerRegardingState()