Version: 9.15.0
driver_internal.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2024 CEA, EDF
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 
21 import salome
22 import logging
23 
24 DisplayEntryInCMD = "--display"
25 VerboseEntryInCMD = "--verbose"
26 VerboseLevelEntryInCMD = "--verbose-level"
27 StopOnErrorEntryInCMD = "--stop-on-error"
28 DumpOnErrorEntryInCMD = "--dump-on-error"
29 DumpEntryInCMD = "--dump"
30 KernelTraceEntryInCMD = "--kerneltrace"
31 DumpStateEntryInCMD = "--dump-final"
32 LoadStateEntryInCMD = "--load-state"
33 SaveXMLSchemaEntryInCMD = "--save-xml-schema"
34 ShutdownEntryInCMD = "--shutdown"
35 ResetEntryInCMD = "--reset"
36 InitPortEntryInCMD = "--init-port"
37 DoNotSqueezeEntryInCMD = "--donotsqueeze"
38 IOREntryInCMD = "--ior-ns"
39 CPUTimeResOfContainerEntryInCMD = "--cpu-mem-container-time-res"
40 HTOPFileEntryInCMD = "--htop-of-yacs-engine-process-file"
41 HTOPServerFileEntryInCMD = "--htop-of-servers"
42 HTOPFileTimeResEntryInCMD = "--htop-of-yacs-engine-process-time-res"
43 HTOPServerFileTimeResEntryInCMD = "--htop-of-servers-time-res"
44 MonitoringDirsEntryInCMD = "--monitoring-dirs-content"
45 MonitoringDirsResEntryInCMD = "--monitoring-dirs-content-res"
46 MonitoringDirsTimeResEntryInCMD = "--monitoring-dirs-content-time-res"
47 ReplayOnErrorEntryInCMD = "--replay-on-error"
48 ReplayDirInCMD = "--replay-dir"
49 BigObjDirInCMD = "--bigobj-dir"
50 BigObjThresInCMD = "--bigobj-thres"
51 CustomOverridesInCMD = "--activate-custom-overrides"
52 
53 DisplayKeyInARGS = "display"
54 VerboseKeyInARGS = "verbose"
55 VerboseLevelKeyInARGS = "verbose_level"
56 StopOnErrorKeyInARGS = "stop"
57 DumpOnErrorKeyInARGS = "dumpErrorFile"
58 DumpKeyInARGS = "dump"
59 KernelTraceKeyInARGS = "kerneltrace"
60 DumpStateKeyInARGS = "finalDump"
61 LoadStateKeyInARGS = "loadState"
62 SaveXMLSchemaKeyInARGS = "saveXMLSchema"
63 ShutdownKeyInARGS = "shutdown"
64 ResetKeyInARGS = "reset"
65 InitPortKeyInARGS = "init_port"
66 DoNotSqueezeKeyInARGS = "donotsqueeze"
67 IORKeyInARGS = "iorNS"
68 CPUTimeResOfContainerKeyInARGS = "cpu_mem_container_time_res"
69 HTOPFileKeyInARGS = "htop_of_yacs_engine_process_file"
70 HTOPServerFileKeyInARGS = "htop_of_servers"
71 HTOPFileTimeResKeyInARGS = "htop_of_yacs_engine_process_time_res"
72 HTOPServerFileTimeResKeyInARGS = "htop_of_servers_time_res"
73 MonitoringDirsInARGS = "monitoring_dirs_content"
74 MonitoringDirsResInARGS = "monitoring_dirs_content_res"
75 MonitoringDirsTimeResInARGS = "monitoring_dirs_content_time_res"
76 ReplayOnErrorEntryInARGS = "replay_on_error"
77 ReplayDirInARGS = "replay_dir"
78 BigObjDirInARGS = "bigobj_dir"
79 BigObjThresInARGS = "bigobj_thres"
80 CustomOverridesInARGS = "activate_custom_overrides"
81 
82 KeyValnARGS = [(DisplayEntryInCMD,DisplayKeyInARGS),
83  (VerboseEntryInCMD,VerboseKeyInARGS),
84  (VerboseLevelEntryInCMD,VerboseLevelKeyInARGS),
85  (StopOnErrorEntryInCMD,StopOnErrorKeyInARGS),
86  (DumpOnErrorEntryInCMD,DumpOnErrorKeyInARGS),
87  (DumpEntryInCMD,DumpKeyInARGS),
88  (KernelTraceEntryInCMD,KernelTraceKeyInARGS),
89  (DumpStateEntryInCMD,DumpStateKeyInARGS),
90  (LoadStateEntryInCMD,LoadStateKeyInARGS),
91  (SaveXMLSchemaEntryInCMD,SaveXMLSchemaKeyInARGS),
92  (ShutdownEntryInCMD,ShutdownKeyInARGS),
93  (ResetEntryInCMD,ResetKeyInARGS),
94  (InitPortEntryInCMD,InitPortKeyInARGS),
95  (DoNotSqueezeEntryInCMD,DoNotSqueezeKeyInARGS),
96  (CPUTimeResOfContainerEntryInCMD,CPUTimeResOfContainerKeyInARGS),
97  (HTOPFileEntryInCMD,HTOPFileKeyInARGS),
98  (HTOPFileTimeResEntryInCMD,HTOPFileTimeResKeyInARGS),
99  (HTOPServerFileEntryInCMD,HTOPServerFileKeyInARGS),
100  (HTOPServerFileTimeResEntryInCMD,HTOPServerFileTimeResKeyInARGS),
101  (MonitoringDirsEntryInCMD,MonitoringDirsInARGS),
102  (MonitoringDirsResEntryInCMD,MonitoringDirsResInARGS),
103  (MonitoringDirsTimeResEntryInCMD,MonitoringDirsTimeResInARGS),
104  (ReplayOnErrorEntryInCMD,ReplayOnErrorEntryInARGS),
105  (ReplayDirInCMD,ReplayDirInARGS),
106  (BigObjDirInCMD,BigObjDirInARGS),
107  (BigObjThresInCMD,BigObjThresInARGS),
108  (CustomOverridesInCMD,CustomOverridesInARGS),
109  (IOREntryInCMD,IORKeyInARGS)]
110 
111 my_runtime_yacs = None
112 
113 my_ior_ns = None
114 
115 my_replay_on_error = False
116 
117 my_replay_dir = ""
118 
120  import SALOMERuntime
121  import KernelBasis
122  global my_runtime_yacs,my_ior_ns,my_runtime_yacs
123  if my_runtime_yacs:
124  return
125  salome.salome_init()
126  if my_replay_on_error:
127  KernelBasis.SetPyExecutionMode("OutOfProcessWithReplay")
128  KernelBasis.SetDirectoryForReplayFiles( my_replay_dir )
129  if my_ior_ns:
130  salome.naming_service.DumpIORInFile( my_ior_ns )
131  flags = SALOMERuntime.RuntimeSALOME.UsePython + SALOMERuntime.RuntimeSALOME.UseCorba + SALOMERuntime.RuntimeSALOME.UseXml + SALOMERuntime.RuntimeSALOME.UseCpp + SALOMERuntime.RuntimeSALOME.UseSalome
132  SALOMERuntime.RuntimeSALOME.setRuntime( flags )
133  my_runtime_yacs = SALOMERuntime.getSALOMERuntime()
134  anIOR = salome.orb.object_to_string ( salome.modulcat )
135  aCatalog = my_runtime_yacs.loadCatalog( "session", anIOR )
136  my_runtime_yacs.addCatalog( aCatalog )
137 
139  def decaratedFunc(*args,**kwargs):
141  return func(*args,**kwargs)
142  return decaratedFunc
143 
144 @SALOMEInitializationNeeded
145 def loadGraph( xmlFileName ):
146  """
147  Args:
148  -----
149  xmlFileName : XML file containing YACS schema
150 
151  Returns
152  -------
153 
154  SALOMERuntime.SalomeProc : YACS graph instance
155  """
156  import loader
157  l=loader.YACSLoader()
158  p=l.load( xmlFileName )
159  return p
160 
161 def patchGraph( proc, squeezeMemory, initPorts, xmlSchema, loadStateXmlFile, reset, display):
162  """
163  Args:
164  -----
165 
166  proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated
167  squeezeMemory ( bool ) : squeezememory to be activated
168  initPorts (list<string>) : list of bloc.node.port=value.
169  xmlSchema (string) :
170  loadStateXmlFile (string) : file if any of state to be loaded inside proc
171  reset (int) :
172  display (int) :
173  """
174  import SALOMERuntime
175  import loader
176  import pilot
177  def parse_init_port(input):
178  """
179  Returns
180  -------
181  node, port, value
182  """
183  node_port, value = input.split("=")
184  nodePortSpl = node_port.split(".")
185  port = nodePortSpl[-1]
186  node = ".".join( nodePortSpl[:-1] )
187  return node,port,value
188 
189  if squeezeMemory:
190  logging.info("SqueezeMemory requested -> update proc")
191  allNodes = proc.getAllRecursiveNodes()
192  for node in allNodes:
193  if isinstance(node,SALOMERuntime.PythonNode):
194  node.setSqueezeStatus( True )
195  #
196  for initPort in initPorts:
197  node,port,value = parse_init_port(initPort)
198  init_state = proc.setInPortValue(node, port, value)
199  if init_state != value:
200  raise RuntimeError(f"Error on initialization of {initPort}")
201  #
202  if xmlSchema:
203  SALOMERuntime.VisitorSaveSalomeSchemaUnsafe(proc,xmlSchema)
204  pass
205  #
206  info = pilot.LinkInfo( pilot.LinkInfo.ALL_DONT_STOP )
207  proc.checkConsistency(info)
208  if info.areWarningsOrErrors():
209  raise RuntimeError( info.getGlobalRepr() )
210  #
211  if loadStateXmlFile:
212  loader.loadState( proc, loadStateXmlFile )
213  if reset > 0:
214  proc.resetState(reset)
215  proc.exUpdateState()
216  #
217  if display > 0:
218  proc.writeDotInFile("toto")
219 
220 @SALOMEInitializationNeeded
221 def prepareExecution(proc, isStop, dumpErrorFile):
222  """
223  Returns
224  -------
225 
226  pilot.ExecutorSwig : Instance of executor
227  """
228  import pilot
229  ex=pilot.ExecutorSwig()
230  if isStop:
231  logging.info(f"Stop has been activated with {dumpErrorFile}")
232  ex.setStopOnError( dumpErrorFile!="", dumpErrorFile )
233  return ex
234 
235 @SALOMEInitializationNeeded
236 def executeGraph( executor, xmlfilename, proc, dump, finalDump, display, shutdown, CPUMemContainerTimeRes,
237  HTopOfThisProcessFile, HTopTimeRes,
238  HTopOfAllServersFile, HTopOfAllServersTimeRes, DirectoriesToMonitor):
239  """
240  Args:
241  -----
242 
243  executor (pilot.ExecutorSwig) : Executor in charge of evaluation.
244  proc ( SALOMERuntime.SalomeProc ) : YACS Proc instance to be evaluated
245  xmlfilename (string)
246  dump (int) : time interval between 2 dump state
247  finalDump ( string ) : filename containing final result of graph, if any.
248  display (int) :
249  shutdown (int) : shutdown level
250  CPUMemContainerTimeRes (int) : time in second between two measures of CPU/Mem in container processes
251  HTopOfThisProcessFile (str) : file name (if not empty) containing the result of measure of current process
252  HTopTimeRes (int) : time in second between two measures of CPU/Mem of current process
253  HTopOfAllServersFile (str) : file name (if not empty) containing the result of measure of all servers
254  HTopOfAllServersTimeRes (int) : time in second between two measures of CPU/Mem of any of server
255  """
256  import SALOMERuntime
257  import pilot
258  import os
259  import contextlib
260 
261  class AutoShutdown:
262  def __init__(self, proc, shutdown):
263  self._proc = proc
264  self._shutdown = shutdown
265  def __enter__(self):
266  pass
267 
268  def __exit__(self,exctype, exc, tb):
269  if my_replay_on_error:
270  listOfGrps = []
271  for cont in salome.get_all_containers():
272  listOfGrps += cont.getAllLogFileNameGroups()
273  print("{} {} {}".format( 100*"=", "List of replay sessions of failing usecases" , 100*"="))
274  for igrp,grp in enumerate(listOfGrps):
275  print("{} : {}".format("Group {}".format(igrp)," ".join(grp)))
276  print(300*"=")
277  #
278  if self._shutdown < 999:
279  self._proc.shutdown(self._shutdown)
280  salome.dsm.shutdownScopes()
281  my_runtime_yacs.fini( False )
282 
283  class AutoDumpThread:
284  def __init__(self, proc, dump, xmlfilename):
285  self._dumpFile = "dumpState_{}".format( os.path.basename(xmlfilename) )
286  self._lockFile = "{}.lock".format( os.path.splitext( os.path.basename(xmlfilename) )[0] )
287  def __enter__(self):
288  logging.info(f"Ready to launch thread of state dump with dumpFile = {self._dumpFile} lockFile = {self._lockFile}")
289  self._dump_thread = SALOMERuntime.ThreadDumpState(proc,dump,self._dumpFile,self._lockFile)
290  self._dump_thread.start()
291  def __exit__(self,exctype, exc, tb):
292  self._dump_thread.join()
293 
294  def MonitoringDirectories( DirectoriesToMonitor ):
295  import SALOME_PyNode
296  if len( DirectoriesToMonitor ) > 0:
297  return [ SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.FileSystemMonitoring(timeRes*1000,zeDir,zeDirRes) ) for zeDir,zeDirRes,timeRes in DirectoriesToMonitor ]
298  else:
299  return [ ]
300 
301  def MonitoringThisProcess(HTopOfThisProcessFile,HTopTimeRes):
302  import SALOME_PyNode
303  if HTopOfThisProcessFile:
304  return [ SALOME_PyNode.GenericPythonMonitoringLauncherCtxMgr( SALOME_PyNode.CPUMemoryMonitoring(1000*HTopTimeRes,HTopOfThisProcessFile) ) ]
305  else:
306  return [ ]
307 
308  def MonitoringAllKernelServers(HTopOfAllServersFile, HTopOfAllServersTimeRes):
309  if HTopOfAllServersFile:
310  return [ salome.LogManagerLaunchMonitoringFileCtxMgr( 1000*HTopOfAllServersTimeRes, HTopOfAllServersFile ) ]
311  else:
312  return [ ]
313  #
314  salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 1000*CPUMemContainerTimeRes )
315  # Start part of context manager instances
316  ctxManagers = [ AutoShutdown(proc,shutdown) ] # the first one must be this one. Because orb.shutdown must be called last !
317  #
318  ctxManagers += MonitoringDirectories( DirectoriesToMonitor ) + MonitoringThisProcess(HTopOfThisProcessFile, HTopTimeRes) + MonitoringAllKernelServers(HTopOfAllServersFile, HTopOfAllServersTimeRes)
319  #
320  if dump != 0:
321  ctxManagers += [ AutoDumpThread(proc,dump,xmlfilename) ]
322  # end of part of context managers
323  with contextlib.ExitStack() as stack:
324  for mgr in ctxManagers:
325  stack.enter_context(mgr)
326  executor.RunPy(proc,display,isPyThread=True,fromscratch=True) # same as RunW but releasing GIL
327  #
328  if proc.getEffectiveState() != pilot.DONE:
329  raise RuntimeError( proc.getErrorReport() )
330  #
331  if display > 0:
332  proc.writeDotInFile("titi")
333  #
334  if finalDump:
335  logging.info(f"Final dump requested : {finalDump}")
336  SALOMERuntime.schemaSaveStateUnsafe( proc, finalDump )
337 
338 def EntryFromCoarseEntry( entry ):
339  if entry[:2] != "--":
340  raise RuntimeError("Unexpected entry")
341  return entry[2:]
342 
343 def toDict( args ):
344  """
345  Convert argparse.Namespace to dict
346  """
347  return {EntryFromCoarseEntry(entry):getattr(args,key) for entry,key in KeyValnARGS}
348 
350  """
351  Args:
352  -----
353 
354  args (argparse.Namespace) : instance after parsing
355  """
356  return "\n".join( [ f"{EntryFromCoarseEntry(entry)} : {args[key]}" for entry,key in KeyValnARGS ] )
357 
359  import KernelBasis
360  import argparse
361  parser = argparse.ArgumentParser()
362  parser.add_argument('xmlfilename',help = "XML file containing YACS schema to be executed")
363  parser.add_argument("-d", DisplayEntryInCMD, dest = DisplayKeyInARGS, type=int, const=1, nargs='?', default=0, help="Display dot files: 0=never to 3=very often")
364  parser.add_argument("-v", VerboseEntryInCMD, dest = VerboseKeyInARGS,help="Produce verbose output", action='store_true')
365  parser.add_argument("-vl", VerboseLevelEntryInCMD, dest = VerboseLevelKeyInARGS, type=str, choices=["ERROR", "WARNING", "INFO", "DEBUG"], default="INFO", help="Specifies level of verbosity")
366  parser.add_argument("-s",StopOnErrorEntryInCMD,dest=StopOnErrorKeyInARGS,help="Stop on first error", action='store_true')
367  parser.add_argument("-e",DumpOnErrorEntryInCMD,dest=DumpOnErrorKeyInARGS, type=str, const='dumpErrorState.xml', default="", nargs='?', help="Stop on first error and dump state")
368  parser.add_argument("-g",DumpEntryInCMD,dest=DumpKeyInARGS, type=int, const=60, default=0, nargs='?', help="dump state")
369  parser.add_argument("-kt", KernelTraceEntryInCMD, dest = KernelTraceKeyInARGS,help="Produce verbose of SALOME/KERNEL", action='store_true')
370  parser.add_argument("-f",DumpStateEntryInCMD, dest =DumpStateKeyInARGS, type=str, const='finalDumpState.xml', default="", nargs='?', help="dump final state")
371  parser.add_argument("-l",LoadStateEntryInCMD, dest=LoadStateKeyInARGS, type=str, default="", help="Load State from a previous partial execution")
372  parser.add_argument("-x",SaveXMLSchemaEntryInCMD, dest=SaveXMLSchemaKeyInARGS, type=str, const="saveSchema.xml", nargs='?', default="", help = "dump xml schema")
373  parser.add_argument("-t",ShutdownEntryInCMD, dest = ShutdownKeyInARGS, type=int , default=3, help="Shutdown the schema: 0=no shutdown to 3=full shutdown")
374  parser.add_argument("-r",ResetEntryInCMD, dest = ResetKeyInARGS, type=int , default = 0, help="Reset the schema before execution: 0=nothing, 1=reset error nodes to ready state")
375  parser.add_argument("-i",InitPortEntryInCMD, dest = InitPortKeyInARGS, type=str, default =[], action='append', help="Initialisation value of a port, specified as bloc.node.port=value. For multiple settings use comma.")
376  parser.add_argument("-z",DoNotSqueezeEntryInCMD, dest = DoNotSqueezeKeyInARGS, help = "Desactivate squeeze memory optimization.", action='store_true')
377  parser.add_argument(CPUTimeResOfContainerEntryInCMD, dest = CPUTimeResOfContainerKeyInARGS, type=int, default = 10, help="Time in second between two measures of CPU/Mem in container processes")
378  parser.add_argument(HTOPFileEntryInCMD, dest = HTOPFileKeyInARGS, type=str, default ="", help="File name (if not empty) containing the result of measure of current process")
379  parser.add_argument(HTOPFileTimeResEntryInCMD, dest = HTOPFileTimeResKeyInARGS, type=int, default = 60, help="Time in second between between two measures of CPU/Mem of current process")
380  parser.add_argument(HTOPServerFileEntryInCMD, dest = HTOPServerFileKeyInARGS, type=str, default ="", help="File name (if not empty) containing the result of measure of all server processes")
381  parser.add_argument(HTOPServerFileTimeResEntryInCMD, dest = HTOPServerFileTimeResKeyInARGS, type=int, default = 30, help="Time in second between between two measures of CPU/Mem of any server process")
382  parser.add_argument(MonitoringDirsEntryInCMD, dest = MonitoringDirsInARGS, nargs='+', type=str, default =[], help="List of directories to be monitored")
383  parser.add_argument(MonitoringDirsResEntryInCMD, dest = MonitoringDirsResInARGS, nargs='+', type=str, default =[], help=f"List of files with result of monitoring of directories to be monitored (see {MonitoringDirsInARGS}). The size of lists are expected to be the same.")
384  parser.add_argument(MonitoringDirsTimeResEntryInCMD, dest = MonitoringDirsTimeResInARGS, nargs='+', type=int, default =[], help=f"List of time resolution (in second) of monitoring of directories to be monitored (see {MonitoringDirsInARGS}). The size of lists are expected to be the same.")
385  parser.add_argument("-w",ReplayOnErrorEntryInCMD,dest=ReplayOnErrorEntryInARGS,help="Mode of execution of YACS where all python execution are wrapped into a subprocess to be able to resist against failure (such as SIGSEV)", action='store_true')
386  parser.add_argument(ReplayDirInCMD, dest=ReplayDirInARGS, type=str, default ="", help="Directory storing replay scenarii if any (see replay-on-error option.")
387  parser.add_argument(BigObjDirInCMD, dest=BigObjDirInARGS, type=str, default ="", help="Directory storing big obj files exchanged between YACS python nodes.")
388  parser.add_argument(BigObjThresInCMD, dest=BigObjThresInARGS, type=int, default = KernelBasis.GetBigObjOnDiskThreshold(), help="Objects whose size exceeds this threshold in bytes will be written inside directory")
389  parser.add_argument(CustomOverridesInCMD, dest=CustomOverridesInARGS, help="Activate custom overrides. These overrides are incarnated by yacs_driver_overrides module that is expected to loadable in current application.", action='store_true')
390  parser.add_argument(IOREntryInCMD, dest = IORKeyInARGS, type=str, default ="", help="file inside which the ior of NS will be stored")
391  parser.add_argument("--options_from_json", dest = "options_from_json", type=str, default ="", help="Json file of options. If defined options in json will override those specified in command line.")
392  return parser
393 
394 def mainRun( args, xmlFileName):
395  """
396  Args:
397  -----
398 
399  args (dict) : options for treatment
400 
401  """
402  global my_ior_ns,my_replay_on_error,my_replay_dir
403  from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose,KernelLogLevelToLogging
404  #
405  iorNS = args[IORKeyInARGS]
406  #
407  if iorNS:
408  my_ior_ns = iorNS
409  #
410  if args[ReplayOnErrorEntryInARGS]:
411  my_replay_on_error = True
412  my_replay_dir = args[ReplayDirInARGS]
413  #
414  if args[VerboseKeyInARGS]:
415  setVerbose( args[ KernelTraceKeyInARGS ] )
416  setVerboseLevel( KernelLogLevelToLogging[ args[VerboseLevelKeyInARGS] ] )
417  positionVerbosityOfLoggerRegardingState()
418  logging.info( reprAfterArgParsing(args) )
419  #
420  proc = loadGraph( xmlFileName )
421  # work around a bug in Executor::Run when there are no tasks to launch.
422  if len(proc.getChildren()) == 0 :
423  return
424  #
425  patchGraph( proc, not args[DoNotSqueezeKeyInARGS], args[InitPortKeyInARGS], args[SaveXMLSchemaKeyInARGS], args[LoadStateKeyInARGS], args[ResetKeyInARGS], args[DisplayKeyInARGS])
426  executor = prepareExecution( proc, args[StopOnErrorKeyInARGS], args[DumpOnErrorKeyInARGS])
427  # proxy parameters management
428  if args[ BigObjDirInARGS ]:
429  salome.cm.SetBigObjOnDiskDirectory( args[ BigObjDirInARGS ] )
430  salome.cm.SetBigObjOnDiskThreshold( args[ BigObjThresInARGS ] )
431  # overrides
432  if args[ CustomOverridesInARGS ]:
433  try:
434  import yacs_driver_overrides
435  import pylauncher
436  allresources = pylauncher.RetrieveRMCppSingleton()# pylauncher.ResourcesManager_cpp singleton representing all resources (pylauncher.ResourceDefinition_cpp) devoted for the computation.
437  yacs_driver_overrides.customize( salome.cm, allresources )
438  except:
439  raise RuntimeError("Overrides have be requested to be triggered by the user but module is not available")
440  #
441  executeGraph( executor, xmlFileName, proc, args[DumpKeyInARGS], args[DumpStateKeyInARGS], args[DisplayKeyInARGS], args[ShutdownKeyInARGS], args[CPUTimeResOfContainerKeyInARGS],
442  args[HTOPFileKeyInARGS], args[HTOPFileTimeResKeyInARGS],
443  args[HTOPServerFileKeyInARGS], args[HTOPServerFileTimeResKeyInARGS], [(dirToMonitor,resFile,timeRes) for dirToMonitor,resFile,timeRes in zip(args[MonitoringDirsInARGS],args[MonitoringDirsResInARGS],args[MonitoringDirsTimeResInARGS])] )
444 
445 def parseArgs():
446  """
447  Returns
448  -------
449 
450  - args (dict) : dictionnary containing all args taken into account. If json, the params in json will override entries
451  - xmlFileName (str) : XML YACS schema
452 
453  """
454  import json
455  parser = getArgumentParser()
456  args = parser.parse_args()
457  iorNS = args.iorNS
458  xmlFileName = args.xmlfilename
459  optionFromJSon = args.options_from_json
460  args = toDict( args )
461  if optionFromJSon:
462  # in case of Json overrides
463  with open( optionFromJSon ) as f:
464  opts_from_json = json.load( f )
465  for k,v in opts_from_json.items():
466  if k != EntryFromCoarseEntry(IOREntryInCMD) or v:# for IOR if v is null -> do not override
467  args[k] = v
468  # change key of args from entryCMD to KeyInARGS
469  args = {key:args[EntryFromCoarseEntry(entry)] for entry,key in KeyValnARGS}
470  return args, xmlFileName
471 
472 if __name__ == "__main__":
473  args, xmlFileName = parseArgs()
474  mainRun( args, xmlFileName)
bool parse_init_port(const std::string &input, std::string &node, std::string &port, std::string &value)
Definition: driver.cxx:294
def EntryFromCoarseEntry(entry)
def patchGraph(proc, squeezeMemory, initPorts, xmlSchema, loadStateXmlFile, reset, display)
def reprAfterArgParsing(args)
def prepareExecution(proc, isStop, dumpErrorFile)
def SALOMEInitializationNeeded(func)
def executeGraph(executor, xmlfilename, proc, dump, finalDump, display, shutdown, CPUMemContainerTimeRes, HTopOfThisProcessFile, HTopTimeRes, HTopOfAllServersFile, HTopOfAllServersTimeRes, DirectoriesToMonitor)
def loadGraph(xmlFileName)
def mainRun(args, xmlFileName)