The Gaudi Framework  master (37c0b60a)
MemoryAuditor.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 "CommonAuditor.h"
15 #include "ProcStats.h"
16 #include <GaudiKernel/MsgStream.h>
17 
22 class MemoryAuditor : public CommonAuditor {
23 public:
24  using CommonAuditor::CommonAuditor;
25 
26 protected:
28  void i_before( CustomEventTypeRef evt, std::string_view caller ) override;
29 
31  void i_after( CustomEventTypeRef evt, std::string_view caller, const StatusCode& sc ) override;
32 
34  virtual void i_printinfo( std::string_view msg, CustomEventTypeRef evt, std::string_view caller );
35 };
36 
38 
39 void MemoryAuditor::i_before( CustomEventTypeRef evt, std::string_view caller ) {
40  i_printinfo( "Memory usage before", evt, caller );
41 }
42 
43 void MemoryAuditor::i_after( CustomEventTypeRef evt, std::string_view caller, const StatusCode& ) {
44  i_printinfo( "Memory usage has changed after", evt, caller );
45 }
46 
47 void MemoryAuditor::i_printinfo( std::string_view msg, CustomEventTypeRef 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
CommonAuditor
Base class with common functionalities shared by few auditor implementations.
Definition: CommonAuditor.h:18
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
procInfo
Definition: ProcStats.h:29
ProcStats::instance
static ProcStats * instance()
Definition: ProcStats.cpp:239
MemoryAuditor::i_after
void i_after(CustomEventTypeRef evt, std::string_view caller, const StatusCode &sc) override
Default (catch-all) "after" Auditor hook.
Definition: MemoryAuditor.cpp:43
StatusCode
Definition: StatusCode.h:65
MemoryAuditor::i_printinfo
virtual void i_printinfo(std::string_view msg, CustomEventTypeRef evt, std::string_view caller)
Report the memory usage.
Definition: MemoryAuditor.cpp:47
MemoryAuditor::i_before
void i_before(CustomEventTypeRef evt, std::string_view caller) override
Default (catch-all) "before" Auditor hook.
Definition: MemoryAuditor.cpp:39
ProcStats.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
ProcStats::fetch
bool fetch(procInfo &fill_me)
Definition: ProcStats.cpp:259
MemoryAuditor
Monitors the memory use of each algorithm.
Definition: MemoryAuditor.cpp:22
CommonAuditor.h
MsgStream.h