ATLAS Offline Software
LeakCheckModule.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 
9 
10 //
11 // includes
12 //
13 
15 
16 #include <EventLoop/Job.h>
17 #include <EventLoop/ModuleData.h>
19 #include <TSystem.h>
20 #include <TTree.h>
21 #include <exception>
22 
23 //
24 // method implementations
25 //
26 
27 namespace EL
28 {
29  namespace Detail
30  {
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  }
47 
48 
49 
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  }
79 
80 
81 
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  }
137 
138 
139 
141  memIncreaseResident () const
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  }
150 
151 
152 
154  memIncreaseVirtual () const
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  }
163  }
164 }
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::onWorkerEnd
virtual StatusCode onWorkerEnd(ModuleData &data) override
action at the end of the worker job
Definition: LeakCheckModule.cxx:83
EL::Detail::ModuleData
the data the EventLoop core classes are sharing with the Module implementation
Definition: ModuleData.h:64
Job.h
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
MetaObject.h
EL::Detail::LeakCheckModule::m_finMemVirtual
Long_t m_finMemVirtual
Amount of virtual memory used after finalisation in kB.
Definition: LeakCheckModule.h:62
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL::Detail::LeakCheckModule::postFinalize
virtual StatusCode postFinalize(ModuleData &data) override
actions after algorithms have been finalized
Definition: LeakCheckModule.cxx:51
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
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
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
xAOD::DiTauJetParameters::Detail
Detail
Definition: DiTauDefs.h:38
EL::Detail::LeakCheckModule::m_finMemResident
Long_t m_finMemResident
Amount of resident memory used after finalisation in kB.
Definition: LeakCheckModule.h:58
LeakCheckModule.h
EL::Detail::LeakCheckModule::postFirstEvent
virtual StatusCode postFirstEvent(ModuleData &data) override
action after processing first event
Definition: LeakCheckModule.cxx:32
ModuleData.h
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