| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ProcStats.h
Go to the documentation of this file.
1 #ifndef GAUDIAUD_PROCSTATS_H
2 #define GAUDIAUD_PROCSTATS_H
3
4 // Class: ProcStats
5 // Description: Keeps statistics on memory usage
6 // Author: Jim Kowalkowski (FNAL), modified by M. Shapiro (LBNL)
7
8 #include <string>
9 #include <vector>
10 #ifdef __linux
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <fcntl.h>
14 #endif
15
16 struct procInfo
17 {
18 procInfo() : vsize(0), rss(0) {}
19 procInfo(double sz, double rss_sz): vsize(sz),rss(rss_sz) {}
20
21 bool operator==(const procInfo& p) const {
22 #ifdef __ICC
23 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
24 #pragma warning(push)
25 #pragma warning(disable:1572)
26 #endif
27
28 return vsize==p.vsize && rss==p.rss;
29
30 #ifdef __ICC
31 // re-enable icc remark #1572
32 #pragma warning(pop)
33 #endif
34 }
35
36 // see proc(4) man pages for units and a description
37 double vsize; // in MB (used to be in pages?)
38 double rss; // in MB (used to be in pages?)
39 };
40
41 class ProcStats
42 {
43 public:
44 static ProcStats* instance();
45
46 bool fetch(procInfo& fill_me);
47 double pageSize() const { return pg_size; }
48
49 private:
50 ProcStats();
51
52 struct cleanup
53 {
54 cleanup() { }
55 ~cleanup();
56 };
57
58 friend struct cleanup;
59
60 class unique_fd {
61 int m_fd;
62 unique_fd(const unique_fd&) = delete;
63 unique_fd& operator=(const unique_fd&) = delete;
64 public:
65 unique_fd(int fd=-1) : m_fd(fd) {}
66 unique_fd(unique_fd&& other) { m_fd = other.m_fd; other.m_fd = -1; }
67 ~unique_fd() { if (m_fd != -1) ::close(m_fd); }
68
69 explicit operator bool() const { return m_fd != -1; }
70 template <typename... Args>
71 unique_fd& open(Args&& ... args) { m_fd = ::open(std::forward<Args>(args)...); return *this; }
72 #define unique_fd_forward(fun) template <typename...Args> auto fun(Args&&... args) const \
73 -> decltype(::fun(m_fd,std::forward<Args>(args)...)) \
74 { return ::fun(m_fd,std::forward<Args>(args)...); }
75 unique_fd_forward(lseek)
76 unique_fd_forward(read)
77 unique_fd_forward(write)
78 unique_fd_forward(fcntl)
79 unique_fd_forward(fsync)
80 unique_fd_forward(fchown)
81 unique_fd_forward(stat)
82 #undef unique_fd_forward
83 int close() { auto r = ::close(m_fd); m_fd = -1; return r; }
84 };
85
86
87 unique_fd fd;
88 double pg_size;
89 procInfo curr;
90 std::string fname;
91 char buf[500];
92 bool valid;
93
94 static ProcStats* inst;
95 };
96
97 #endif
98
ProcStats::inst
static ProcStats * inst
Definition: ProcStats.h:94
ProcStats::unique_fd::operator=
unique_fd & operator=(const unique_fd &)=delete
ProcStats::cleanup
Definition: ProcStats.h:52
ProcStats::unique_fd::~unique_fd
~unique_fd()
Definition: ProcStats.h:67
ProcStats::unique_fd
Definition: ProcStats.h:60
ProcStats::instance
static ProcStats * instance()
Definition: ProcStats.cpp:237
ProcStats::unique_fd::unique_fd
unique_fd(int fd=-1)
Definition: ProcStats.h:65
procInfo::operator==
bool operator==(const procInfo &p) const
Definition: ProcStats.h:21
ProcStats::unique_fd::open
unique_fd & open(Args &&...args)
Definition: ProcStats.h:71
ProcStats::pg_size
double pg_size
Definition: ProcStats.h:88
ProcStats::curr
procInfo curr
Definition: ProcStats.h:89
ProcStats::fname
std::string fname
Definition: ProcStats.h:90
std::string
STL class.
ProcStats::cleanup::cleanup
cleanup()
Definition: ProcStats.h:54
ProcStats::unique_fd::unique_fd
unique_fd(const unique_fd &)=delete
ProcStats::cleanup::~cleanup
~cleanup()
Definition: ProcStats.cpp:230
procInfo::rss
double rss
Definition: ProcStats.h:38
ProcStats::fd
unique_fd fd
Definition: ProcStats.h:87
ProcStats::unique_fd::unique_fd_forward
unique_fd_forward(lseek) unique_fd_forward(read) unique_fd_forward(write) unique_fd_forward(fcntl) unique_fd_forward(fsync) unique_fd_forward(fchown) unique_fd_forward(stat) int close()
Definition: ProcStats.h:75
ProcStats::unique_fd::unique_fd
unique_fd(unique_fd &&other)
Definition: ProcStats.h:66
ProcStats
Definition: ProcStats.h:41
ProcStats::unique_fd::m_fd
int m_fd
Definition: ProcStats.h:61
procInfo::procInfo
procInfo(double sz, double rss_sz)
Definition: ProcStats.h:19
gaudirun.args
list args
Definition: gaudirun.py:290
ProcStats::valid
bool valid
Definition: ProcStats.h:92
ProcStats::buf
char buf[500]
Definition: ProcStats.h:91
procInfo::vsize
double vsize
Definition: ProcStats.h:37
ProcStats::ProcStats
ProcStats()
Definition: ProcStats.cpp:245
ProcStats::fetch
bool fetch(procInfo &fill_me)
Definition: ProcStats.cpp:263
ProcStats::pageSize
double pageSize() const
Definition: ProcStats.h:47
procInfo
Definition: ProcStats.h:16
procInfo::procInfo
procInfo()
Definition: ProcStats.h:18