ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoop
Root
AlgorithmMemoryWrapper.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
9
//
10
// includes
11
//
12
13
#include <
EventLoop/AlgorithmMemoryWrapper.h
>
14
15
#include <
EventLoop/MessageCheck.h
>
16
#include <
RootCoreUtils/Assert.h
>
17
#include <TSystem.h>
18
#include <iomanip>
19
#include <ios>
20
#include <numeric>
21
22
//
23
// method implementations
24
//
25
26
namespace
EL
27
{
28
void
AlgorithmMemoryWrapper ::
29
testInvariant ()
const
30
{
31
}
32
33
34
35
AlgorithmMemoryWrapper ::
36
AlgorithmMemoryWrapper (std::unique_ptr<IAlgorithmWrapper>&& val_algorithm)
37
:
m_algorithm
(
std
::move (val_algorithm))
38
{
39
RCU_NEW_INVARIANT
(
this
);
40
}
41
42
43
44
std::string_view AlgorithmMemoryWrapper ::
45
getName ()
const
46
{
47
RCU_READ_INVARIANT
(
this
);
48
return
m_algorithm
->getName();
49
}
50
51
52
53
bool
AlgorithmMemoryWrapper ::
54
hasName (
const
std::string& name)
const
55
{
56
RCU_READ_INVARIANT
(
this
);
57
return
m_algorithm
->hasName (name);
58
}
59
60
61
62
std::unique_ptr<IAlgorithmWrapper> AlgorithmMemoryWrapper ::
63
makeClone()
const
64
{
65
using namespace
msgEventLoop;
66
RCU_READ_INVARIANT
(
this
);
67
68
return
std::make_unique<AlgorithmMemoryWrapper> (
m_algorithm
->makeClone());
69
}
70
71
72
73
Algorithm
*AlgorithmMemoryWrapper ::
74
getLegacyAlg ()
75
{
76
RCU_READ_INVARIANT
(
this
);
77
return
m_algorithm
->getLegacyAlg();
78
}
79
80
81
82
StatusCode
AlgorithmMemoryWrapper ::
83
initialize (
const
AlgorithmWorkerData
& workerData)
84
{
85
using namespace
msgEventLoop;
86
RCU_CHANGE_INVARIANT
(
this
);
87
88
ANA_CHECK
(
recordPreMemory
());
89
auto
result =
m_algorithm
->initialize (workerData);
90
ANA_CHECK
(
recordPostMemory
());
91
return
result;
92
}
93
94
95
96
StatusCode
AlgorithmMemoryWrapper ::
97
execute (
const
EventContext& ctx)
98
{
99
using namespace
msgEventLoop;
100
RCU_CHANGE_INVARIANT
(
this
);
101
102
ANA_CHECK
(
recordPreMemory
());
103
auto
result =
m_algorithm
->execute (ctx);
104
ANA_CHECK
(
recordPostMemory
());
105
return
result;
106
}
107
108
109
110
StatusCode
AlgorithmMemoryWrapper ::
111
postExecute ()
112
{
113
using namespace
msgEventLoop;
114
RCU_CHANGE_INVARIANT
(
this
);
115
116
ANA_CHECK
(
recordPreMemory
());
117
auto
result =
m_algorithm
->postExecute ();
118
ANA_CHECK
(
recordPostMemory
());
119
return
result;
120
}
121
122
123
124
StatusCode
AlgorithmMemoryWrapper ::
125
finalize ()
126
{
127
using namespace
msgEventLoop;
128
RCU_CHANGE_INVARIANT
(
this
);
129
130
ANA_CHECK
(
recordPreMemory
());
131
auto
result =
m_algorithm
->finalize ();
132
ANA_CHECK
(
recordPostMemory
());
133
std::ostringstream
str
;
134
str
<<
"algorithm memory: "
<<
m_algorithm
->getName() <<
" rss="
;
135
for
(
auto
& rss :
m_mem_resident
)
136
str
<< rss <<
","
;
137
str
<<
" vss="
;
138
for
(
auto
& vss :
m_mem_virtual
)
139
str
<< vss <<
","
;
140
ANA_MSG_INFO
(
str
.str());
141
return
result;
142
}
143
144
145
146
StatusCode
AlgorithmMemoryWrapper ::
147
fileExecute ()
148
{
149
using namespace
msgEventLoop;
150
RCU_CHANGE_INVARIANT
(
this
);
151
152
ANA_CHECK
(
recordPreMemory
());
153
auto
result =
m_algorithm
->fileExecute ();
154
ANA_CHECK
(
recordPostMemory
());
155
return
result;
156
}
157
158
159
160
StatusCode
AlgorithmMemoryWrapper ::
161
beginInputFile ()
162
{
163
using namespace
msgEventLoop;
164
RCU_CHANGE_INVARIANT
(
this
);
165
166
ANA_CHECK
(
recordPreMemory
());
167
auto
result =
m_algorithm
->beginInputFile ();
168
ANA_CHECK
(
recordPostMemory
());
169
return
result;
170
}
171
172
173
174
StatusCode
AlgorithmMemoryWrapper ::
175
endInputFile ()
176
{
177
using namespace
msgEventLoop;
178
RCU_CHANGE_INVARIANT
(
this
);
179
180
ANA_CHECK
(
recordPreMemory
());
181
auto
result =
m_algorithm
->endInputFile ();
182
ANA_CHECK
(
recordPostMemory
());
183
return
result;
184
}
185
186
187
188
StatusCode
AlgorithmMemoryWrapper ::
189
recordPreMemory()
190
{
191
using namespace
msgEventLoop;
192
RCU_CHANGE_INVARIANT
(
this
);
193
::ProcInfo_t pinfo;
194
if
(gSystem->GetProcInfo (&pinfo) != 0) {
195
ANA_MSG_ERROR
(
"Could not get memory usage information"
);
196
return
StatusCode::FAILURE;
197
}
198
m_preMem_resident
= pinfo.fMemResident;
199
m_preMem_virtual
= pinfo.fMemVirtual;
200
return
StatusCode::SUCCESS;
201
}
202
203
204
205
StatusCode
AlgorithmMemoryWrapper ::
206
recordPostMemory()
207
{
208
constexpr
std::size_t max_entries = 3;
209
210
using namespace
msgEventLoop;
211
RCU_CHANGE_INVARIANT
(
this
);
212
::ProcInfo_t pinfo;
213
if
(gSystem->GetProcInfo (&pinfo) != 0) {
214
ANA_MSG_ERROR
(
"Could not get memory usage information"
);
215
return
StatusCode::FAILURE;
216
}
217
m_mem_resident
.push_back (pinfo.fMemResident -
m_preMem_resident
);
218
std::sort
(
m_mem_resident
.begin()+1,
m_mem_resident
.end(), std::greater<Long_t>());
219
if
(
m_mem_resident
.size() > max_entries)
220
m_mem_resident
.resize (max_entries);
221
m_mem_virtual
.push_back (pinfo.fMemVirtual -
m_preMem_virtual
);
222
std::sort
(
m_mem_virtual
.begin()+1,
m_mem_virtual
.end(), std::greater<Long_t>());
223
if
(
m_mem_virtual
.size() > max_entries)
224
m_mem_virtual
.resize (max_entries);
225
return
StatusCode::SUCCESS;
226
}
227
}
AlgorithmMemoryWrapper.h
Assert.h
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:219
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
MessageCheck.h
EL::AlgorithmMemoryWrapper::recordPostMemory
StatusCode recordPostMemory()
Definition
AlgorithmMemoryWrapper.cxx:206
EL::AlgorithmMemoryWrapper::m_algorithm
std::unique_ptr< IAlgorithmWrapper > m_algorithm
the actual algorithm
Definition
AlgorithmMemoryWrapper.h:99
EL::AlgorithmMemoryWrapper::m_mem_resident
std::vector< Long_t > m_mem_resident
the Memory Consumption for different calls
Definition
AlgorithmMemoryWrapper.h:102
EL::AlgorithmMemoryWrapper::recordPreMemory
StatusCode recordPreMemory()
Definition
AlgorithmMemoryWrapper.cxx:189
EL::AlgorithmMemoryWrapper::m_mem_virtual
std::vector< Long_t > m_mem_virtual
Definition
AlgorithmMemoryWrapper.h:103
EL::AlgorithmMemoryWrapper::m_preMem_resident
Long_t m_preMem_resident
Definition
AlgorithmMemoryWrapper.h:105
EL::AlgorithmMemoryWrapper::m_preMem_virtual
Long_t m_preMem_virtual
Definition
AlgorithmMemoryWrapper.h:106
EL::Algorithm
Definition
Algorithm.h:22
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
std
STL namespace.
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition
DVL_algorithms.h:554
str
Definition
BTagTrackIpAccessor.cxx:11
EL::AlgorithmWorkerData
all the external components an algorithm needs before initialization (in EventLoop)
Definition
AlgorithmWorkerData.h:34
Generated on
for ATLAS Offline Software by
1.17.0