| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 #if defined(__linux__) or defined(__APPLE__)
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <fcntl.h>
15 #endif // __linux__ or __APPLE__
16
17 struct procInfo
18 {
19 procInfo() : vsize(0), rss(0) {}
20 procInfo(double sz, double rss_sz): vsize(sz),rss(rss_sz) {}
21
22 bool operator==(const procInfo& p) const {
23 #ifdef __ICC
24 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
25 #pragma warning(push)
26 #pragma warning(disable:1572)
27 #endif
28
29 return vsize==p.vsize && rss==p.rss;
30
31 #ifdef __ICC
32 // re-enable icc remark #1572
33 #pragma warning(pop)
34 #endif
35 }
36
37 // see proc(4) man pages for units and a description
38 double vsize; // in MB (used to be in pages?)
39 double rss; // in MB (used to be in pages?)
40 };
41
42 class ProcStats
43 {
44 public:
45 static ProcStats* instance();
46
47 bool fetch(procInfo& fill_me);
48 double pageSize() const { return pg_size; }
49
50 private:
51 ProcStats();
52
53 struct cleanup
54 {
55 cleanup() { }
56 ~cleanup();
57 };
58
59 friend struct cleanup;
60
61 class unique_fd {
62 int m_fd;
63 unique_fd(const unique_fd&) = delete;
64 unique_fd& operator=(const unique_fd&) = delete;
65 public:
66 unique_fd(int fd=-1) : m_fd(fd) {}
67 unique_fd(unique_fd&& other) { m_fd = other.m_fd; other.m_fd = -1; }
68 ~unique_fd() { if (m_fd != -1) ::close(m_fd); }
69
70 explicit operator bool() const { return m_fd != -1; }
71 template <typename... Args>
72 unique_fd& open(Args&& ... args) { m_fd = ::open(std::forward<Args>(args)...); return *this; }
73 #define unique_fd_forward(fun) template <typename...Args> auto fun(Args&&... args) const \
74 -> decltype(::fun(m_fd,std::forward<Args>(args)...)) \
75 { return ::fun(m_fd,std::forward<Args>(args)...); }
76 unique_fd_forward(lseek)
77 unique_fd_forward(read)
78 unique_fd_forward(write)
79 unique_fd_forward(fcntl)
80 unique_fd_forward(fsync)
81 unique_fd_forward(fchown)
82 unique_fd_forward(stat)
83 #undef unique_fd_forward
84 int close() { auto r = ::close(m_fd); m_fd = -1; return r; }
85 };
86
87
88 unique_fd fd;
89 double pg_size;
90 procInfo curr;
91 std::string fname;
92 char buf[500];
93 bool valid;
94
95 static ProcStats* inst;
96 };
97
98 #endif
99
ProcStats::inst
static ProcStats * inst
Definition: ProcStats.h:95
gaudirun.fd
fd
Definition: gaudirun.py:459
gaudirun.args
args
Definition: gaudirun.py:236
ProcStats::cleanup
Definition: ProcStats.h:53
ProcStats::unique_fd::~unique_fd
~unique_fd()
Definition: ProcStats.h:68
ProcStats::unique_fd
Definition: ProcStats.h:61
ProcStats::unique_fd::unique_fd
unique_fd(int fd=-1)
Definition: ProcStats.h:66
hivetimeline.read
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:19
procInfo::operator==
bool operator==(const procInfo &p) const
Definition: ProcStats.h:22
ProcStats::unique_fd::open
unique_fd & open(Args &&...args)
Definition: ProcStats.h:72
ProcStats::pg_size
double pg_size
Definition: ProcStats.h:89
ProcStats::curr
procInfo curr
Definition: ProcStats.h:90
ProcStats::fname
std::string fname
Definition: ProcStats.h:91
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
std::string
STL class.
ProcStats::cleanup::cleanup
cleanup()
Definition: ProcStats.h:55
procInfo::rss
double rss
Definition: ProcStats.h:39
ProcStats::fd
unique_fd fd
Definition: ProcStats.h:88
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:76
unique_fd_forward
#define unique_fd_forward(fun)
Definition: ProcStats.h:73
ProcStats::unique_fd::unique_fd
unique_fd(unique_fd &&other)
Definition: ProcStats.h:67
ProcStats
Definition: ProcStats.h:42
ProcStats::unique_fd::m_fd
int m_fd
Definition: ProcStats.h:62
procInfo::procInfo
procInfo(double sz, double rss_sz)
Definition: ProcStats.h:20
ProcStats::valid
bool valid
Definition: ProcStats.h:93
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1144
procInfo::vsize
double vsize
Definition: ProcStats.h:38
ProcStats::pageSize
double pageSize() const
Definition: ProcStats.h:48
procInfo
Definition: ProcStats.h:17
procInfo::procInfo
procInfo()
Definition: ProcStats.h:19