The Gaudi Framework
master (bb4415cc)
Toggle main menu visibility
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
>
24
#include <
GaudiKernel/IChronoStatSvc.h
>
25
#include <
GaudiKernel/MsgStream.h
>
26
#include <
GaudiKernel/Stat.h
>
27
28
class
MemStatAuditor
:
public
Gaudi::Auditor
{
29
public
:
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
42
private
:
43
void
i_printinfo
( std::string_view
msg
, std::string
const
& evt, std::string_view caller );
44
SmartIF<IChronoStatSvc>
m_stat
;
45
47
double
m_vSize
= -1;
48
};
49
50
DECLARE_COMPONENT
(
MemStatAuditor
)
51
52
StatusCode
MemStatAuditor
::
initialize
() {
53
return
Auditor::initialize().andThen( [&]() ->
StatusCode
{
54
m_stat
=
serviceLocator
()->service(
"ChronoStatSvc"
);
55
if
( !
m_stat
) {
56
error
() <<
"Cannot get ChronoStatSvc"
<<
endmsg
;
57
return
StatusCode::FAILURE
;
58
}
59
return
StatusCode::SUCCESS
;
60
} );
61
}
62
63
void
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
}
Auditor.h
IChronoStatSvc.h
MsgStream.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.h
Stat.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::msg
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:124
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
EventContext
This class represents an entry point to all the event specific data.
Definition
EventContext.h:35
Gaudi::Auditor
Base class from which all concrete auditor classes should be derived.
Definition
Auditor.h:33
Gaudi::Auditor::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition
Auditor.h:59
MemStatAuditor
Just a minor modification of MemoryAuditor to allow the output memory statistics table to be printed.
Definition
MemStatAuditor.cpp:28
MemStatAuditor::i_printinfo
void i_printinfo(std::string_view msg, std::string const &evt, std::string_view caller)
Definition
MemStatAuditor.cpp:63
MemStatAuditor::before
void before(std::string const &, std::string const &, EventContext const &) override
Definition
MemStatAuditor.cpp:34
MemStatAuditor::m_vSize
double m_vSize
vsize of the previous call to printinfo
Definition
MemStatAuditor.cpp:47
MemStatAuditor::m_stat
SmartIF< IChronoStatSvc > m_stat
Definition
MemStatAuditor.cpp:44
MemStatAuditor::initialize
StatusCode initialize() override
Definition
MemStatAuditor.cpp:52
MemStatAuditor::after
void after(std::string const &evt, std::string const &caller, EventContext const &, const StatusCode &) override
Definition
MemStatAuditor.cpp:38
ProcStats::fetch
bool fetch(procInfo &fill_me)
Definition
ProcStats.cpp:259
ProcStats::instance
static ProcStats * instance()
Definition
ProcStats.cpp:239
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition
SmartIF.h:28
Stat
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition
Stat.h:48
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
procInfo
Definition
ProcStats.h:29
GaudiAud
src
MemStatAuditor.cpp
Generated on
for The Gaudi Framework by
1.17.0