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 41 of file ProcStats.h.

Constructor & Destructor Documentation

ProcStats::ProcStats ( )
private

Definition at line 245 of file ProcStats.cpp.

245  :valid(false)
246 {
247 #ifdef __linux
248  pg_size = sysconf(_SC_PAGESIZE); // getpagesize();
249 
250  fname = "/proc/" + std::to_string(getpid()) + "/stat";
251 
252  fd.open( fname.c_str(), O_RDONLY );
253  if(!fd)
254  {
255  cerr << "Failed to open " << fname << endl;
256  return;
257  }
258 #endif
259  valid=true;
260 }
T to_string(T...args)
T endl(T...args)
unique_fd & open(Args &&...args)
Definition: ProcStats.h:71
double pg_size
Definition: ProcStats.h:88
std::string fname
Definition: ProcStats.h:90
unique_fd fd
Definition: ProcStats.h:87
bool valid
Definition: ProcStats.h:92
T c_str(T...args)

Member Function Documentation

bool ProcStats::fetch ( procInfo fill_me)

Definition at line 263 of file ProcStats.cpp.

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

Definition at line 237 of file ProcStats.cpp.

237  {
238  static cleanup c;
239  if(!inst) inst = new ProcStats;
240  return inst;
241 }
static ProcStats * inst
Definition: ProcStats.h:94
tuple c
Definition: gaudirun.py:391
friend struct cleanup
Definition: ProcStats.h:58
double ProcStats::pageSize ( ) const
inline

Definition at line 47 of file ProcStats.h.

47 { return pg_size; }
double pg_size
Definition: ProcStats.h:88

Friends And Related Function Documentation

friend struct cleanup
friend

Definition at line 58 of file ProcStats.h.

Member Data Documentation

char ProcStats::buf[500]
private

Definition at line 91 of file ProcStats.h.

procInfo ProcStats::curr
private

Definition at line 89 of file ProcStats.h.

unique_fd ProcStats::fd
private

Definition at line 87 of file ProcStats.h.

std::string ProcStats::fname
private

Definition at line 90 of file ProcStats.h.

ProcStats * ProcStats::inst = 0
staticprivate

Definition at line 94 of file ProcStats.h.

double ProcStats::pg_size
private

Definition at line 88 of file ProcStats.h.

bool ProcStats::valid
private

Definition at line 92 of file ProcStats.h.


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