ATLAS Offline Software
Loading...
Searching...
No Matches
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>
19#include <TSystem.h>
20#include <TTree.h>
21#include <exception>
22
23//
24// method implementations
25//
26
27namespace EL
28{
29 namespace Detail
30 {
31 StatusCode LeakCheckModule ::
32 postFirstEvent (ModuleData& data)
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
50 StatusCode LeakCheckModule ::
51 postFinalize (ModuleData& data)
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
82 StatusCode LeakCheckModule ::
83 onWorkerEnd (ModuleData& data)
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 }
123
124
125
126 Long_t LeakCheckModule ::
127 memIncreaseResident () const
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 }
136
137
138
139 Long_t LeakCheckModule ::
140 memIncreaseVirtual () const
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 }
149 }
150}
#define RCU_ASSERT(x)
Definition Assert.h:222
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Long_t m_initMemVirtual
Amount of virtual memory used after initialisation in kB.
Gaudi::Property< int > absResidentLimit
Long_t m_finMemResident
Amount of resident memory used after finalisation in kB.
Long_t memIncreaseVirtual() const
Virtual memory leak/increase during the job.
Gaudi::Property< int > perEvResidentLimit
uint64_t m_skippedEvents
number of skipped events
Gaudi::Property< int > absVirtualLimit
Long_t memIncreaseResident() const
Resident memory leak/increase during the job.
Gaudi::Property< int > perEvVirtualLimit
Long_t m_finMemVirtual
Amount of virtual memory used after finalisation in kB.
Gaudi::Property< bool > failOnLeak
Long_t m_initMemResident
Amount of resident memory used after initialisation in kB.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
the data the EventLoop core classes are sharing with the Module implementation
Definition ModuleData.h:64