ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
EL::Detail::LeakCheckModule Class Referencefinal

a Module implementing a simple leak checker More...

#include <LeakCheckModule.h>

Inheritance diagram for EL::Detail::LeakCheckModule:
Collaboration diagram for EL::Detail::LeakCheckModule:

Public Member Functions

virtual StatusCode postFirstEvent (ModuleData &data) override
 action after processing first event More...
 
virtual StatusCode onWorkerEnd (ModuleData &data) override
 action at the end of the worker job More...
 
virtual StatusCode postFinalize (ModuleData &data) override
 actions after algorithms have been finalized More...
 
virtual StatusCode firstInitialize (ModuleData &data)
 action at the the very beginning of the worker job More...
 
virtual StatusCode preFileInitialize (ModuleData &data)
 action before opening the first file in the worker job More...
 
virtual StatusCode onInitialize (ModuleData &data)
 action just before algorithms are initialized More...
 
virtual StatusCode processInputs (ModuleData &data, IInputModuleActions &actions)
 process all input files More...
 
virtual StatusCode onNewInputFile (ModuleData &data)
 actions after opening a new input file More...
 
virtual StatusCode onCloseInputFile (ModuleData &data)
 actions before closing an input file More...
 
virtual StatusCode postCloseInputFile (ModuleData &data)
 actions after CloseInputFile is called on the algorithms More...
 
virtual StatusCode onFileExecute (ModuleData &data)
 actions just before fileExecute is called on algorithms More...
 
virtual StatusCode onExecute (ModuleData &data)
 actions just before execute is called on algorithms More...
 
virtual StatusCode onFinalize (ModuleData &data)
 actions just before algorithms are finalized More...
 
virtual StatusCode postFileClose (ModuleData &data)
 action at end of the worker job More...
 
virtual void reportInputFailure (ModuleData &data)
 report that we failed to open our input file More...
 

Public Attributes

Gaudi::Property< int > absResidentLimit {this, "absResidentLimit", 10000}
 
Gaudi::Property< int > absVirtualLimit {this, "absVirtualLimit", 0}
 
Gaudi::Property< int > perEvResidentLimit {this, "perEvResidentLimit", 10}
 
Gaudi::Property< int > perEvVirtualLimit {this, "perEvVirtualLimit", 0}
 
Gaudi::Property< bool > failOnLeak {this, "failOnLeak", false}
 

Private Member Functions

Long_t memIncreaseResident () const
 Resident memory leak/increase during the job. More...
 
Long_t memIncreaseVirtual () const
 Virtual memory leak/increase during the job. More...
 

Private Attributes

uint64_t m_skippedEvents = 0
 number of skipped events More...
 
Long_t m_initMemResident = -1
 Amount of resident memory used after initialisation in kB. More...
 
Long_t m_initMemVirtual = -1
 Amount of virtual memory used after initialisation in kB. More...
 
Long_t m_finMemResident = -1
 Amount of resident memory used after finalisation in kB. More...
 
Long_t m_finMemVirtual = -1
 Amount of virtual memory used after finalisation in kB. More...
 

Detailed Description

a Module implementing a simple leak checker

Definition at line 25 of file LeakCheckModule.h.

Member Function Documentation

◆ firstInitialize()

StatusCode EL::Detail::Module::firstInitialize ( ModuleData data)
virtualinherited

action at the the very beginning of the worker job

This gets called as early as possible in the worker initialization. Essentially all that should happen before this is to load all the modules. The main purpose is to start any benchmarks that are meant to capture the initialization process as well.

Reimplemented in EL::Detail::MemoryMonitorModule, EL::Detail::AlgorithmMemoryModule, EL::Detail::AlgorithmTimerModule, and EL::Detail::StopwatchModule.

Definition at line 25 of file Module.cxx.

27  {
28  return ::StatusCode::SUCCESS;
29  }

◆ memIncreaseResident()

Long_t EL::Detail::LeakCheckModule::memIncreaseResident ( ) const
private

Resident memory leak/increase during the job.

The idea here is that the worker captures the amount of memory used by the job during initialisation and finalisation, so that a rough estimate could be made about the memory leak behaviour of the user's code.

This function returns the number of kilobytes by which the used resident memory changed between initialisation and finalisation. If the function is called at an incorrect point in time, it throws an exception.

Definition at line 126 of file LeakCheckModule.cxx.

128  {
129  // Check that the user called the function at the correct time.
130  if ((m_initMemResident == -1) || (m_finMemResident == -1)) {
131  throw std::logic_error ("Function called at incorrect time");
132  }
133  // Return the resident memory increase.
135  }

◆ memIncreaseVirtual()

Long_t EL::Detail::LeakCheckModule::memIncreaseVirtual ( ) const
private

Virtual memory leak/increase during the job.

The idea here is that the worker captures the amount of memory used by the job during initialisation and finalisation, so that a rough estimate could be made about the memory leak behaviour of the user's code.

This function returns the number of kilobytes by which the used virtual memory changed between initialisation and finalisation. If the function is called at an incorrect point in time, it throws an exception.

Definition at line 139 of file LeakCheckModule.cxx.

141  {
142  // Check that the user called the function at the correct time.
143  if ((m_initMemVirtual == -1) || (m_finMemVirtual == -1)) {
144  throw std::logic_error ("Function called at incorrect time");
145  }
146  // Return the resident memory increase.
148  }

◆ onCloseInputFile()

StatusCode EL::Detail::Module::onCloseInputFile ( ModuleData data)
virtualinherited

actions before closing an input file

Reimplemented in EL::Detail::AlgorithmStateModule, and EL::Detail::TreeCacheModule.

Definition at line 43 of file Module.cxx.

45  {
46  return ::StatusCode::SUCCESS;
47  }

◆ onExecute()

StatusCode EL::Detail::Module::onExecute ( ModuleData data)
virtualinherited

actions just before execute is called on algorithms

For now that is mostly used to point input modules to the right event

Reimplemented in EL::Detail::TEventModule, EL::Detail::AlgorithmStateModule, EL::Detail::MemoryMonitorModule, and EL::Detail::GridReportingModule.

Definition at line 71 of file Module.cxx.

73  {
74  return ::StatusCode::SUCCESS;
75  }

◆ onFileExecute()

StatusCode EL::Detail::Module::onFileExecute ( ModuleData data)
virtualinherited

actions just before fileExecute is called on algorithms

Reimplemented in EL::Detail::AlgorithmStateModule, EL::Detail::FileExecutedModule, and EL::Detail::StopwatchModule.

Definition at line 65 of file Module.cxx.

67  {
68  return ::StatusCode::SUCCESS;
69  }

◆ onFinalize()

StatusCode EL::Detail::Module::onFinalize ( ModuleData data)
virtualinherited

actions just before algorithms are finalized

Reimplemented in EL::Detail::AlgorithmStateModule, and EL::Detail::MemoryMonitorModule.

Definition at line 89 of file Module.cxx.

91  {
92  return ::StatusCode::SUCCESS;
93  }

◆ onInitialize()

StatusCode EL::Detail::Module::onInitialize ( ModuleData data)
virtualinherited

action just before algorithms are initialized

This is typically used for any setup that this module needs to do.

Reimplemented in EL::Detail::TEventModule, EL::Detail::AlgorithmStateModule, EL::Detail::MemoryMonitorModule, EL::Detail::FileExecutedModule, EL::Detail::FactoryPreloadModule, and EL::Detail::WorkerConfigModule.

Definition at line 77 of file Module.cxx.

79  {
80  return ::StatusCode::SUCCESS;
81  }

◆ onNewInputFile()

StatusCode EL::Detail::Module::onNewInputFile ( ModuleData data)
virtualinherited

actions after opening a new input file

Reimplemented in EL::Detail::TEventModule, EL::Detail::AlgorithmStateModule, EL::Detail::GridReportingModule, and EL::Detail::TreeCacheModule.

Definition at line 37 of file Module.cxx.

39  {
40  return ::StatusCode::SUCCESS;
41  }

◆ onWorkerEnd()

StatusCode EL::Detail::LeakCheckModule::onWorkerEnd ( ModuleData data)
overridevirtual

action at the end of the worker job

This is mostly meant/used to print job summary statements at the very end of worker job, and actually have them show up at or at least near the end of any log file.

Reimplemented from EL::Detail::Module.

Definition at line 82 of file LeakCheckModule.cxx.

84  {
85  // Perform a memory leak check in case at least one event was processed.
86  if (m_skippedEvents > 0 &&
87  data.m_eventsProcessed > m_skippedEvents) {
88 
89  // Calculate and print the memory increase of the job.
90  const Long_t resLeak = memIncreaseResident();
91  const Double_t resLeakPerEv =
92  (static_cast< Double_t > (resLeak) /
93  static_cast< Double_t > (data.m_eventsProcessed-m_skippedEvents));
94  const Long_t virtLeak = memIncreaseVirtual();
95  const Double_t virtLeakPerEv =
96  (static_cast< Double_t > (virtLeak) /
97  static_cast< Double_t > (data.m_eventsProcessed-m_skippedEvents) );
98  ANA_MSG_INFO ("Memory increase/change during the job:");
99  ANA_MSG_INFO (" - resident: " << resLeakPerEv << " kB/event ("
100  << resLeak << " kB total)");
101  ANA_MSG_INFO (" - virtual : " << virtLeakPerEv << " kB/event ("
102  << virtLeak << " kB total)");
103 
104  // Decide if this acceptable or not.
105  if ((resLeak > absResidentLimit.value()) &&
106  (resLeakPerEv > perEvResidentLimit.value()) &&
107  (virtLeak > absVirtualLimit.value()) &&
108  (virtLeakPerEv > perEvVirtualLimit.value())) {
109 
110  // If not, decide what to do about it.
111  if (failOnLeak.value()) {
112  ANA_MSG_ERROR ("A significant memory leak was detected");
113  return StatusCode::FAILURE;
114  } else {
115  ANA_MSG_WARNING ("*");
116  ANA_MSG_WARNING ("* A significant memory leak was detected");
117  ANA_MSG_WARNING ("*");
118  }
119  }
120  }
121  return StatusCode::SUCCESS;
122  }

◆ postCloseInputFile()

StatusCode EL::Detail::Module::postCloseInputFile ( ModuleData data)
virtualinherited

actions after CloseInputFile is called on the algorithms

Right now that is only used to disconnect the TEvent object from the input file.

Reimplemented in EL::Detail::TEventModule.

Definition at line 49 of file Module.cxx.

51  {
52  return ::StatusCode::SUCCESS;
53  }

◆ postFileClose()

StatusCode EL::Detail::Module::postFileClose ( ModuleData data)
virtualinherited

action at end of the worker job

Executed just right before worker exit successfully at this stage all outputs have been created

Reimplemented in EL::Detail::GridReportingModule, and EL::Detail::PostClosedOutputsModule.

Definition at line 107 of file Module.cxx.

109  {
110  return ::StatusCode::SUCCESS;
111  }

◆ postFinalize()

StatusCode EL::Detail::LeakCheckModule::postFinalize ( ModuleData data)
overridevirtual

actions after algorithms have been finalized

This is usually used to calculate some job summary information that is to be stored it in the histogram output file.

Reimplemented from EL::Detail::Module.

Definition at line 50 of file LeakCheckModule.cxx.

52  {
53  if (m_skippedEvents > 0) {
54  // Get the memory usage of the process after finalisation.
55  ::ProcInfo_t pinfo;
56  if (gSystem->GetProcInfo (&pinfo) != 0) {
57  ANA_MSG_ERROR ("Could not get memory usage information");
58  return StatusCode::FAILURE;
59  }
60  m_finMemResident = pinfo.fMemResident;
61  m_finMemVirtual = pinfo.fMemVirtual;
62  ANA_MSG_DEBUG ("finishing memory: " << pinfo.fMemResident << " " << pinfo.fMemVirtual);
63 
64  // Save the memory increase values into the job statistics tree.
65  RCU_ASSERT (data.m_jobStats != nullptr);
66  Float_t incRes = memIncreaseResident();
67  if (! data.m_jobStats->Branch ("memIncreaseResident", &incRes)) {
68  ANA_MSG_ERROR ("Failed to create branch memIncreaseResident");
69  return StatusCode::FAILURE;
70  }
71  Float_t incVirt = memIncreaseVirtual();
72  if (! data.m_jobStats->Branch ("memIncreaseVirtual", &incVirt)) {
73  ANA_MSG_ERROR ("Failed to create branch memIncreaseVirtual");
74  return StatusCode::FAILURE;
75  }
76  }
77  return StatusCode::SUCCESS;
78  }

◆ postFirstEvent()

StatusCode EL::Detail::LeakCheckModule::postFirstEvent ( ModuleData data)
overridevirtual

action after processing first event

This is mostly meant to set up benchmarks that record per-event performance. While a lot of initialization happens during initialize() there is a fair amount of initialization that happens on the first event, so when recording per-event performance the first event is sort of "special" and may need to be omitted.

Reimplemented from EL::Detail::Module.

Definition at line 31 of file LeakCheckModule.cxx.

33  {
34  m_skippedEvents = data.m_eventsProcessed + 1;
35 
36  // Get the memory usage of the process after initialisation.
37  ::ProcInfo_t pinfo;
38  if (gSystem->GetProcInfo (&pinfo) != 0) {
39  ANA_MSG_ERROR ("Could not get memory usage information");
40  return StatusCode::FAILURE;
41  }
42  m_initMemResident = pinfo.fMemResident;
43  m_initMemVirtual = pinfo.fMemVirtual;
44  ANA_MSG_DEBUG ("starting memory: " << pinfo.fMemResident << " " << pinfo.fMemVirtual);
45  return StatusCode::SUCCESS;
46  }

◆ preFileInitialize()

StatusCode EL::Detail::Module::preFileInitialize ( ModuleData data)
virtualinherited

action before opening the first file in the worker job

This is mostly meant to allow loading the dictionaries before any files and associated information is loaded.

Definition at line 31 of file Module.cxx.

33  {
34  return ::StatusCode::SUCCESS;
35  }

◆ processInputs()

StatusCode EL::Detail::Module::processInputs ( ModuleData data,
IInputModuleActions actions 
)
virtualinherited

process all input files

This deviates slightly from the usual pattern for module functions in that I pass in the possible actions as an argument. See IInputModuleActions for details.

Reimplemented in EL::Detail::BatchInputModule, and EL::Detail::DirectInputModule.

Definition at line 83 of file Module.cxx.

85  {
86  return ::StatusCode::SUCCESS;
87  }

◆ reportInputFailure()

void EL::Detail::Module::reportInputFailure ( ModuleData data)
virtualinherited

report that we failed to open our input file

Reimplemented in EL::Detail::GridReportingModule.

Definition at line 61 of file Module.cxx.

63  {}

Member Data Documentation

◆ absResidentLimit

Gaudi::Property<int> EL::Detail::LeakCheckModule::absResidentLimit {this, "absResidentLimit", 10000}

Definition at line 39 of file LeakCheckModule.h.

◆ absVirtualLimit

Gaudi::Property<int> EL::Detail::LeakCheckModule::absVirtualLimit {this, "absVirtualLimit", 0}

Definition at line 40 of file LeakCheckModule.h.

◆ failOnLeak

Gaudi::Property<bool> EL::Detail::LeakCheckModule::failOnLeak {this, "failOnLeak", false}

Definition at line 43 of file LeakCheckModule.h.

◆ m_finMemResident

Long_t EL::Detail::LeakCheckModule::m_finMemResident = -1
private

Amount of resident memory used after finalisation in kB.

Definition at line 63 of file LeakCheckModule.h.

◆ m_finMemVirtual

Long_t EL::Detail::LeakCheckModule::m_finMemVirtual = -1
private

Amount of virtual memory used after finalisation in kB.

Definition at line 67 of file LeakCheckModule.h.

◆ m_initMemResident

Long_t EL::Detail::LeakCheckModule::m_initMemResident = -1
private

Amount of resident memory used after initialisation in kB.

Definition at line 55 of file LeakCheckModule.h.

◆ m_initMemVirtual

Long_t EL::Detail::LeakCheckModule::m_initMemVirtual = -1
private

Amount of virtual memory used after initialisation in kB.

Definition at line 59 of file LeakCheckModule.h.

◆ m_skippedEvents

uint64_t EL::Detail::LeakCheckModule::m_skippedEvents = 0
private

number of skipped events

Definition at line 51 of file LeakCheckModule.h.

◆ perEvResidentLimit

Gaudi::Property<int> EL::Detail::LeakCheckModule::perEvResidentLimit {this, "perEvResidentLimit", 10}

Definition at line 41 of file LeakCheckModule.h.

◆ perEvVirtualLimit

Gaudi::Property<int> EL::Detail::LeakCheckModule::perEvVirtualLimit {this, "perEvVirtualLimit", 0}

Definition at line 42 of file LeakCheckModule.h.


The documentation for this class was generated from the following files:
EL::Detail::LeakCheckModule::m_initMemVirtual
Long_t m_initMemVirtual
Amount of virtual memory used after initialisation in kB.
Definition: LeakCheckModule.h:59
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
EL::Detail::LeakCheckModule::failOnLeak
Gaudi::Property< bool > failOnLeak
Definition: LeakCheckModule.h:43
EL::Detail::LeakCheckModule::memIncreaseVirtual
Long_t memIncreaseVirtual() const
Virtual memory leak/increase during the job.
Definition: LeakCheckModule.cxx:140
EL::Detail::LeakCheckModule::memIncreaseResident
Long_t memIncreaseResident() const
Resident memory leak/increase during the job.
Definition: LeakCheckModule.cxx:127
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
EL::Detail::LeakCheckModule::m_initMemResident
Long_t m_initMemResident
Amount of resident memory used after initialisation in kB.
Definition: LeakCheckModule.h:55
EL::Detail::LeakCheckModule::m_finMemVirtual
Long_t m_finMemVirtual
Amount of virtual memory used after finalisation in kB.
Definition: LeakCheckModule.h:67
EL::Detail::LeakCheckModule::perEvVirtualLimit
Gaudi::Property< int > perEvVirtualLimit
Definition: LeakCheckModule.h:42
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
EL::Detail::LeakCheckModule::m_skippedEvents
uint64_t m_skippedEvents
number of skipped events
Definition: LeakCheckModule.h:51
EL::Detail::LeakCheckModule::absVirtualLimit
Gaudi::Property< int > absVirtualLimit
Definition: LeakCheckModule.h:40
EL::Detail::LeakCheckModule::m_finMemResident
Long_t m_finMemResident
Amount of resident memory used after finalisation in kB.
Definition: LeakCheckModule.h:63
EL::Detail::LeakCheckModule::absResidentLimit
Gaudi::Property< int > absResidentLimit
Definition: LeakCheckModule.h:39
EL::Detail::LeakCheckModule::perEvResidentLimit
Gaudi::Property< int > perEvResidentLimit
Definition: LeakCheckModule.h:41
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288