ATLAS Offline Software
Loading...
Searching...
No Matches
EL::AlgorithmMemoryWrapper Class Referencefinal

an IAlgorithmWrapper that adds a memory monitor to an algorithm More...

#include <AlgorithmMemoryWrapper.h>

Inheritance diagram for EL::AlgorithmMemoryWrapper:
Collaboration diagram for EL::AlgorithmMemoryWrapper:

Public Types

using clock_type = std::chrono::high_resolution_clock
 the clock we use for our Memory

Public Member Functions

void testInvariant () const
 test the invariant of this object
 AlgorithmMemoryWrapper ()
 standard default constructor for serialization
 AlgorithmMemoryWrapper (std::unique_ptr< IAlgorithmWrapper > &&val_algorithm)
 standard constructor
virtual std::string_view getName () const override
virtual bool hasName (const std::string &name) const override
 whether this algorithm has the given name
virtual std::unique_ptr< IAlgorithmWrappermakeClone () const override
 make a clone of this algorithm
virtual AlgorithmgetLegacyAlg () override
 get the legacy algorithm, if we wrap one
virtual StatusCode initialize (const AlgorithmWorkerData &workerData) override
 call initialize on the algorithm
virtual StatusCode execute () override
 call execute on the algorithm
virtual StatusCode postExecute () override
 call postExecute on the algorithm
virtual StatusCode finalize () override
 call finalize on the algorithm
virtual StatusCode fileExecute () override
 call fileExecute on the algorithm
virtual StatusCode beginInputFile () override
 call beginInputFile on the algorithm
virtual StatusCode endInputFile () override
 call endInputFile on the algorithm

Private Member Functions

StatusCode recordPreMemory ()
StatusCode recordPostMemory ()

Private Attributes

std::unique_ptr< IAlgorithmWrapperm_algorithm
 the actual algorithm
std::vector< Long_t > m_mem_resident
 the Memory Consumption for different calls
std::vector< Long_t > m_mem_virtual
Long_t m_preMem_resident = 0
Long_t m_preMem_virtual = 0

Detailed Description

an IAlgorithmWrapper that adds a memory monitor to an algorithm

This is a little weird in how its done: We can't just count the total memory allocated as all algorithms allocate memory which gets released at the end of the event. We also can't just count what gets allocated in initialize (which would seem natural), as some tools and algorithms do not allocate all their memory until we hit execute. And it may not even be the first execute either, it depends on what's in the event. So I'm summing up the memory increase from the top ten calls to functions on the algorithm. This is a bit of a hack, but the whole mechanism is meant to be quick and dirty. If you want a proper estimate, you should use valgrind.

Note
This module is specifically intended to debug the issue with analysis jobs running out of memory (Feb 24). Once that issue is resolved for good, or if there are fundamental issues that break this module it can be removed.
There is a dedicated test in AnalysisAlgorithms config that runs a test job with this module enabled to ensure it runs and doesn't break the output.

Definition at line 43 of file AlgorithmMemoryWrapper.h.

Member Typedef Documentation

◆ clock_type

using EL::AlgorithmMemoryWrapper::clock_type = std::chrono::high_resolution_clock

the clock we use for our Memory

Public Members

Definition at line 51 of file AlgorithmMemoryWrapper.h.

Constructor & Destructor Documentation

◆ AlgorithmMemoryWrapper() [1/2]

EL::AlgorithmMemoryWrapper::AlgorithmMemoryWrapper ( )
inline

standard default constructor for serialization

Definition at line 57 of file AlgorithmMemoryWrapper.h.

57{};

◆ AlgorithmMemoryWrapper() [2/2]

EL::AlgorithmMemoryWrapper::AlgorithmMemoryWrapper ( std::unique_ptr< IAlgorithmWrapper > && val_algorithm)

standard constructor

Definition at line 35 of file AlgorithmMemoryWrapper.cxx.

37 : m_algorithm (std::move (val_algorithm))
38 {
39 RCU_NEW_INVARIANT (this);
40 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
std::unique_ptr< IAlgorithmWrapper > m_algorithm
the actual algorithm

Member Function Documentation

◆ beginInputFile()

StatusCode EL::AlgorithmMemoryWrapper::beginInputFile ( )
overridevirtual

call beginInputFile on the algorithm

Implements EL::IAlgorithmWrapper.

Definition at line 160 of file AlgorithmMemoryWrapper.cxx.

162 {
163 using namespace msgEventLoop;
165
167 auto result = m_algorithm->beginInputFile ();
169 return result;
170 }
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define ANA_CHECK(EXP)
check whether the given expression was successful

◆ endInputFile()

StatusCode EL::AlgorithmMemoryWrapper::endInputFile ( )
overridevirtual

call endInputFile on the algorithm

Implements EL::IAlgorithmWrapper.

Definition at line 174 of file AlgorithmMemoryWrapper.cxx.

176 {
177 using namespace msgEventLoop;
179
181 auto result = m_algorithm->endInputFile ();
183 return result;
184 }

◆ execute()

StatusCode EL::AlgorithmMemoryWrapper::execute ( )
overridevirtual

call execute on the algorithm

Implements EL::IAlgorithmWrapper.

Definition at line 96 of file AlgorithmMemoryWrapper.cxx.

98 {
99 using namespace msgEventLoop;
101
103 auto result = m_algorithm->execute ();
105 return result;
106 }

◆ fileExecute()

StatusCode EL::AlgorithmMemoryWrapper::fileExecute ( )
overridevirtual

call fileExecute on the algorithm

Implements EL::IAlgorithmWrapper.

Definition at line 146 of file AlgorithmMemoryWrapper.cxx.

148 {
149 using namespace msgEventLoop;
151
153 auto result = m_algorithm->fileExecute ();
155 return result;
156 }

◆ finalize()

StatusCode EL::AlgorithmMemoryWrapper::finalize ( )
overridevirtual

call finalize on the algorithm

Implements EL::IAlgorithmWrapper.

Definition at line 124 of file AlgorithmMemoryWrapper.cxx.

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 }
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
std::vector< Long_t > m_mem_resident
the Memory Consumption for different calls
std::vector< Long_t > m_mem_virtual

◆ getLegacyAlg()

Algorithm * EL::AlgorithmMemoryWrapper::getLegacyAlg ( )
overridevirtual

get the legacy algorithm, if we wrap one

Reimplemented from EL::IAlgorithmWrapper.

Definition at line 73 of file AlgorithmMemoryWrapper.cxx.

75 {
76 RCU_READ_INVARIANT (this);
77 return m_algorithm->getLegacyAlg();
78 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229

◆ getName()

std::string_view EL::AlgorithmMemoryWrapper::getName ( ) const
overridevirtual

Inherited Members

Implements EL::IAlgorithmWrapper.

Definition at line 44 of file AlgorithmMemoryWrapper.cxx.

46 {
47 RCU_READ_INVARIANT (this);
48 return m_algorithm->getName();
49 }

◆ hasName()

bool EL::AlgorithmMemoryWrapper::hasName ( const std::string & name) const
overridevirtual

whether this algorithm has the given name

Implements EL::IAlgorithmWrapper.

Definition at line 53 of file AlgorithmMemoryWrapper.cxx.

55 {
56 RCU_READ_INVARIANT (this);
57 return m_algorithm->hasName (name);
58 }

◆ initialize()

StatusCode EL::AlgorithmMemoryWrapper::initialize ( const AlgorithmWorkerData & workerData)
overridevirtual

call initialize on the algorithm

Implements EL::IAlgorithmWrapper.

Definition at line 82 of file AlgorithmMemoryWrapper.cxx.

84 {
85 using namespace msgEventLoop;
87
89 auto result = m_algorithm->initialize (workerData);
91 return result;
92 }

◆ makeClone()

std::unique_ptr< IAlgorithmWrapper > EL::AlgorithmMemoryWrapper::makeClone ( ) const
overridevirtual

make a clone of this algorithm

Implements EL::IAlgorithmWrapper.

Definition at line 62 of file AlgorithmMemoryWrapper.cxx.

64 {
65 using namespace msgEventLoop;
66 RCU_READ_INVARIANT (this);
67
68 return std::make_unique<AlgorithmMemoryWrapper> (m_algorithm->makeClone());
69 }

◆ postExecute()

StatusCode EL::AlgorithmMemoryWrapper::postExecute ( )
overridevirtual

call postExecute on the algorithm

Reimplemented from EL::IAlgorithmWrapper.

Definition at line 110 of file AlgorithmMemoryWrapper.cxx.

112 {
113 using namespace msgEventLoop;
115
117 auto result = m_algorithm->postExecute ();
119 return result;
120 }

◆ recordPostMemory()

StatusCode EL::AlgorithmMemoryWrapper::recordPostMemory ( )
private

Definition at line 205 of file AlgorithmMemoryWrapper.cxx.

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 }
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ recordPreMemory()

StatusCode EL::AlgorithmMemoryWrapper::recordPreMemory ( )
private

Definition at line 188 of file AlgorithmMemoryWrapper.cxx.

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 }

◆ testInvariant()

void EL::AlgorithmMemoryWrapper::testInvariant ( ) const

test the invariant of this object

Definition at line 28 of file AlgorithmMemoryWrapper.cxx.

30 {
31 }

Member Data Documentation

◆ m_algorithm

std::unique_ptr<IAlgorithmWrapper> EL::AlgorithmMemoryWrapper::m_algorithm
private

the actual algorithm

Private Members

Definition at line 99 of file AlgorithmMemoryWrapper.h.

◆ m_mem_resident

std::vector<Long_t> EL::AlgorithmMemoryWrapper::m_mem_resident
private

the Memory Consumption for different calls

Definition at line 102 of file AlgorithmMemoryWrapper.h.

◆ m_mem_virtual

std::vector<Long_t> EL::AlgorithmMemoryWrapper::m_mem_virtual
private

Definition at line 103 of file AlgorithmMemoryWrapper.h.

◆ m_preMem_resident

Long_t EL::AlgorithmMemoryWrapper::m_preMem_resident = 0
private

Definition at line 105 of file AlgorithmMemoryWrapper.h.

◆ m_preMem_virtual

Long_t EL::AlgorithmMemoryWrapper::m_preMem_virtual = 0
private

Definition at line 106 of file AlgorithmMemoryWrapper.h.


The documentation for this class was generated from the following files: