The Gaudi Framework  v30r3 (a5ef0a68)
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 
19 {
21  if ( UNLIKELY( sc.isFailure() ) ) return sc;
22 
23  m_stat = serviceLocator()->service( "ChronoStatSvc" );
24  if ( UNLIKELY( !m_stat.get() ) ) {
25  error() << "Cannot get ChronoStatSvc" << endmsg;
26  return StatusCode::FAILURE;
27  }
28  return StatusCode::SUCCESS;
29 }
30 
31 void MemStatAuditor::i_before( CustomEventTypeRef /*evt*/, const std::string& /*caller*/ )
32 {
33  // It's not interesting to monitor the memory usage before the methods.
34 }
35 
36 void MemStatAuditor::i_printinfo( const std::string& msg, CustomEventTypeRef evt, const std::string& caller )
37 {
38  // cannot be exactly 0
39  double deltaVSize = 0.00001;
40 
41  procInfo pInfo;
42  if ( getProcInfo( pInfo ) ) {
43 
44  if ( pInfo.vsize > 0 ) {
45  if ( m_vSize > 0 ) {
46  deltaVSize = pInfo.vsize - m_vSize;
47  }
48  // store the current VSize to be able to monitor the increment
49  m_vSize = pInfo.vsize;
50  }
51 
52  info() << msg << " " << caller << " " << evt << " \tvirtual size = " << pInfo.vsize << " MB"
53  << " \tresident set size = " << pInfo.rss << " MB"
54  << " deltaVsize = " << deltaVSize << " MB" << endmsg;
55  }
56  // fill the stat for every call, not just when there is a change
57  // only monitor the increment in VSize
58  // Stat stv(statSvc(), caller + ":VMemUsage", pInfo.vsize);
59  // Stat str(statSvc(), caller + ":RMemUsage", pInfo.rss);
60  Stat sts( statSvc(), caller + ":VMem", deltaVSize );
61 }
#define UNLIKELY(x)
Definition: Kernel.h:122
constexpr static const auto FAILURE
Definition: StatusCode.h:88
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
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 interface.
Definition: Stat.h:46
bool isFailure() const
Definition: StatusCode.h:139
STL class.
#define DECLARE_COMPONENT(type)
double rss
Definition: ProcStats.h:39
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
double m_vSize
vsize of the previous call to printinfo
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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
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.