Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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>
16 #include <GaudiKernel/MsgStream.h>
17 
22 class MemoryAuditor : public Gaudi::Auditor {
23 public:
24  using Auditor::Auditor;
25 
26 protected:
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 
39 void MemoryAuditor::before( std::string const& evt, std::string const& caller, EventContext const& ) {
40  i_printinfo( "Memory usage before", evt, caller );
41 }
42 
43 void 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 
47 void 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 }
IOTest.evt
evt
Definition: IOTest.py:107
GaudiPartProp.decorators.std
std
Definition: decorators.py:32
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
procInfo
Definition: ProcStats.h:29
ProcStats::instance
static ProcStats * instance()
Definition: ProcStats.cpp:239
StatusCode
Definition: StatusCode.h:64
ProcStats.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:45
ProcStats::fetch
bool fetch(procInfo &fill_me)
Definition: ProcStats.cpp:259
EventContext
Definition: EventContext.h:34
MemoryAuditor::before
void before(std::string const &evt, std::string const &, EventContext const &) override
Default (catch-all) "before" Auditor hook.
Definition: MemoryAuditor.cpp:39
Gaudi::Auditor
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:33
MemoryAuditor
Monitors the memory use of each algorithm.
Definition: MemoryAuditor.cpp:22
MemoryAuditor::after
void after(std::string const &evt, std::string const &caller, EventContext const &, const StatusCode &sc) override
Default (catch-all) "after" Auditor hook.
Definition: MemoryAuditor.cpp:43
MsgStream.h
MemoryAuditor::i_printinfo
virtual void i_printinfo(std::string_view msg, std::string const &evt, std::string_view caller)
Report the memory usage.
Definition: MemoryAuditor.cpp:47
Auditor.h