ATLAS Offline Software
Public Member Functions | 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...
 

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 24 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 140 of file LeakCheckModule.cxx.

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

◆ 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 153 of file LeakCheckModule.cxx.

155  {
156  // Check that the user called the function at the correct time.
157  if ((m_initMemVirtual == -1) || (m_finMemVirtual == -1)) {
158  throw std::logic_error ("Function called at incorrect time");
159  }
160  // Return the resident memory increase.
162  }

◆ 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  // Extract the limits for producing an error.
90  const int absResidentLimit =
91  data.m_metaData->castInteger (Job::optMemResidentIncreaseLimit,
92  10000);
93  const int absVirtualLimit =
94  data.m_metaData->castInteger (Job::optMemVirtualIncreaseLimit,
95  0);
96  const int perEvResidentLimit =
97  data.m_metaData->castInteger (Job::optMemResidentPerEventIncreaseLimit,
98  10);
99  const int perEvVirtualLimit =
100  data.m_metaData->castInteger (Job::optMemVirtualPerEventIncreaseLimit,
101  0);
102 
103  // Calculate and print the memory increase of the job.
104  const Long_t resLeak = memIncreaseResident();
105  const Double_t resLeakPerEv =
106  (static_cast< Double_t > (resLeak) /
107  static_cast< Double_t > (data.m_eventsProcessed-m_skippedEvents));
108  const Long_t virtLeak = memIncreaseVirtual();
109  const Double_t virtLeakPerEv =
110  (static_cast< Double_t > (virtLeak) /
111  static_cast< Double_t > (data.m_eventsProcessed-m_skippedEvents) );
112  ANA_MSG_INFO ("Memory increase/change during the job:");
113  ANA_MSG_INFO (" - resident: " << resLeakPerEv << " kB/event ("
114  << resLeak << " kB total)");
115  ANA_MSG_INFO (" - virtual : " << virtLeakPerEv << " kB/event ("
116  << virtLeak << " kB total)");
117 
118  // Decide if this acceptable or not.
119  if ((resLeak > absResidentLimit) &&
120  (resLeakPerEv > perEvResidentLimit) &&
121  (virtLeak > absVirtualLimit) &&
122  (virtLeakPerEv > perEvVirtualLimit)) {
123 
124  // If not, decide what to do about it.
125  if (data.m_metaData->castBool (Job::optMemFailOnLeak, false)) {
126  ANA_MSG_ERROR ("A significant memory leak was detected");
127  return StatusCode::FAILURE;
128  } else {
129  ANA_MSG_WARNING ("*");
130  ANA_MSG_WARNING ("* A significant memory leak was detected");
131  ANA_MSG_WARNING ("*");
132  }
133  }
134  }
135  return StatusCode::SUCCESS;
136  }

◆ 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

◆ m_finMemResident

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

Amount of resident memory used after finalisation in kB.

Definition at line 58 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 62 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 50 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 54 of file LeakCheckModule.h.

◆ m_skippedEvents

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

number of skipped events

Definition at line 46 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:54
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
EL::Detail::LeakCheckModule::memIncreaseVirtual
Long_t memIncreaseVirtual() const
Virtual memory leak/increase during the job.
Definition: LeakCheckModule.cxx:154
EL::Job::optMemResidentPerEventIncreaseLimit
static const std::string optMemResidentPerEventIncreaseLimit
The minimal per-event resident memory increase for triggering an error.
Definition: Job.h:551
EL::Detail::LeakCheckModule::memIncreaseResident
Long_t memIncreaseResident() const
Resident memory leak/increase during the job.
Definition: LeakCheckModule.cxx:141
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:50
EL::Detail::LeakCheckModule::m_finMemVirtual
Long_t m_finMemVirtual
Amount of virtual memory used after finalisation in kB.
Definition: LeakCheckModule.h:62
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::Job::optMemFailOnLeak
static const std::string optMemFailOnLeak
Failure behaviour of the code when a "significant memory leak" is found.
Definition: Job.h:591
EL::Job::optMemResidentIncreaseLimit
static const std::string optMemResidentIncreaseLimit
The minimal resident memory increase necessary to trigger an error.
Definition: Job.h:569
EL::Detail::LeakCheckModule::m_skippedEvents
uint64_t m_skippedEvents
number of skipped events
Definition: LeakCheckModule.h:46
EL::Detail::LeakCheckModule::m_finMemResident
Long_t m_finMemResident
Amount of resident memory used after finalisation in kB.
Definition: LeakCheckModule.h:58
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
EL::Job::optMemVirtualPerEventIncreaseLimit
static const std::string optMemVirtualPerEventIncreaseLimit
The minimal per-event virtual memory increase for triggering an error.
Definition: Job.h:561
EL::Job::optMemVirtualIncreaseLimit
static const std::string optMemVirtualIncreaseLimit
The minimal virtual memory increase necessary to trigger an error.
Definition: Job.h:577
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288