ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ISF::MemoryMonitoringTool Class Reference

#include <MemoryMonitoringTool.h>

Inheritance diagram for ISF::MemoryMonitoringTool:
Collaboration diagram for ISF::MemoryMonitoringTool:

Public Member Functions

 MemoryMonitoringTool (const std::string &t, const std::string &n, const IInterface *p)
 Constructor with parameters. More...
 
 ~MemoryMonitoringTool ()
 Destructor. More...
 
StatusCode initialize ()
 Athena algtool Hooks. More...
 
StatusCode finalize ()
 Athena algtool Hook. More...
 
virtual double getCurrent () const
 return current memory usage in kBytes More...
 
virtual void dumpCurrent (const char *infoStr, bool considerInSummary)
 dump current memory monitoring information More...
 
virtual void recordCurrent (const char *infoStr)
 store the current memory monitoring information internally More...
 
virtual void dumpSummary (const char *dumpCallDescr) const
 dump all internally stored memory monitoring information More...
 

Private Member Functions

int computeCurMemoryUsage () const
 consolidate /proc to determine current memory usage More...
 

Private Attributes

unsigned int m_numCalls
 needed to compute per event stats More...
 
unsigned int m_prevCallMemUsage
 
double m_accumulatedCallMemory
 
double m_accumulatedIncrMemory
 
InfoUsagePairVector m_table
 storing all (infoStr,memUsage) pairs created in recordCurrent(..) calls More...
 

Detailed Description

the code actually computing the memory usage is kindly stolen from: atlasoff:: Simulation/G4Sim/SimHelpers/SimHelpers/MemorySnooper.h

Author
Elmar.Ritsch -at- cern.ch

Definition at line 37 of file MemoryMonitoringTool.h.

Constructor & Destructor Documentation

◆ MemoryMonitoringTool()

ISF::MemoryMonitoringTool::MemoryMonitoringTool ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Constructor with parameters.

Constructor.

Definition at line 16 of file MemoryMonitoringTool.cxx.

18  :
19  base_class(t,n,p),
20  m_numCalls(0),
24  m_table()
25 {
26 }

◆ ~MemoryMonitoringTool()

ISF::MemoryMonitoringTool::~MemoryMonitoringTool ( )

Destructor.

Definition at line 29 of file MemoryMonitoringTool.cxx.

29  {
30  // clean up memory
31  for (auto & p : m_table){
32  delete p;
33  }
34  // reset summary table vector
35  m_table.clear();
36 
37 }

Member Function Documentation

◆ computeCurMemoryUsage()

int ISF::MemoryMonitoringTool::computeCurMemoryUsage ( ) const
private

consolidate /proc to determine current memory usage

Definition at line 138 of file MemoryMonitoringTool.cxx.

138  {
139  // this code is copied from:
140  // atlasoff: Simulation/G4Sim/SimHelpers/SimHelpers/MemorySnooper.h
141 
142  int pid=getpid();
143  std::ostringstream is;
144  is<<pid;
145  std::string spid=is.str();
146  std::string filename="mem"+spid+".txt";
147  std::string temp="cat /proc/"+spid+"/status | grep VmSize >"+filename;
148  system(temp.c_str());
149  std::ifstream in(filename.c_str());
150  std::string text,mem,text1;
151  in>>text>>mem>>text1;
152  temp="rm -f "+filename;
153  system(temp.c_str());
154  float memsize=atof(mem.c_str());
155 
156  // finally return the memory size
157  return int(memsize);
158 }

◆ dumpCurrent()

void ISF::MemoryMonitoringTool::dumpCurrent ( const char *  infoStr,
bool  considerInSummary 
)
virtual

dump current memory monitoring information

Definition at line 66 of file MemoryMonitoringTool.cxx.

67  {
68 
69  // get current memory usage
70  int curMem = computeCurMemoryUsage();
71 
72  // store for different stats
73  int curDiff = curMem-m_prevCallMemUsage;
74 
75  // use these stats for the summary table
76  if (considerInSummary) {
77  m_accumulatedCallMemory += curMem;
78  m_accumulatedIncrMemory += curDiff;
79  ++m_numCalls;
80  }
81 
82  ATH_MSG_INFO( "Current Process Memory Usage " << infoStr
83  << " (VmMem,diff-previous) kBytes: "
84  << curMem<<" "<< curDiff );
85 
86  m_prevCallMemUsage = curMem;
87 
88  return;
89 }

◆ dumpSummary()

void ISF::MemoryMonitoringTool::dumpSummary ( const char *  dumpCallDescr) const
virtual

dump all internally stored memory monitoring information

Definition at line 108 of file MemoryMonitoringTool.cxx.

108  {
109 
110  ATH_MSG_INFO("*****************************************************\n"<<
111  "* (VmMem) MEMORY SUMMARY: (kBytes)");
112 
113  // loop over all (infoStr,memUsage) pairs and print them
114  InfoUsagePairVector::const_iterator it = m_table.begin();
115  InfoUsagePairVector::const_iterator itEnd = m_table.end();
116  for ( ; it != itEnd; ++it) {
117  const char *curInfo = (*it)->first;
118  int curUsage = (*it)->second;
119 
120  ATH_MSG_INFO("* Memory Usage " << curInfo << "\t\t: " << curUsage);
121  }
122 
123  if (m_numCalls) {
124  //cppcheck-suppress uselessAssignmentPtrArg
125  if (!desc) desc = "MemoryMonitor call";
126  ATH_MSG_INFO( "* Average memory per " << desc << " : "
128  ATH_MSG_INFO( "* Average memory increase per " << desc << " : "
130  }
131 
132  ATH_MSG_INFO("*****************************************************");
133 
134  return;
135 }

◆ finalize()

StatusCode ISF::MemoryMonitoringTool::finalize ( )

Athena algtool Hook.

Definition at line 51 of file MemoryMonitoringTool.cxx.

52 {
53  ATH_MSG_VERBOSE("finalize() ...");
54  ATH_MSG_VERBOSE("finalize() successful");
55  return StatusCode::SUCCESS;
56 }

◆ getCurrent()

double ISF::MemoryMonitoringTool::getCurrent ( ) const
virtual

return current memory usage in kBytes

Definition at line 60 of file MemoryMonitoringTool.cxx.

60  {
61  return double( computeCurMemoryUsage());
62 }

◆ initialize()

StatusCode ISF::MemoryMonitoringTool::initialize ( )

Athena algtool Hooks.

Definition at line 41 of file MemoryMonitoringTool.cxx.

42 {
43  ATH_MSG_VERBOSE("initialize() ...");
44 
45  ATH_MSG_VERBOSE("initialize() successful");
46  return StatusCode::SUCCESS;
47 }

◆ recordCurrent()

void ISF::MemoryMonitoringTool::recordCurrent ( const char *  infoStr)
virtual

store the current memory monitoring information internally

Definition at line 93 of file MemoryMonitoringTool.cxx.

93  {
94 
95  int curUsage = computeCurMemoryUsage();
96  ATH_MSG_VERBOSE("recording current memory footprint of "
97  << curUsage << " kBytes");
98 
99  // create new InfoUsagePair and store it locally in vector
100  InfoUsagePair *curInfoUsage = new InfoUsagePair(infoStr, curUsage);
101  m_table.push_back( curInfoUsage);
102 
103  return;
104 }

Member Data Documentation

◆ m_accumulatedCallMemory

double ISF::MemoryMonitoringTool::m_accumulatedCallMemory
private

Definition at line 70 of file MemoryMonitoringTool.h.

◆ m_accumulatedIncrMemory

double ISF::MemoryMonitoringTool::m_accumulatedIncrMemory
private

Definition at line 71 of file MemoryMonitoringTool.h.

◆ m_numCalls

unsigned int ISF::MemoryMonitoringTool::m_numCalls
private

needed to compute per event stats

Definition at line 68 of file MemoryMonitoringTool.h.

◆ m_prevCallMemUsage

unsigned int ISF::MemoryMonitoringTool::m_prevCallMemUsage
private

Definition at line 69 of file MemoryMonitoringTool.h.

◆ m_table

InfoUsagePairVector ISF::MemoryMonitoringTool::m_table
private

storing all (infoStr,memUsage) pairs created in recordCurrent(..) calls

Definition at line 74 of file MemoryMonitoringTool.h.


The documentation for this class was generated from the following files:
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ISF::MemoryMonitoringTool::computeCurMemoryUsage
int computeCurMemoryUsage() const
consolidate /proc to determine current memory usage
Definition: MemoryMonitoringTool.cxx:138
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
skel.it
it
Definition: skel.GENtoEVGEN.py:396
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ISF::InfoUsagePair
std::pair< const char *, int > InfoUsagePair
these datatypes used to store (infoStr,memUsage) paired info
Definition: MemoryMonitoringTool.h:26
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
beamspotman.n
n
Definition: beamspotman.py:731
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
ISF::MemoryMonitoringTool::m_accumulatedIncrMemory
double m_accumulatedIncrMemory
Definition: MemoryMonitoringTool.h:71
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
ISF::MemoryMonitoringTool::m_accumulatedCallMemory
double m_accumulatedCallMemory
Definition: MemoryMonitoringTool.h:70
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
ISF::MemoryMonitoringTool::m_numCalls
unsigned int m_numCalls
needed to compute per event stats
Definition: MemoryMonitoringTool.h:68
ISF::MemoryMonitoringTool::m_table
InfoUsagePairVector m_table
storing all (infoStr,memUsage) pairs created in recordCurrent(..) calls
Definition: MemoryMonitoringTool.h:74
ISF::MemoryMonitoringTool::m_prevCallMemUsage
unsigned int m_prevCallMemUsage
Definition: MemoryMonitoringTool.h:69