ATLAS Offline Software
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 
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 {
29  testInvariant () const
30  {
31  }
32 
33 
34 
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 
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 
75  {
76  RCU_READ_INVARIANT (this);
77  return m_algorithm->getLegacyAlg();
78  }
79 
80 
81 
83  initialize (const AlgorithmWorkerData& workerData)
84  {
85  using namespace msgEventLoop;
86  RCU_CHANGE_INVARIANT (this);
87 
89  auto result = m_algorithm->initialize (workerData);
91  return result;
92  }
93 
94 
95 
97  execute ()
98  {
99  using namespace msgEventLoop;
100  RCU_CHANGE_INVARIANT (this);
101 
103  auto result = m_algorithm->execute ();
105  return result;
106  }
107 
108 
109 
111  postExecute ()
112  {
113  using namespace msgEventLoop;
114  RCU_CHANGE_INVARIANT (this);
115 
117  auto result = m_algorithm->postExecute ();
119  return result;
120  }
121 
122 
123 
125  finalize ()
126  {
127  using namespace msgEventLoop;
128  RCU_CHANGE_INVARIANT (this);
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 
147  fileExecute ()
148  {
149  using namespace msgEventLoop;
150  RCU_CHANGE_INVARIANT (this);
151 
153  auto result = m_algorithm->fileExecute ();
155  return result;
156  }
157 
158 
159 
162  {
163  using namespace msgEventLoop;
164  RCU_CHANGE_INVARIANT (this);
165 
167  auto result = m_algorithm->beginInputFile ();
169  return result;
170  }
171 
172 
173 
175  endInputFile ()
176  {
177  using namespace msgEventLoop;
178  RCU_CHANGE_INVARIANT (this);
179 
181  auto result = m_algorithm->endInputFile ();
183  return result;
184  }
185 
186 
187 
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 
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 }
EL::AlgorithmMemoryWrapper::execute
virtual StatusCode execute() override
call execute on the algorithm
Definition: AlgorithmMemoryWrapper.cxx:97
AlgorithmMemoryWrapper.h
get_generator_info.result
result
Definition: get_generator_info.py:21
EL::AlgorithmMemoryWrapper::m_preMem_resident
Long_t m_preMem_resident
Definition: AlgorithmMemoryWrapper.h:105
EL::AlgorithmMemoryWrapper::getLegacyAlg
virtual Algorithm * getLegacyAlg() override
get the legacy algorithm, if we wrap one
Definition: AlgorithmMemoryWrapper.cxx:74
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
EL::AlgorithmMemoryWrapper::m_mem_resident
std::vector< Long_t > m_mem_resident
the Memory Consumption for different calls
Definition: AlgorithmMemoryWrapper.h:102
Assert.h
MessageCheck.h
EL::AlgorithmMemoryWrapper::hasName
virtual bool hasName(const std::string &name) const override
whether this algorithm has the given name
Definition: AlgorithmMemoryWrapper.cxx:54
EL::AlgorithmMemoryWrapper::recordPreMemory
StatusCode recordPreMemory()
Definition: AlgorithmMemoryWrapper.cxx:189
EL::AlgorithmMemoryWrapper::postExecute
virtual StatusCode postExecute() override
call postExecute on the algorithm
Definition: AlgorithmMemoryWrapper.cxx:111
EL::AlgorithmMemoryWrapper::m_mem_virtual
std::vector< Long_t > m_mem_virtual
Definition: AlgorithmMemoryWrapper.h:103
EL::AlgorithmMemoryWrapper::m_preMem_virtual
Long_t m_preMem_virtual
Definition: AlgorithmMemoryWrapper.h:106
EL::Algorithm
Definition: Algorithm.h:22
EL::AlgorithmMemoryWrapper::getName
virtual std::string_view getName() const override
Definition: AlgorithmMemoryWrapper.cxx:45
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
EL::AlgorithmMemoryWrapper::beginInputFile
virtual StatusCode beginInputFile() override
call beginInputFile on the algorithm
Definition: AlgorithmMemoryWrapper.cxx:161
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::AlgorithmMemoryWrapper::fileExecute
virtual StatusCode fileExecute() override
call fileExecute on the algorithm
Definition: AlgorithmMemoryWrapper.cxx:147
EL::AlgorithmMemoryWrapper::makeClone
virtual std::unique_ptr< IAlgorithmWrapper > makeClone() const override
make a clone of this algorithm
Definition: AlgorithmMemoryWrapper.cxx:63
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
EL::AlgorithmMemoryWrapper::recordPostMemory
StatusCode recordPostMemory()
Definition: AlgorithmMemoryWrapper.cxx:206
EL::AlgorithmWorkerData
all the external components an algorithm needs before initialization (in EventLoop)
Definition: AlgorithmWorkerData.h:34
EL::AlgorithmMemoryWrapper::AlgorithmMemoryWrapper
AlgorithmMemoryWrapper()
standard default constructor for serialization
Definition: AlgorithmMemoryWrapper.h:57
EL::AlgorithmMemoryWrapper::initialize
virtual StatusCode initialize(const AlgorithmWorkerData &workerData) override
call initialize on the algorithm
Definition: AlgorithmMemoryWrapper.cxx:83
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
EL::AlgorithmMemoryWrapper::m_algorithm
std::unique_ptr< IAlgorithmWrapper > m_algorithm
the actual algorithm
Definition: AlgorithmMemoryWrapper.h:99
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
str
Definition: BTagTrackIpAccessor.cxx:11
EL::AlgorithmMemoryWrapper::testInvariant
void testInvariant() const
test the invariant of this object
Definition: AlgorithmMemoryWrapper.cxx:29
EL::AlgorithmMemoryWrapper::endInputFile
virtual StatusCode endInputFile() override
call endInputFile on the algorithm
Definition: AlgorithmMemoryWrapper.cxx:175
EL::AlgorithmMemoryWrapper::finalize
virtual StatusCode finalize() override
call finalize on the algorithm
Definition: AlgorithmMemoryWrapper.cxx:125
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233