All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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), m_vSize(-1.)
20 {
21 }
22 
24 
27  if (UNLIKELY(sc.isFailure())) return sc;
28 
29  m_stat = serviceLocator()->service("ChronoStatSvc");
30  if (UNLIKELY(!m_stat.get())) {
31  MsgStream log(msgSvc(), name());
32  log << MSG::ERROR << "Cannot get ChronoStatSvc" << endmsg;
33  return StatusCode::FAILURE;
34  }
35  return StatusCode::SUCCESS;
36 }
37 
38 void MemStatAuditor::i_before(CustomEventTypeRef /*evt*/, const std::string& /*caller*/) {
39  // It's not interesting to monitor the memory usage before the methods.
40 }
41 
42 void MemStatAuditor::i_printinfo(const std::string& msg, CustomEventTypeRef evt, const std::string& caller) {
43  // cannot be exactly 0
44  double deltaVSize = 0.00001;
45 
46  procInfo info;
47  if (getProcInfo(info)) {
48  MsgStream log(msgSvc(), name());
49 
50  if (info.vsize > 0) {
51  if (m_vSize > 0){
52  deltaVSize = info.vsize - m_vSize;
53  }
54  // store the current VSize to be able to monitor the increment
55  m_vSize = info.vsize;
56  }
57 
58  log << MSG::INFO << msg << " " << caller << " " << evt <<
59  " \tvirtual size = " << info.vsize << " MB" <<
60  " \tresident set size = " << info.rss << " MB" <<
61  " deltaVsize = " << deltaVSize << " MB" << endmsg;
62  }
63  // fill the stat for every call, not just when there is a change
64  // only monitor the increment in VSize
65  // Stat stv(statSvc(), caller + ":VMemUsage", info.vsize);
66  // Stat str(statSvc(), caller + ":RMemUsage", info.rss);
67  Stat sts(statSvc(), caller + ":VMem", deltaVSize);
68 }
#define UNLIKELY(x)
Definition: Kernel.h:127
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:26
Just a minor modification of MemoryAuditor to allow the output memory statistics table to be printed...
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
Definition: Stat.h:50
const CustomEventType & CustomEventTypeRef
Used in function calls for optimization purposes.
Definition: IAuditor.h:41
virtual StatusCode initialize()
virtual void i_before(CustomEventTypeRef evt, const std::string &caller)
Re-implement i_before to avoid monitoring the memory usage before a function.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
virtual ~MemStatAuditor()
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
double rss
Definition: ProcStats.h:34
virtual void i_printinfo(const std::string &msg, CustomEventTypeRef evt, const std::string &caller)
Report the memory usage.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
double m_vSize
vsize of the previous call to printinfo
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
Definition: Auditor.cpp:236
SmartIF< IChronoStatSvc > m_stat
static bool getProcInfo(procInfo &info)
Get the process informations.
Definition: MemoryAuditor.h:27
virtual StatusCode initialize()
Definition: Auditor.cpp:97
Monitors the memory use of each algorithm.
Definition: MemoryAuditor.h:11
double vsize
Definition: ProcStats.h:33
SmartIF< IChronoStatSvc > & statSvc()
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244