Gaudi Framework, version v22r1

Home   Generated: Mon Feb 28 2011
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends

ProcStats Class Reference

#include <ProcStats.h>

Collaboration diagram for ProcStats:
Collaboration graph
[legend]

List of all members.

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 83 of file ProcStats.cpp.

                    :valid(false)
{
#ifdef __linux
  pg_size = sysconf(_SC_PAGESIZE); // getpagesize();
  std::ostringstream ost; 

  ost << "/proc/" << getpid() << "/stat";
  fname = ost.str();
  if((fd=open(fname.c_str(),O_RDONLY))<0)
  {
    cerr << "Failed to open " << ost.str() << endl;
    return;
  }
#endif
  valid=true;
}
ProcStats::~ProcStats (  ) [private]

Definition at line 100 of file ProcStats.cpp.

{
#ifdef __linux
  close(fd);
#endif
}

Member Function Documentation

bool ProcStats::fetch ( procInfo fill_me )

Definition at line 107 of file ProcStats.cpp.

{
  if( valid == false ) return false;

#ifdef __linux
  double pr_size, pr_rssize;
  linux_proc pinfo;
  int cnt;

  lseek(fd,0,SEEK_SET);

  if((cnt=read(fd,buf,sizeof(buf)))<0)
  {
    cout << "LINUX Read of Proc file failed:" << endl;
    return false;
  }

  if(cnt>0)
  {
    buf[cnt]='\0';

    sscanf(buf,
      "%d %s %c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u",
      &pinfo.pid, // %d
      pinfo.comm, // %s
      &pinfo.state, // %c
      &pinfo.ppid, // %d
      &pinfo.pgrp, // %d
      &pinfo.session, // %d
      &pinfo.tty, // %d
      &pinfo.tpgid, // %d
      &pinfo.flags, // %u
      &pinfo.minflt, // %u
      &pinfo.cminflt, // %u
      &pinfo.majflt, // %u
      &pinfo.cmajflt, // %u
      &pinfo.utime, // %d
      &pinfo.stime, // %d
      &pinfo.cutime, // %d
      &pinfo.cstime, // %d
      &pinfo.counter, // %d
      &pinfo.priority, // %d
      &pinfo.timeout, // %u
      &pinfo.itrealvalue, // %u
      &pinfo.starttime, // %d
      &pinfo.vsize, // %u
      &pinfo.rss, // %u
      &pinfo.rlim, // %u
      &pinfo.startcode, // %u
      &pinfo.endcode, // %u
      &pinfo.startstack, // %u
      &pinfo.kstkesp, // %u
      &pinfo.kstkeip, // %u
      &pinfo.signal, // %d
      &pinfo.blocked, // %d
      &pinfo.sigignore, // %d
      &pinfo.sigcatch, // %d
      &pinfo.wchan // %u
      );

      // resident set size in pages
    pr_size = (double)pinfo.vsize;
    pr_rssize = (double)pinfo.rss;

    f.vsize = pr_size   / (1024*1024);
    f.rss   = pr_rssize * pg_size / (1024*1024);
  }

#else
  f.vsize = 0;
  f.rss   = 0;
#endif

  bool rc = (curr==f)?false:true;

  curr.rss=f.rss;
  curr.vsize=f.vsize;

  return rc;
}
ProcStats * ProcStats::instance (  ) [static]

Definition at line 74 of file ProcStats.cpp.

                               {
  static cleanup c;
  if(inst==0)
    inst = new ProcStats;
  return inst;
}
double ProcStats::pageSize (  ) const [inline]

Definition at line 43 of file ProcStats.h.

{ return pg_size; }

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.

Definition at line 59 of file ProcStats.h.

int ProcStats::fd [private]

Definition at line 57 of file ProcStats.h.

Definition at line 60 of file ProcStats.h.

ProcStats * ProcStats::inst = 0 [static, private]

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Feb 28 2011 18:28:22 for Gaudi Framework, version v22r1 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004