Salome HOME
[EDF29150] : log performance of python scripts run inside SALOME container + verbosit...
[modules/kernel.git] / src / Launcher / SALOME_LogManager.py
1 #  -*- coding: iso-8859-1 -*-
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 os
22 import sys
23 import pickle
24 from SALOME_ContainerHelper import ScriptExecInfo
25
26 class SALOME_ContainerScriptExecPerfLog:
27   def __init__(self, father):
28     self._father = father
29     self._start_pos = None
30     self._stop_pos = None
31     
32   @property
33   def father(self):
34     return self._father
35
36   def end(self,s):
37     obj = pickle.loads(s)
38     self._stop_pos = os.path.getsize( self.father.father.logfilename )
39     setattr(obj,"tracePosStop",self._stop_pos)
40     setattr(obj,"tracePosStart",self._start_pos)
41     return pickle.dumps(obj)
42
43   def start(self):
44     self._start_pos = os.path.getsize( self.father.father.logfilename )
45
46 class SALOME_ContainerScriptPerfLog:
47   def __init__(self, father):
48     self._father = father
49
50   @property
51   def father(self):
52     return self._father
53
54   def addExecution(self):
55     return SALOME_ContainerScriptExecPerfLog(self)
56
57 class SALOME_ContainerPerfLog:
58   def __init__(self,contInNS,logfile):
59     self._container_in_ns = contInNS
60     self._log_filename = logfile
61     
62   @property
63   def logfilename(self):
64     return self._log_filename
65     
66   @property
67   def father(self):
68     return self._father
69
70   def addScript(self):
71     return SALOME_ContainerScriptPerfLog(self)
72
73 class SALOME_LogManagerHelper:
74   def __init__(self):
75     pass
76   
77   def declareContainer(self, contInNS,logfile):
78     inst = SALOME_ContainerPerfLog(contInNS,logfile)
79     return inst