Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 StatusCode MemStatAuditor::initialize() {
20  if ( UNLIKELY( sc.isFailure() ) ) return sc;
21 
22  m_stat = serviceLocator()->service( "ChronoStatSvc" );
23  if ( UNLIKELY( !m_stat.get() ) ) {
24  error() << "Cannot get ChronoStatSvc" << endmsg;
25  return StatusCode::FAILURE;
26  }
27  return StatusCode::SUCCESS;
28 }
29 
30 void MemStatAuditor::i_before( CustomEventTypeRef /*evt*/, const std::string& /*caller*/ ) {
31  // It's not interesting to monitor the memory usage before the methods.
32 }
33 
34 void MemStatAuditor::i_printinfo( const std::string& msg, CustomEventTypeRef evt, const std::string& caller ) {
35  // cannot be exactly 0
36  double deltaVSize = 0.00001;
37 
38  procInfo pInfo;
39  if ( getProcInfo( pInfo ) ) {
40 
41  if ( pInfo.vsize > 0 ) {
42  if ( m_vSize > 0 ) { deltaVSize = pInfo.vsize - m_vSize; }
43  // store the current VSize to be able to monitor the increment
44  m_vSize = pInfo.vsize;
45  }
46 
47  info() << msg << " " << caller << " " << evt << " \tvirtual size = " << pInfo.vsize << " MB"
48  << " \tresident set size = " << pInfo.rss << " MB"
49  << " deltaVsize = " << deltaVSize << " MB" << endmsg;
50  }
51  // fill the stat for every call, not just when there is a change
52  // only monitor the increment in VSize
53  // Stat stv(statSvc(), caller + ":VMemUsage", pInfo.vsize);
54  // Stat str(statSvc(), caller + ":RMemUsage", pInfo.rss);
55  Stat sts( statSvc(), caller + ":VMem", deltaVSize );
56 }
#define UNLIKELY(x)
Definition: Kernel.h:89
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
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
bool isFailure() const
Definition: StatusCode.h:130
STL class.
#define DECLARE_COMPONENT(type)
double rss
Definition: ProcStats.h:38
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
double m_vSize
vsize of the previous call to printinfo
static bool getProcInfo(procInfo &info)
Get the process informations.
Definition: MemoryAuditor.h:27
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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:64
double vsize
Definition: ProcStats.h:37
SmartIF< IChronoStatSvc > & statSvc()
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
evt
Definition: IOTest.py:94
void i_printinfo(const std::string &msg, CustomEventTypeRef evt, const std::string &caller) override
Report the memory usage.