The Gaudi Framework  v33r0 (d5ea422b)
MemStatAuditor.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifdef __ICC
12 // disable icc warning #654: overloaded virtual function "B::Y" is only partially overridden in class "C"
13 // TODO: there is only a partial overload of IAuditor::before and IAuditor::after
14 # pragma warning( disable : 654 )
15 #endif
16 
18 #include "GaudiKernel/MsgStream.h"
19 
20 #include "GaudiKernel/Stat.h"
21 
23 #include "MemStatAuditor.h"
24 #include "ProcStats.h"
25 
27 
28 StatusCode MemStatAuditor::initialize() {
30  if ( UNLIKELY( sc.isFailure() ) ) return sc;
31 
32  m_stat = serviceLocator()->service( "ChronoStatSvc" );
33  if ( UNLIKELY( !m_stat.get() ) ) {
34  error() << "Cannot get ChronoStatSvc" << endmsg;
35  return StatusCode::FAILURE;
36  }
37  return StatusCode::SUCCESS;
38 }
39 
40 void MemStatAuditor::i_before( CustomEventTypeRef /*evt*/, const std::string& /*caller*/ ) {
41  // It's not interesting to monitor the memory usage before the methods.
42 }
43 
44 void MemStatAuditor::i_printinfo( const std::string& msg, CustomEventTypeRef evt, const std::string& caller ) {
45  // cannot be exactly 0
46  double deltaVSize = 0.00001;
47 
48  procInfo pInfo;
49  if ( getProcInfo( pInfo ) ) {
50 
51  if ( pInfo.vsize > 0 ) {
52  if ( m_vSize > 0 ) { deltaVSize = pInfo.vsize - m_vSize; }
53  // store the current VSize to be able to monitor the increment
54  m_vSize = pInfo.vsize;
55  }
56 
57  info() << msg << " " << caller << " " << evt << " \tvirtual size = " << pInfo.vsize << " MB"
58  << " \tresident set size = " << pInfo.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", pInfo.vsize);
64  // Stat str(statSvc(), caller + ":RMemUsage", pInfo.rss);
65  Stat sts( statSvc(), caller + ":VMem", deltaVSize );
66 }
#define UNLIKELY(x)
Definition: Kernel.h:106
Just a minor modification of MemoryAuditor to allow the output memory statistics table to be printed.
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition: Stat.h:56
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
STL class.
#define DECLARE_COMPONENT(type)
double rss
Definition: ProcStats.h:48
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
double m_vSize
vsize of the previous call to printinfo
static bool getProcInfo(procInfo &info)
Get the process informations.
Definition: MemoryAuditor.h:37
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
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:74
bool isFailure() const
Definition: StatusCode.h:141
double vsize
Definition: ProcStats.h:47
SmartIF< IChronoStatSvc > & statSvc()
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
void i_printinfo(const std::string &msg, CustomEventTypeRef evt, const std::string &caller) override
Report the memory usage.