| The Gaudi Framework v30r0 (c919700c)

- 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 <fcntl.h>
12 #include <sys/stat.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15 #endif // __linux__ or __APPLE__
16
17 struct procInfo {
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 {
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 cleanup() {}
55 ~cleanup();
56 };
57
58 friend struct cleanup;
59
60 class unique_fd
61 {
62 int m_fd;
63 unique_fd( const unique_fd& ) = delete;
64 unique_fd& operator=( const unique_fd& ) = delete;
65
66 public:
67 unique_fd( int fd = -1 ) : m_fd( fd ) {}
68 unique_fd( unique_fd&& other )
69 {
70 m_fd = other.m_fd;
71 other.m_fd = -1;
72 }
73 ~unique_fd()
74 {
75 if ( m_fd != -1 ) ::close( m_fd );
76 }
77
78 explicit operator bool() const { return m_fd != -1; }
79 template <typename... Args>
80 unique_fd& open( Args&&... args )
81 {
82 m_fd = ::open( std::forward<Args>( args )... );
83 return *this;
84 }
85 #define unique_fd_forward( fun ) \
86 template <typename... Args> \
87 auto fun( Args&&... args ) const->decltype(::fun( m_fd, std::forward<Args>( args )... ) ) \
88 { \
89 return ::fun( m_fd, std::forward<Args>( args )... ); \
90 }
91 unique_fd_forward( lseek ) unique_fd_forward( read ) unique_fd_forward( write ) unique_fd_forward( fcntl )
92 unique_fd_forward( fsync ) unique_fd_forward( fchown ) unique_fd_forward( stat )
93 #undef unique_fd_forward
94 int close()
95 {
96 auto r = ::close( m_fd );
97 m_fd = -1;
98 return r;
99 }
100 };
101
102 unique_fd fd;
103 double pg_size;
104 procInfo curr;
105 std::string fname;
106 char buf[500];
107 bool valid;
108
109 static ProcStats* inst;
110 };
111
112 #endif
ProcStats::inst
static ProcStats * inst
Definition: ProcStats.h:109
gaudirun.fd
fd
Definition: gaudirun.py:478
gaudirun.args
args
Definition: gaudirun.py:244
ProcStats::cleanup
Definition: ProcStats.h:53
ProcStats::unique_fd::~unique_fd
~unique_fd()
Definition: ProcStats.h:73
ProcStats::unique_fd
Definition: ProcStats.h:60
ProcStats::unique_fd::unique_fd
unique_fd(int fd=-1)
Definition: ProcStats.h:67
hivetimeline.read
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:22
procInfo::operator==
bool operator==(const procInfo &p) const
Definition: ProcStats.h:21
ProcStats::unique_fd::open
unique_fd & open(Args &&...args)
Definition: ProcStats.h:80
ProcStats::pg_size
double pg_size
Definition: ProcStats.h:103
ProcStats::curr
procInfo curr
Definition: ProcStats.h:104
ProcStats::fname
std::string fname
Definition: ProcStats.h:105
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
std::string
STL class.
ProcStats::cleanup::cleanup
cleanup()
Definition: ProcStats.h:54
procInfo::rss
double rss
Definition: ProcStats.h:39
ProcStats::fd
unique_fd fd
Definition: ProcStats.h:102
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:91
ProcStats::unique_fd::unique_fd
unique_fd(unique_fd &&other)
Definition: ProcStats.h:68
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:19
ProcStats::valid
bool valid
Definition: ProcStats.h:107
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1259
procInfo::vsize
double vsize
Definition: ProcStats.h:38
unique_fd_forward
#define unique_fd_forward(fun)
Definition: ProcStats.h:85
ProcStats::pageSize
double pageSize() const
Definition: ProcStats.h:48
procInfo
Definition: ProcStats.h:17
procInfo::procInfo
procInfo()
Definition: ProcStats.h:18