The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
MemStatAuditor.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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
21
22#include "ProcStats.h"
23#include <Gaudi/Auditor.h>
26#include <GaudiKernel/Stat.h>
27
29public:
30 using Auditor::Auditor;
31
32 StatusCode initialize() override;
33
34 void before( std::string const& /*evt*/, std::string const& /*caller*/, EventContext const& ) override {
35 // It's not interesting to monitor the memory usage before the methods.
36 }
37
38 void after( std::string const& evt, std::string const& caller, EventContext const&, const StatusCode& ) override {
39 i_printinfo( "Memory usage has changed after", evt, caller );
40 }
41
42private:
43 void i_printinfo( std::string_view msg, std::string const& evt, std::string_view caller );
45
47 double m_vSize = -1;
48};
49
51
53 return Auditor::initialize().andThen( [&]() -> StatusCode {
54 m_stat = serviceLocator()->service( "ChronoStatSvc" );
55 if ( !m_stat ) {
56 error() << "Cannot get ChronoStatSvc" << endmsg;
58 }
60 } );
61}
62
63void MemStatAuditor::i_printinfo( std::string_view msg, std::string const& evt, std::string_view caller ) {
64 // cannot be exactly 0
65 double deltaVSize = 0.00001;
66
67 if ( procInfo pInfo; ProcStats::instance()->fetch( pInfo ) ) {
68
69 if ( pInfo.vsize > 0 ) {
70 if ( m_vSize > 0 ) { deltaVSize = pInfo.vsize - m_vSize; }
71 // store the current VSize to be able to monitor the increment
72 m_vSize = pInfo.vsize;
73 }
74
75 info() << msg << " " << caller << " " << evt << " \tvirtual size = " << pInfo.vsize << " MB"
76 << " \tresident set size = " << pInfo.rss << " MB"
77 << " deltaVsize = " << deltaVSize << " MB" << endmsg;
78 }
79 // fill the stat for every call, not just when there is a change
80 // only monitor the increment in VSize
81 // Stat stv(m_stat, caller + ":VMemUsage", pInfo.vsize);
82 // Stat str(m_stat, caller + ":RMemUsage", pInfo.rss);
83 Stat sts( m_stat, std::string{ caller }.append( ":VMem" ), deltaVSize );
84}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
This class represents an entry point to all the event specific data.
Base class from which all concrete auditor classes should be derived.
Definition Auditor.h:33
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition Auditor.h:59
Just a minor modification of MemoryAuditor to allow the output memory statistics table to be printed.
void i_printinfo(std::string_view msg, std::string const &evt, std::string_view caller)
void before(std::string const &, std::string const &, EventContext const &) override
double m_vSize
vsize of the previous call to printinfo
SmartIF< IChronoStatSvc > m_stat
StatusCode initialize() override
void after(std::string const &evt, std::string const &caller, EventContext const &, const StatusCode &) override
bool fetch(procInfo &fill_me)
static ProcStats * instance()
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition Stat.h:48
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100