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 
7 #include "GaudiKernel/MsgStream.h"
8 #include "GaudiKernel/IChronoStatSvc.h"
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  MsgStream log(msgSvc(), name());
30  log << MSG::ERROR << "Cannot get ChronoStatSvc" << endmsg;
31  return StatusCode::FAILURE;
32  }
33  return StatusCode::SUCCESS;
34 }
35 
36 void MemStatAuditor::i_before(CustomEventTypeRef /*evt*/, const std::string& /*caller*/) {
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  // cannot be exactly 0
42  double deltaVSize = 0.00001;
43 
44  procInfo info;
45  if (getProcInfo(info)) {
46  MsgStream log(msgSvc(), name());
47 
48  if (info.vsize > 0) {
49  if (m_vSize > 0){
50  deltaVSize = info.vsize - m_vSize;
51  }
52  // store the current VSize to be able to monitor the increment
53  m_vSize = info.vsize;
54  }
55 
56  log << MSG::INFO << msg << " " << caller << " " << evt <<
57  " \tvirtual size = " << info.vsize << " MB" <<
58  " \tresident set size = " << info.rss << " MB" <<
59  " deltaVsize = " << deltaVSize << " MB" << endmsg;
60  }
61  // fill the stat for every call, not just when there is a change
62  // only monitor the increment in VSize
63  // Stat stv(statSvc(), caller + ":VMemUsage", info.vsize);
64  // Stat str(statSvc(), caller + ":RMemUsage", info.rss);
65  Stat sts(statSvc(), caller + ":VMem", deltaVSize);
66 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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 & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:220
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
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
double rss
Definition: ProcStats.h:38
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
double m_vSize
vsize of the previous call to printinfo
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
Definition: Auditor.cpp:228
SmartIF< IChronoStatSvc > m_stat
static bool getProcInfo(procInfo &info)
Get the process informations.
Definition: MemoryAuditor.h:27
const std::string & name() const override
Definition: Auditor.cpp:212
#define UNLIKELY(x)
Definition: Kernel.h:126
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:91
Monitors the memory use of each algorithm.
Definition: MemoryAuditor.h:11
double vsize
Definition: ProcStats.h:37
SmartIF< IChronoStatSvc > & statSvc()
void i_printinfo(const std::string &msg, CustomEventTypeRef evt, const std::string &caller) override
Report the memory usage.