All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ProcStats Class Reference

#include <src/ProcStats.h>

Collaboration diagram for ProcStats:

Classes

struct  cleanup
 

Public Member Functions

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

Static Public Member Functions

static ProcStatsinstance ()
 

Private Member Functions

 ProcStats ()
 
 ~ProcStats ()
 

Private Attributes

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

Constructor & Destructor Documentation

ProcStats::ProcStats ( )
private

Definition at line 249 of file ProcStats.cpp.

249  :valid(false)
250 {
251 #ifdef __linux
252  pg_size = sysconf(_SC_PAGESIZE); // getpagesize();
253  std::ostringstream ost;
254 
255  ost << "/proc/" << getpid() << "/stat";
256  fname = ost.str();
257  if((fd=open(fname.c_str(),O_RDONLY))<0)
258  {
259  cerr << "Failed to open " << ost.str() << endl;
260  return;
261  }
262 #endif
263  valid=true;
264 }
double pg_size
Definition: ProcStats.h:58
std::string fname
Definition: ProcStats.h:60
int fd
Definition: ProcStats.h:57
bool valid
Definition: ProcStats.h:62
ProcStats::~ProcStats ( )
private

Definition at line 266 of file ProcStats.cpp.

267 {
268 #ifdef __linux
269  close(fd);
270 #endif
271 }
int fd
Definition: ProcStats.h:57

Member Function Documentation

bool ProcStats::fetch ( procInfo fill_me)

Definition at line 273 of file ProcStats.cpp.

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

Definition at line 240 of file ProcStats.cpp.

240  {
241  static cleanup c;
242  if(inst==0)
243  inst = new ProcStats;
244  return inst;
245 }
static ProcStats * inst
Definition: ProcStats.h:64
tuple c
Definition: gaudirun.py:341
friend struct cleanup
Definition: ProcStats.h:55
double ProcStats::pageSize ( ) const
inline

Definition at line 43 of file ProcStats.h.

43 { return pg_size; }
double pg_size
Definition: ProcStats.h:58

Friends And Related Function Documentation

friend struct cleanup
friend

Definition at line 55 of file ProcStats.h.

Member Data Documentation

char ProcStats::buf[500]
private

Definition at line 61 of file ProcStats.h.

procInfo ProcStats::curr
private

Definition at line 59 of file ProcStats.h.

int ProcStats::fd
private

Definition at line 57 of file ProcStats.h.

std::string ProcStats::fname
private

Definition at line 60 of file ProcStats.h.

ProcStats * ProcStats::inst = 0
staticprivate

Definition at line 64 of file ProcStats.h.

double ProcStats::pg_size
private

Definition at line 58 of file ProcStats.h.

bool ProcStats::valid
private

Definition at line 62 of file ProcStats.h.


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