ATLAS Offline Software
Loading...
Searching...
No Matches
MemoryLogger.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6// MemoryLogger.cxx, (c) ATLAS Detector software
8
10#include <fstream>
11#include <sstream>
12
14 : m_vsize{ -1 }
15 , m_rss{ -1 }
16{}
17
18void
20{
21
22#ifndef __APPLE__
23 // memory monitoring
24 std::ostringstream filename;
25 filename << "/proc/" << pid << "/status";
26
27 std::ifstream status(filename.str().c_str());
28 std::string buff;
29 float vsize;
30 float rss;
31 // loop over the files in the input
32 while (!status.eof()) {
33 status >> buff;
34 if (buff == "VmSize:")
35 status >> vsize;
36 if (buff == "VmRSS:")
37 status >> rss;
38 }
39 // close the file again
40 status.close();
41 m_vsize.store(vsize);
42 m_rss.store(vsize);
43#else
44#warning MemoryLogger does not yet work on the mac.
45#endif
46}
47
49MsgStream&
50Trk::operator<<(MsgStream& sl, const Trk::MemoryLogger& mlg)
51{
52 sl << "[ memory usage ] in kB ( VmSize | VmRSS ) : " << mlg.vmSize() << '\t' << mlg.vmRss();
53 return sl;
54}
55
56std::ostream&
57Trk::operator<<(std::ostream& sl, const Trk::MemoryLogger& mlg)
58{
59 sl << "[ memory usage ] in kB ( VmSize | VmRSS ) : " << mlg.vmSize() << '\t' << mlg.vmRss();
60 return sl;
61}
A small helper class looking at /proc/<PID>status.
std::atomic< float > m_rss
real memory size
float vmRss() const
float vmSize() const
vsize/rss returnal
MemoryLogger()
Default constructor.
std::atomic< float > m_vsize
virtual memory size
void refresh(int pid) const
update the memory logger
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output