//! name of the %container log file
attribute string locallogfilename ;
+
+ //! interval of time between two measures of CPU/time process container
+ attribute long monitoringtimeresms;
void verbosity(out boolean activated, out string level);
long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond();
void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(in long timeInMS);
+
+ long GetDeltaTimeBetweenCPUMemMeasureInMilliSecond();
+
+ void SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(in long timeInMS);
void SetOverrideEnvForContainers(in KeyValDict env);
#define SLASH '/'
#endif
+const int Abstract_Engines_Container_i::DFT_TIME_INTERVAL_BTW_MEASURE = 500;
+
std::map<std::string, int> Abstract_Engines_Container_i::_cntInstances_map;
std::map<std::string, void *> Abstract_Engines_Container_i::_library_map;
std::map<std::string, void *> Abstract_Engines_Container_i::_toRemove_map;
// pycont = SALOME_Container.SALOME_Container_i(containerIORStr)
CORBA::String_var sior = _orb->object_to_string(pCont);
- std::string myCommand="pyCont = SALOME_Container.SALOME_Container_i('";
- myCommand += _containerName + "','";
- myCommand += sior;
- myCommand += "')\n";
- SCRUTE(myCommand);
+ std::ostringstream myCommand;
+ myCommand << "pyCont = SALOME_Container.SALOME_Container_i('" << _containerName << "','" << sior << "','" << DFT_TIME_INTERVAL_BTW_MEASURE << "')\n";
+ SCRUTE(myCommand.str());
//[RNV]: Comment the PyEval_AcquireLock() and PyEval_ReleaseLock() because this
//approach leads to the deadlock of the main thread of the application on Windows platform
PyRun_SimpleString("sys.path = sys.path[1:]\n");
#endif
PyRun_SimpleString("import SALOME_Container\n");
- PyRun_SimpleString((char*)myCommand.c_str());
+ PyRun_SimpleString((char*)myCommand.str().c_str());
PyObject *mainmod = PyImport_AddModule("__main__");
PyObject *globals = PyModule_GetDict(mainmod);
_pyCont = PyDict_GetItemString(globals, "pyCont");
_localfilename = name;
}
+CORBA::Long Abstract_Engines_Container_i::monitoringtimeresms()
+{
+ AutoGIL gstate;
+ PyObject *result = PyObject_CallMethod(_pyCont,(char*)"monitoringtimeresms",nullptr);
+ if (PyErr_Occurred())
+ {
+ std::string error("can not retrieve time interval between 2 measures");
+ PyErr_Print();
+ THROW_SALOME_CORBA_EXCEPTION(error.c_str(),SALOME::INTERNAL_ERROR);
+ }
+ CORBA::Long ret = PyLong_AsLong( result );
+ Py_XDECREF(result);
+ return ret;
+}
+
+void Abstract_Engines_Container_i::monitoringtimeresms(CORBA::Long intervalInMs)
+{
+ AutoGIL gstate;
+ PyObject *result = PyObject_CallMethod(_pyCont,(char*)"SetMonitoringtimeresms","i",intervalInMs,nullptr);
+ if (PyErr_Occurred())
+ {
+ std::string error("can not set time interval between 2 measures");
+ PyErr_Print();
+ THROW_SALOME_CORBA_EXCEPTION(error.c_str(),SALOME::INTERNAL_ERROR);
+ }
+ Py_XDECREF(result);
+}
+
void Abstract_Engines_Container_i::verbosity(bool& activated, CORBA::String_out level)
{
activated = SALOME::VerbosityActivated();
#-------------------------------------------------------------------------
- def __init__(self ,containerName, containerIORStr):
+ def __init__(self ,containerName, containerIORStr, dftTimeIntervalInMs):
MESSAGE( "SALOME_Container_i::__init__" )
try:
argv = sys.argv
self._poa = self._orb.resolve_initial_references("RootPOA")
self._containerName = containerName
self._dbg_info = []
+ self._timeIntervalInMs = dftTimeIntervalInMs
if verbose(): print("SALOME_Container.SALOME_Container_i : _containerName ",self._containerName)
self._container = self._orb.string_to_object(containerIORStr)
def getAllInfo(self):
import pickle
return pickle.dumps( self._dbg_info )
+
+ def monitoringtimeresms(self):
+ return self._timeIntervalInMs
+
+ def SetMonitoringtimeresms(self , value):
+ self._timeIntervalInMs = value
return "{} {}".format(m,UNITS[3])
def __init__(self):
+ self._cpu_mem_during_exec = None
self._start_exec_time = None
self._end_exec_time = None
self._start_input_time = None
self._input_hdd_mem = None
self._output_mem = 0
self._output_hdd_mem = None
+
+ @property
+ def CPUMemDuringExec(self):
+ return self._cpu_mem_during_exec
+
+ @CPUMemDuringExec.setter
+ def CPUMemDuringExec(self,value):
+ self._cpu_mem_during_exec = value
+
+ @property
+ def CPUMemDuringExecStr(self):
+ cpu = self._cpu_mem_during_exec[::2]
+ mem_rss = self._cpu_mem_during_exec[1::2]
+ return [(a,ScriptExecInfo.MemRepr(b)) for a,b in self._cpu_mem_during_exec]
@property
def inputMem(self):
return """start exec time = {self.startExecTime}
end exec time = {self.endExecTime}
exec_time = {self.execTimeStr}
+CPU and mem monitoring = {self.CPUMemDuringExecStr}
input unpickling and ev load from disk time = {self.inputTimeStr}
output serialization and ev write to disk time = {self.outputTimeStr}
input memory size before exec (MemoryPeak 2x) = {self.inputMemStr}
#include "SALOME_ResourcesManager.hxx"
#include "SALOME_LoadRateManager.hxx"
#include "SALOME_NamingService.hxx"
+#include "SALOME_Container_i.hxx"
#include "SALOME_ResourcesManager_Client.hxx"
#include "SALOME_Embedded_NamingService.hxx"
#include "SALOME_ModuleCatalog.hh"
//=============================================================================
SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns)
- : _nbprocUsed(1),_delta_time_ns_lookup_in_ms(DFT_DELTA_TIME_NS_LOOKUP_IN_MS)
+ : _nbprocUsed(1),_delta_time_ns_lookup_in_ms(DFT_DELTA_TIME_NS_LOOKUP_IN_MS),_delta_time_measure_in_ms(Abstract_Engines_Container_i::DFT_TIME_INTERVAL_BTW_MEASURE)
{
MESSAGE("constructor");
_NS = ns;
this->_delta_time_ns_lookup_in_ms = timeInMS;
}
+CORBA::Long SALOME_ContainerManager::GetDeltaTimeBetweenCPUMemMeasureInMilliSecond()
+{
+ return this->_delta_time_measure_in_ms;
+}
+
+void SALOME_ContainerManager::SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(CORBA::Long timeInMS)
+{
+ this->_delta_time_measure_in_ms = timeInMS;
+}
+
//=============================================================================
//! Loop on all the containers listed in naming service, ask shutdown on each
/*! CORBA Method:
if (!CORBA::is_nil(cont))
{
INFOS("[GiveContainer] container " << containerNameInNS << " launched");
+ cont->monitoringtimeresms( this->_delta_time_measure_in_ms );
+ INFOS("[GiveContainer] container " << containerNameInNS << " first CORBA invocation OK");
std::ostringstream envInfo;
std::for_each( _override_env.begin(), _override_env.end(), [&envInfo](const std::pair<std::string,std::string>& p) { envInfo << p.first << " = " << p.second << std::endl; } );
INFOS("[GiveContainer] container " << containerNameInNS << " override " << envInfo.str());
void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) override;
+ CORBA::Long GetDeltaTimeBetweenCPUMemMeasureInMilliSecond() override;
+
+ void SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(CORBA::Long timeInMS) override;
+
static const char *_ContainerManagerNameInNS;
protected:
std::vector< std::pair<std::string, std::string> > _override_env;
int _time_out_in_second;
int _delta_time_ns_lookup_in_ms;
+ int _delta_time_measure_in_ms;
std::string _code_to_exe_on_startup;
};
#endif
void logfilename(const char *name) override;
char *locallogfilename() override;
void locallogfilename(const char *name) override;
+ CORBA::Long monitoringtimeresms() override;
+ void monitoringtimeresms(CORBA::Long intervalInMs) override;
void verbosity(bool& activated, CORBA::String_out level) override;
void setVerbosity(bool activated, const char *level) override;
SALOME::vectorOfByte *getAllInfo() override;
void unregisterTemporaryFile(const std::string &fileName);
void clearTemporaryFiles();
PortableServer::ObjectId *getCORBAId() const { return _id; }
-
+public:
+ static const int DFT_TIME_INTERVAL_BTW_MEASURE;
protected:
static std::map<std::string, int> _cntInstances_map;
static std::map<std::string, void *> _library_map; // library names, loaded
import SALOME
import logging
import os
+import sys
MY_CONTAINER_ENTRY_IN_GLBS = "my_container"
list<float,str> : list of pairs. First param of pair is CPU usage. Second param of pair is rss memory usage
"""
import KernelBasis
- from SALOME_ContainerHelper import ScriptExecInfo
ret = KernelBasis.StopMonitoring()
cpu = ret[::2]
- mem_rss = [ScriptExecInfo.MemRepr( int(elt) ) for elt in ret[1::2]]
+ mem_rss = [ int(elt) for elt in ret[1::2]]
return [(a,b) for a,b in zip(cpu,mem_rss)]
class SeqByteReceiver:
self.context[MY_CONTAINER_ENTRY_IN_GLBS] = self.my_container
self._pos = None
self._current_exec = 0
+ sys.stdout.flush() ; sys.stderr.flush() # flush to correctly capture log per execution session
#start of non remote callable methods
def executeFirst(self,argsin):
""" Same than first part of self.execute to reduce memory peak."""
try:
+ #self.my_container_py.addInfoOnLevel2(self.getIDInContainer(),self._current_exec,"tracePosStart",)
data = None
self.my_container_py.addTimeInfoOnLevel2(self.getIDInContainer(),self._current_exec,"startInputTime")
if True: # to force call of SeqByteReceiver's destructor
import sys
try:
self.my_container_py.addTimeInfoOnLevel2(self.getIDInContainer(),self._current_exec,"startExecTime")
- pyfile = BuildPythonFileForCPUPercent()
-
+ ##
+ monitoringParams = LaunchMonitoring( self.my_container_py.monitoringtimeresms() )
exec(self.ccode, self.context)
+ cpumeminfo = StopMonitoring( )
+ ##
+ self.my_container_py.addInfoOnLevel2(self.getIDInContainer(),self._current_exec,"CPUMemDuringExec",cpumeminfo)
+ del monitoringParams
self.my_container_py.addTimeInfoOnLevel2(self.getIDInContainer(),self._current_exec,"endExecTime")
self.my_container_py.addTimeInfoOnLevel2(self.getIDInContainer(),self._current_exec,"startOutputTime")
argsout=[]