The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
MemoryAuditor.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// MemoryAuditor:
12// An auditor that monitors memory usage
13
14#include "ProcStats.h"
15#include <Gaudi/Auditor.h>
17
23public:
24 using Auditor::Auditor;
25
26protected:
28 void before( std::string const& evt, std::string const&, EventContext const& ) override;
29
31 void after( std::string const& evt, std::string const& caller, EventContext const&, const StatusCode& sc ) override;
32
34 virtual void i_printinfo( std::string_view msg, std::string const& evt, std::string_view caller );
35};
36
38
39void MemoryAuditor::before( std::string const& evt, std::string const& caller, EventContext const& ) {
40 i_printinfo( "Memory usage before", evt, caller );
41}
42
43void MemoryAuditor::after( std::string const& evt, std::string const& caller, EventContext const&, const StatusCode& ) {
44 i_printinfo( "Memory usage has changed after", evt, caller );
45}
46
47void MemoryAuditor::i_printinfo( std::string_view msg, std::string const& evt, std::string_view caller ) {
50 if ( procInfo pInfo; ProcStats::instance()->fetch( pInfo ) ) {
51 if ( pInfo.vsize > 0 ) {
52 info() << msg << " " << caller << " " << evt << " virtual size = " << pInfo.vsize << " MB"
53 << " resident set size = " << pInfo.rss << " MB" << endmsg;
54 }
55 }
56}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
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
Monitors the memory use of each algorithm.
virtual void i_printinfo(std::string_view msg, std::string const &evt, std::string_view caller)
Report the memory usage.
void before(std::string const &evt, std::string const &, EventContext const &) override
Default (catch-all) "before" Auditor hook.
void after(std::string const &evt, std::string const &caller, EventContext const &, const StatusCode &sc) override
Default (catch-all) "after" Auditor hook.
bool fetch(procInfo &fill_me)
static ProcStats * instance()
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
STL namespace.