ATLAS Offline Software
Loading...
Searching...
No Matches
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
14
17#include <TSystem.h>
18#include <iomanip>
19#include <ios>
20#include <numeric>
21
22//
23// method implementations
24//
25
26namespace 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;
87
89 auto result = m_algorithm->initialize (workerData);
91 return result;
92 }
93
94
95
96 StatusCode AlgorithmMemoryWrapper ::
97 execute ()
98 {
99 using namespace msgEventLoop;
101
103 auto result = m_algorithm->execute ();
105 return result;
106 }
107
108
109
110 StatusCode AlgorithmMemoryWrapper ::
111 postExecute ()
112 {
113 using namespace msgEventLoop;
115
117 auto result = m_algorithm->postExecute ();
119 return result;
120 }
121
122
123
124 StatusCode AlgorithmMemoryWrapper ::
125 finalize ()
126 {
127 using namespace msgEventLoop;
129
131 auto result = m_algorithm->finalize ();
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;
151
153 auto result = m_algorithm->fileExecute ();
155 return result;
156 }
157
158
159
160 StatusCode AlgorithmMemoryWrapper ::
161 beginInputFile ()
162 {
163 using namespace msgEventLoop;
165
167 auto result = m_algorithm->beginInputFile ();
169 return result;
170 }
171
172
173
174 StatusCode AlgorithmMemoryWrapper ::
175 endInputFile ()
176 {
177 using namespace msgEventLoop;
179
181 auto result = m_algorithm->endInputFile ();
183 return result;
184 }
185
186
187
188 StatusCode AlgorithmMemoryWrapper ::
189 recordPreMemory()
190 {
191 using namespace msgEventLoop;
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;
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}
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
std::unique_ptr< IAlgorithmWrapper > m_algorithm
the actual algorithm
std::vector< Long_t > m_mem_resident
the Memory Consumption for different calls
std::vector< Long_t > m_mem_virtual
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
STL namespace.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
all the external components an algorithm needs before initialization (in EventLoop)