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 "ProcStats.h"
14 #include "MemStatAuditor.h"
15 
17 
18 MemStatAuditor::MemStatAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
19  MemoryAuditor(name, pSvcLocator)
20 {
21 }
22 
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  // It's not interesting to monitor the memory usage before the methods.
37 }
38 
39 void MemStatAuditor::i_printinfo(const std::string& msg, CustomEventTypeRef evt, const std::string& caller) {
40  // cannot be exactly 0
41  double deltaVSize = 0.00001;
42 
43  procInfo pInfo;
44  if (getProcInfo(pInfo)) {
45 
46  if (pInfo.vsize > 0) {
47  if (m_vSize > 0){
48  deltaVSize = pInfo.vsize - m_vSize;
49  }
50  // store the current VSize to be able to monitor the increment
51  m_vSize = pInfo.vsize;
52  }
53 
54  info() << msg << " " << caller << " " << evt <<
55  " \tvirtual size = " << pInfo.vsize << " MB" <<
56  " \tresident set size = " << pInfo.rss << " MB" <<
57  " deltaVsize = " << deltaVSize << " MB" << endmsg;
58  }
59  // fill the stat for every call, not just when there is a change
60  // only monitor the increment in VSize
61  // Stat stv(statSvc(), caller + ":VMemUsage", pInfo.vsize);
62  // Stat str(statSvc(), caller + ":RMemUsage", pInfo.rss);
63  Stat sts(statSvc(), caller + ":VMem", deltaVSize);
64 }
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
#define UNLIKELY(x)
Definition: Kernel.h:126
STL namespace.
StatusCode initialize() override
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
STL class.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
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:26
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:27
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:244
evt
Definition: IOTest.py:85
void i_printinfo(const std::string &msg, CustomEventTypeRef evt, const std::string &caller) override
Report the memory usage.