OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
MemoryProfiler.h
Go to the documentation of this file.
1 #ifndef OPAL_MEMORY_PROFILER_H
2 #define OPAL_MEMORY_PROFILER_H
3 
4 #include <fstream>
5 #include <string>
6 #include <map>
7 #include <vector>
8 
9 #include "SDDSWriter.h"
10 
11 class MemoryProfiler : public SDDSWriter {
12  /* Pay attention with units. /proc/[pid]/status returns values in
13  * KiB (Kibibyte) although the units say kB.
14  * KiB has base 2 not base 10
15  */
16 
17 public:
18  typedef std::vector<long double> vm_t;
19  typedef std::vector<std::string> units_t;
20 
21  MemoryProfiler(const std::string& fname, bool restart);
22 
24  VMPEAK = 0, // VmPeak: Peak virtual memory size.
25  VMSIZE, // VmSize: Virtual memory size.
26  VMHWM, // VmHWM: Peak resident set size ("high water mark").
27  VMRSS, // VmRSS: Resident set size.
28  VMDATA, // VmData: Size of data.
29  VMSTK, // VmStk: Size of stack.
30  VMEXE, // VmExe: Size of text segments.
31  VMLCK, // VmLck: Locked memory size (see mlock(3)).
32  VMPIN, // VmPin: Pinned memory size (since Linux 3.2). These are pages that can't be moved because something
33  // needs to directly access physical memory.
34  VMLIB, // VmLib: Shared library code size.
35  VMPTE, // VmPTE: Page table entries size (since Linux 2.6.10).
36  VMPMD, // VmPMD: Size of second-level page tables (since Linux 4.0).
37  VMSWAP // VmSwap: Swapped-out virtual memory size by anonymous private pages; shmem swap usage is not
38  // included (since Linux 2.6.34).
39  };
40 
41  void write(PartBunchBase<double, 3> *beam) override;
42 
43 private:
44  void header();
45  void update();
46  void compute(vm_t& vmMin, vm_t& vmMax, vm_t& vmAvg);
47 
48 private:
49  std::string fname_m;
50  std::map<std::string, int> procinfo_m;
53 };
54 
55 #endif
std::string fname_m
std::vector< std::string > units_t
MemoryProfiler(const std::string &fname, bool restart)
void compute(vm_t &vmMin, vm_t &vmMax, vm_t &vmAvg)
void write(PartBunchBase< double, 3 > *beam) override
std::map< std::string, int > procinfo_m
std::vector< long double > vm_t