The Gaudi Framework  v28r2p1 (f1a77ff4)
ProcStats Class Reference

#include <src/ProcStats.h>

Collaboration diagram for ProcStats:

Classes

struct  cleanup
 
class  unique_fd
 

Public Member Functions

bool fetch (procInfo &fill_me)
 
double pageSize () const
 

Static Public Member Functions

static ProcStatsinstance ()
 

Private Member Functions

 ProcStats ()
 

Private Attributes

unique_fd fd
 
double pg_size
 
procInfo curr
 
std::string fname
 
char buf [500]
 
bool valid
 

Static Private Attributes

static ProcStatsinst = 0
 

Friends

struct cleanup
 

Detailed Description

Definition at line 42 of file ProcStats.h.

Constructor & Destructor Documentation

ProcStats::ProcStats ( )
private

Definition at line 247 of file ProcStats.cpp.

247  :valid(false)
248 {
249 #if defined(__linux__) or defined(__APPLE__)
250  pg_size = sysconf(_SC_PAGESIZE); // getpagesize();
251 
252  fname = "/proc/" + std::to_string(getpid()) + "/stat";
253 
254  fd.open( fname.c_str(), O_RDONLY );
255  if(!fd)
256  {
257  cerr << "Failed to open " << fname << endl;
258  return;
259  }
260 #endif // __linux__ or __APPLE__
261  valid=true;
262 }
T to_string(T...args)
T endl(T...args)
unique_fd & open(Args &&...args)
Definition: ProcStats.h:72
double pg_size
Definition: ProcStats.h:89
std::string fname
Definition: ProcStats.h:91
unique_fd fd
Definition: ProcStats.h:88
bool valid
Definition: ProcStats.h:93
T c_str(T...args)

Member Function Documentation

bool ProcStats::fetch ( procInfo fill_me)

Definition at line 265 of file ProcStats.cpp.

266 {
267  if( valid == false ) return false;
268 
269 #if defined(__linux__) or defined(__APPLE__)
270  double pr_size, pr_rssize;
271  linux_proc pinfo;
272  int cnt;
273 
274  fd.lseek(0,SEEK_SET);
275 
276  if((cnt=fd.read(buf,sizeof(buf)))<0)
277  {
278  cout << "LINUX Read of Proc file failed:" << endl;
279  return false;
280  }
281 
282  if(cnt>0)
283  {
284  buf[cnt]='\0';
285 
286  sscanf(buf,
287  //1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3 4 5 6 7 8 9 30 1 2 3 4 5
288  "%d %s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %llu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
289  &pinfo.pid,
290  pinfo.comm,
291  &pinfo.state,
292  &pinfo.ppid,
293  &pinfo.pgrp,
294  &pinfo.session,
295  &pinfo.tty,
296  &pinfo.tpgid,
297  &pinfo.flags,
298  &pinfo.minflt,
299  &pinfo.cminflt,
300  &pinfo.majflt,
301  &pinfo.cmajflt,
302  &pinfo.utime,
303  &pinfo.stime,
304  &pinfo.cutime,
305  &pinfo.cstime,
306  &pinfo.priority,
307  &pinfo.nice,
308  &pinfo.num_threads,
309  &pinfo.itrealvalue,
310  &pinfo.starttime,
311  &pinfo.vsize,
312  &pinfo.rss,
313  &pinfo.rlim,
314  &pinfo.startcode,
315  &pinfo.endcode,
316  &pinfo.startstack,
317  &pinfo.kstkesp,
318  &pinfo.kstkeip,
319  &pinfo.signal,
320  &pinfo.blocked,
321  &pinfo.sigignore,
322  &pinfo.sigcatch,
323  &pinfo.wchan
324  );
325 
326  // resident set size in pages
327  pr_size = (double)pinfo.vsize;
328  pr_rssize = (double)pinfo.rss;
329 
330  f.vsize = pr_size / (1024*1024);
331  f.rss = pr_rssize * pg_size / (1024*1024);
332  }
333 
334 #else
335  f.vsize = 0;
336  f.rss = 0;
337 #endif // __linux__ or __APPLE__
338 
339  bool rc = (curr==f)?false:true;
340 
341  curr.rss=f.rss;
342  curr.vsize=f.vsize;
343 
344  return rc;
345 }
unsigned long minflt
unsigned long kstkesp
unsigned long signal
unsigned long wchan
unsigned long sigcatch
T sscanf(T...args)
unsigned long flags
T endl(T...args)
double pg_size
Definition: ProcStats.h:89
procInfo curr
Definition: ProcStats.h:90
double rss
Definition: ProcStats.h:39
unique_fd fd
Definition: ProcStats.h:88
rc
Definition: IOTest.py:92
unsigned long vsize
unsigned long startstack
unsigned long cminflt
unsigned long majflt
unsigned long long starttime
unsigned long cmajflt
unsigned long kstkeip
unsigned long startcode
bool valid
Definition: ProcStats.h:93
unsigned long utime
char buf[500]
Definition: ProcStats.h:92
unsigned long blocked
double vsize
Definition: ProcStats.h:38
unsigned long endcode
unsigned long stime
unsigned long sigignore
unsigned long rlim
ProcStats * ProcStats::instance ( )
static

Definition at line 239 of file ProcStats.cpp.

239  {
240  static cleanup c;
241  if(!inst) inst = new ProcStats;
242  return inst;
243 }
static ProcStats * inst
Definition: ProcStats.h:95
friend struct cleanup
Definition: ProcStats.h:59
double ProcStats::pageSize ( ) const
inline

Definition at line 48 of file ProcStats.h.

48 { return pg_size; }
double pg_size
Definition: ProcStats.h:89

Friends And Related Function Documentation

friend struct cleanup
friend

Definition at line 59 of file ProcStats.h.

Member Data Documentation

char ProcStats::buf[500]
private

Definition at line 92 of file ProcStats.h.

procInfo ProcStats::curr
private

Definition at line 90 of file ProcStats.h.

unique_fd ProcStats::fd
private

Definition at line 88 of file ProcStats.h.

std::string ProcStats::fname
private

Definition at line 91 of file ProcStats.h.

ProcStats * ProcStats::inst = 0
staticprivate

Definition at line 95 of file ProcStats.h.

double ProcStats::pg_size
private

Definition at line 89 of file ProcStats.h.

bool ProcStats::valid
private

Definition at line 93 of file ProcStats.h.


The documentation for this class was generated from the following files: