The Gaudi Framework  v29r0 (ff2e7097)
MemStatAuditor.cpp
Go to the documentation of this file.
1 #ifdef __ICC
2 // disable icc warning #654: overloaded virtual function "B::Y" is only partially overridden in class "C"
3 // TODO: there is only a partial overload of IAuditor::before and IAuditor::after
4 #pragma warning( disable : 654 )
5 #endif
6 
9 
10 #include "GaudiKernel/Stat.h"
11 
13 #include "MemStatAuditor.h"
14 #include "ProcStats.h"
15 
17 
18 MemStatAuditor::MemStatAuditor( const std::string& name, ISvcLocator* pSvcLocator ) : MemoryAuditor( name, pSvcLocator )
19 {
20 }
21 
23 {
25  if ( UNLIKELY( sc.isFailure() ) ) return sc;
26 
27  m_stat = serviceLocator()->service( "ChronoStatSvc" );
28  if ( UNLIKELY( !m_stat.get() ) ) {
29  error() << "Cannot get ChronoStatSvc" << endmsg;
30  return StatusCode::FAILURE;
31  }
32  return StatusCode::SUCCESS;
33 }
34 
35 void MemStatAuditor::i_before( CustomEventTypeRef /*evt*/, const std::string& /*caller*/ )
36 {
37  // It's not interesting to monitor the memory usage before the methods.
38 }
39 
40 void MemStatAuditor::i_printinfo( const std::string& msg, CustomEventTypeRef evt, const std::string& caller )
41 {
42  // cannot be exactly 0
43  double deltaVSize = 0.00001;
44 
45  procInfo pInfo;
46  if ( getProcInfo( pInfo ) ) {
47 
48  if ( pInfo.vsize > 0 ) {
49  if ( m_vSize > 0 ) {
50  deltaVSize = pInfo.vsize - m_vSize;
51  }
52  // store the current VSize to be able to monitor the increment
53  m_vSize = pInfo.vsize;
54  }
55 
56  info() << msg << " " << caller << " " << evt << " \tvirtual size = " << pInfo.vsize << " MB"
57  << " \tresident set size = " << pInfo.rss << " MB"
58  << " deltaVsize = " << deltaVSize << " MB" << endmsg;
59  }
60  // fill the stat for every call, not just when there is a change
61  // only monitor the increment in VSize
62  // Stat stv(statSvc(), caller + ":VMemUsage", pInfo.vsize);
63  // Stat str(statSvc(), caller + ":RMemUsage", pInfo.rss);
64  Stat sts( statSvc(), caller + ":VMem", deltaVSize );
65 }
#define UNLIKELY(x)
Definition: Kernel.h:128
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Just a minor modification of MemoryAuditor to allow the output memory statistics table to be printed...
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
Definition: Stat.h:46
STL namespace.
StatusCode initialize() override
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
STL class.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
double rss
Definition: ProcStats.h:39
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Auditor.cpp:206
double m_vSize
vsize of the previous call to printinfo
SmartIF< IChronoStatSvc > m_stat
static bool getProcInfo(procInfo &info)
Get the process informations.
Definition: MemoryAuditor.h:28
void i_before(CustomEventTypeRef evt, const std::string &caller) override
Re-implement i_before to avoid monitoring the memory usage before a function.
virtual StatusCode initialize()
Definition: Auditor.cpp:70
Monitors the memory use of each algorithm.
Definition: MemoryAuditor.h:11
double vsize
Definition: ProcStats.h:38
SmartIF< IChronoStatSvc > & statSvc()
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
evt
Definition: IOTest.py:96
void i_printinfo(const std::string &msg, CustomEventTypeRef evt, const std::string &caller) override
Report the memory usage.