ATLAS Offline Software
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
python.PyComps.PyStorePayloadMon Class Reference
Inheritance diagram for python.PyComps.PyStorePayloadMon:
Collaboration diagram for python.PyComps.PyStorePayloadMon:

Public Member Functions

def __init__ (self, name='PyStorePayloadMon', **kw)
 
def initialize (self)
 
def handle (self, incident)
 
def execute (self)
 
def process_proxy (self, p)
 
def finalize (self)
 
virtual StatusCode initialize () override
 Gaudi Service Implementation. More...
 
virtual StatusCode reinitialize () override
 
virtual StatusCode start () override
 
virtual StatusCode stop () override
 
virtual StatusCode finalize () override
 
virtual StatusCode sysInitialize () override
 
const char * typeName () const override
 return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part More...
 
virtual PyObjectself () override
 return associated python object. More...
 
virtual void handle (const Incident &incident) override
 callback method for the IIncidentSvc More...
 

Public Attributes

 sg_name
 init base class More...
 
 oname
 
 display_mall_infos
 
 heph_stats
 
 sg
 
 clidsvc
 
 ostream
 

Protected Member Functions

virtual bool setPyAttr (PyObject *pyobj) override
 attach the C++ component to its python cousin More...
 

Protected Attributes

PyObjectm_self
 Pointer to self (from the python world) More...
 

Private Attributes

 _sg_clear
 

Detailed Description

Definition at line 14 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.

Constructor & Destructor Documentation

◆ __init__()

def python.PyComps.PyStorePayloadMon.__init__ (   self,
  name = 'PyStorePayloadMon',
**  kw 
)

Definition at line 16 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.

16  def __init__(self, name='PyStorePayloadMon', **kw):
17 
18  super(PyStorePayloadMon, self).__init__(name, **kw)
19 
20 
21  self.sg_name = kw.get('sg_name', 'StoreGateSvc/StoreGateSvc')
22  """StoreGateSvc instance to monitor for DataProxy payload sizes"""
23 
24  self.oname = kw.get('oname', 'pmon_payload.ascii')
25  """Name of the output file where the monitoring data will be stored"""
26 
27  self.display_mall_infos = kw.get(
28  'display_mall_infos', False)
29  """display mallinfos stats after each event"""
30 
31  import Hephaestus.MemoryTracker as memtrack
32  from Hephaestus.MemoryTracker import FreeStatistics as heph_stats
33  self.heph_stats = heph_stats
34 
35  mask = memtrack.configure()
36  memtrack.configure( mask | memtrack.FREESTAT )
37  return
38 

Member Function Documentation

◆ execute()

def python.PyComps.PyStorePayloadMon.execute (   self)

Definition at line 88 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.

88  def execute(self):
89  proxies = list(self.sg.proxies())
90  data = []
91  fs = self.heph_stats
92  fd = self.ostream
93 
94  mem_store_0, ncalls_0 = fs.stat()
95  data = map(self.process_proxy, proxies)
96  mem_store_1, ncalls_1 = fs.stat()
97 
98  clid2name = self.clidsvc.typename
99  fmt = " (%10i, %10i, %10i, \"%s\", \"%s\"),"
100 
101  print(" [ ## new-event", file=fd)
102  for p, mem_0, mem_1 in data:
103  tp_name = clid2name(p.clID())
104  print(fmt, (mem_0, mem_1, mem_0 - mem_1, tp_name, p.name()), file=fd)
105  pass
106  mem_store_0 = int(mem_store_0)
107  mem_store_1 = int(mem_store_1)
108 
109  print(fmt, (
110  mem_store_0, mem_store_1, mem_store_0 - mem_store_1,
111  "StoreGateSvc", self.sg_name
112  ), file=fd)
113  print(" ],", file=fd)
114 
115  self.msg.info('flush-store: %10d -> %10d -- delta= %10d',
116  mem_store_0, mem_store_1, mem_store_0 - mem_store_1)
117  return StatusCode.Success
118 

◆ finalize() [1/2]

StatusCode PyAthena::Svc::finalize ( )
overridevirtualinherited

Definition at line 71 of file PyAthenaSvc.cxx.

72 {
73  ATH_MSG_INFO("Finalizing " << name() << "...");
74  return PyAthena::callPyMethod( m_self, "sysFinalize" );
75 }

◆ finalize() [2/2]

def python.PyComps.PyStorePayloadMon.finalize (   self)

Definition at line 136 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.

136  def finalize(self):
137  self.msg.info('==> finalize...')
138  print("] # data", file=self.ostream)
139  self.heph_stats.stop()
140 
141  return StatusCode.Success
142 

◆ handle() [1/2]

void PyAthena::Svc::handle ( const Incident &  incident)
overridevirtualinherited

callback method for the IIncidentSvc

Definition at line 122 of file PyAthenaSvc.cxx.

123 {
125  if (0 == PyObject_HasAttrString (m_self, (char*)"handle")) {
126  // python side does not implement 'handle'. Fair enough.
127  // XXX FIXME: could say something though: we have been registered as
128  // listener, so there might be some kind of inconsistency...
129  return;
130  }
131 
132  PyObject *o = TPython::CPPInstance_FromVoidPtr ((void*)(&inc), "Incident");
133  if (0 == o) {
134  Py_XDECREF (o);
136  }
137 
138  PyObject *res = PyObject_CallMethod (m_self,
139  (char*)"handle",
140  (char*)"O", o);
141  if (0 == res) {
142  Py_XDECREF (res);
143  Py_DECREF (o);
145  }
146 
147  Py_DECREF (res);
148  Py_DECREF (o);
149  return;
150 }

◆ handle() [2/2]

def python.PyComps.PyStorePayloadMon.handle (   self,
  incident 
)

Definition at line 74 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.

74  def handle(self, incident):
75  tp = incident.type()
76  if tp == 'BeginEvent':
77  self.heph_stats.reset()
78  #self.heph_stats.start()
79  pass
80  elif tp == 'EndEvent':
81  #self.heph_stats.stop()
82  self.execute()
83  #self.heph_stats.reset()
84  else:
85  pass
86  return
87 

◆ initialize() [1/2]

StatusCode PyAthena::Svc::initialize ( )
overridevirtualinherited

Gaudi Service Implementation.

Definition at line 57 of file PyAthenaSvc.cxx.

58 {
59  ATH_MSG_INFO("Initializing " << name() << "...");
60  return PyAthena::callPyMethod( m_self, "sysInitialize" );
61 }

◆ initialize() [2/2]

def python.PyComps.PyStorePayloadMon.initialize (   self)

Definition at line 39 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.

39  def initialize(self):
40  self.msg.info('==> initialize...')
41  self.sg = PyAthena.py_svc(self.sg_name)
42  if not self.sg:
43  self.msg.error('could not retrieve sg instance [%s]', self.sg_name)
44  return StatusCode.Failure
45 
46  ns = PyAthena.AthenaInternal
47  self._sg_clear = ns.py_sg_clearProxyPayload
48 
49  self.clidsvc = PyAthena.py_svc('ClassIDSvc/ClassIDSvc',
50  iface='IClassIDSvc')
51  if not self.clidsvc:
52  self.msg.error('could not retrieve clidsvc')
53  return StatusCode.Failure
54 
55  self.heph_stats.start()
56 
57  import os
58  import os.path
59  if os.path.exists(self.oname):
60  os.remove(self.oname)
61  self.ostream = open(self.oname, 'w')
62 
63  # describe data format
64  print("#data format: [[(bytes_0, bytes_1, delta, clid, sg_key),]]", file=self.ostream)
65  print("data = [", file=self.ostream)
66 
67  # register incident handles
68  incsvc = PyAthena.py_svc('IncidentSvc', iface='IIncidentSvc')
69  incsvc.addListener(self, 'BeginEvent')
70  incsvc.addListener(self, 'EndEvent')
71 
72  return StatusCode.Success
73 

◆ process_proxy()

def python.PyComps.PyStorePayloadMon.process_proxy (   self,
  p 
)

Definition at line 119 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.

119  def process_proxy(self, p):
120  fs = self.heph_stats
121  mem_0 = -1
122  mem_1 = -1
123  if p.clID() == 2101: # event-info
124  return (p, mem_0, mem_1)
125 
126  mem_0, ncalls_0 = fs.stat()
127  self._sg_clear(self.sg, p)
128  mem_1, ncalls_1 = fs.stat()
129 
130 
134  return (p, int(mem_0), int(mem_1))
135 

◆ reinitialize()

StatusCode PyAthena::Svc::reinitialize ( )
overridevirtualinherited

Definition at line 64 of file PyAthenaSvc.cxx.

65 {
66  ATH_MSG_INFO("Re-Initializing " << name() << "...");
67  return PyAthena::callPyMethod( m_self, "sysReinitialize" );
68 }

◆ self()

virtual PyObject* PyAthena::Svc::self ( )
inlineoverridevirtualinherited

return associated python object.

BORROWED reference.

Definition at line 68 of file PyAthenaSvc.h.

68 { return m_self; }

◆ setPyAttr()

bool PyAthena::Svc::setPyAttr ( PyObject pyobj)
overrideprotectedvirtualinherited

attach the C++ component to its python cousin

Definition at line 154 of file PyAthenaSvc.cxx.

155 {
156  // now we tell the PyObject which C++ object it is the cousin of.
158  PyObject* pyobj = TPython::CPPInstance_FromVoidPtr
159  ( (void*)this, this->typeName() );
160  if ( !pyobj ) {
161  PyErr_Clear();
162  // try PyAthena::Svc
163  pyobj = TPython::CPPInstance_FromVoidPtr ((void*)this, "PyAthena::Svc");
165  ("could not dyncast component [" << name() << "] to a python "
166  << "object of type [" << this->typeName() << "] (probably a missing "
167  << "dictionary)" << endmsg
168  << "fallback to [PyAthena::Svc]...");
169  }
170  if ( !pyobj ) {
171  PyErr_Clear();
173  ("Could not dyncast component [" << name() << "] to a pyobject of type ["
174  << this->typeName() << "]");
175  } else {
176  if ( -1 == PyObject_SetAttrString(o, "_cppHandle", pyobj) ) {
177  PyErr_Clear();
179  ("Could not attach C++ handle [" << name() << "] to its python "
180  << "cousin !");
181  if ( -1 == PyObject_SetAttrString(o, "_cppHandle", Py_None) ) {
182  PyErr_Clear();
184  ("could not attach a dummy C++ handle [" << name() << "] to its "
185  << "python cousin !");
186  }
187  } else {
188  return true;
189  }
190  }
191  return false;
192 }

◆ start()

StatusCode PyAthena::Svc::start ( )
overridevirtualinherited

Definition at line 78 of file PyAthenaSvc.cxx.

79 {
80  return PyAthena::callPyMethod( m_self, "sysStart" );
81 }

◆ stop()

StatusCode PyAthena::Svc::stop ( )
overridevirtualinherited

Definition at line 84 of file PyAthenaSvc.cxx.

85 {
86  return PyAthena::callPyMethod( m_self, "sysStop" );
87 }

◆ sysInitialize()

StatusCode PyAthena::Svc::sysInitialize ( )
overridevirtualinherited

Definition at line 90 of file PyAthenaSvc.cxx.

91 {
93  ( "PyAthena::PyComponentMgr/PyComponentMgr", name() );
94  if ( !pyMgr.retrieve().isSuccess() ) {
96  ("Could not retrieve service [" << pyMgr.typeAndName() << "] !!");
97  return StatusCode::FAILURE;
98  }
99 
100  // first retrieve our python object cousin...
101  m_self = pyMgr->pyObject( this );
102 
103  if ( m_self == Py_None ) {
104  ATH_MSG_ERROR("Wrapped PyObject is NONE !");
105  return StatusCode::FAILURE;
106  }
107 
108  // re-route to usual sysInit...
109  return SvcBase_t::sysInitialize();
110 }

◆ typeName()

const char * PyAthena::Svc::typeName ( ) const
overrideinherited

return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part

Definition at line 114 of file PyAthenaSvc.cxx.

115 {
116  static const std::string tname = System::typeinfoName(typeid(*this));
117  return tname.c_str();
118 }

Member Data Documentation

◆ _sg_clear

python.PyComps.PyStorePayloadMon._sg_clear
private

◆ clidsvc

python.PyComps.PyStorePayloadMon.clidsvc

◆ display_mall_infos

python.PyComps.PyStorePayloadMon.display_mall_infos

◆ heph_stats

python.PyComps.PyStorePayloadMon.heph_stats

◆ m_self

PyObject* PyAthena::Svc::m_self
protectedinherited

Pointer to self (from the python world)

Definition at line 89 of file PyAthenaSvc.h.

◆ oname

python.PyComps.PyStorePayloadMon.oname

◆ ostream

python.PyComps.PyStorePayloadMon.ostream

◆ sg

python.PyComps.PyStorePayloadMon.sg

◆ sg_name

python.PyComps.PyStorePayloadMon.sg_name

init base class

properties and data members

Definition at line 21 of file Control/PerformanceMonitoring/PerfMonComps/python/PyComps.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
PyAthena::throw_py_exception
void throw_py_exception(bool display=true)
helper function to capture the boilerplate code for user friendly stack trace display
Definition: PyAthenaUtils.cxx:134
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
initialize
void initialize()
Definition: run_EoverP.cxx:894
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
RootUtils::PyGILStateEnsure
Definition: PyAthenaGILStateEnsure.h:20
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PyAthena::Svc::typeName
const char * typeName() const override
return the std::type_info name of the underlying py-component This is used by concrete implementation...
Definition: PyAthenaSvc.cxx:114
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
PyAthena::Svc::m_self
PyObject * m_self
Pointer to self (from the python world)
Definition: PyAthenaSvc.h:89
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CxxUtils::reset
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset(E &lhs, E rhs)
Convenience function to clear bits in a class enum bitmask.
Definition: bitmask.h:251
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
error
Definition: IImpactPoint3dEstimator.h:70
PyObject
_object PyObject
Definition: IPyComponent.h:26
ServiceHandle
Definition: ClusterMakerTool.h:37