CMS 3D CMS Logo

Public Member Functions | Private Attributes

edm::service::ProcInfoFetcher Class Reference

#include <ProcInfoFetcher.h>

List of all members.

Public Member Functions

ProcInfo fetch () const
ProcInfoFetcheroperator= (ProcInfoFetcher const &)
 ProcInfoFetcher ()
 ProcInfoFetcher (ProcInfoFetcher const &)
 ~ProcInfoFetcher ()

Private Attributes

char buf_ [500]
int fd_
double pg_size_

Detailed Description

Definition at line 45 of file ProcInfoFetcher.h.


Constructor & Destructor Documentation

ProcInfoFetcher::ProcInfoFetcher ( )

Definition at line 165 of file ProcInfoFetcher.cc.

References edm::errors::Configuration, Exception, and fd_.

                                    :
    pg_size_(sysconf(_SC_PAGESIZE)) {
#ifdef __linux__
      std::ostringstream ost;
      ost << "/proc/" << getpid() << "/stat";
      
      if((fd_ = open(ost.str().c_str(), O_RDONLY)) < 0) {
        throw Exception(errors::Configuration)
        << "Failed to open " << ost.str() << std::endl;
      }
#endif
    }
ProcInfoFetcher::~ProcInfoFetcher ( )

Definition at line 177 of file ProcInfoFetcher.cc.

References fd_.

                                      {
#ifdef LINUX
      close(fd_);
#endif      
    }
edm::service::ProcInfoFetcher::ProcInfoFetcher ( ProcInfoFetcher const &  )

Member Function Documentation

ProcInfo ProcInfoFetcher::fetch ( ) const

Definition at line 182 of file ProcInfoFetcher.cc.

References buf_, fd_, pg_size_, SiPixelLorentzAngle_cfi::read, run_regression::ret, edm::service::ProcInfo::rss, and edm::service::ProcInfo::vsize.

Referenced by edm::service::ResourceEnforcer::check(), and edm::service::SimpleMemoryCheck::fetch().

                                          {
      ProcInfo ret;
      
#ifdef __linux__
      double pr_size = 0.0, pr_rssize = 0.0;
      
      linux_proc pinfo;
      int cnt;
      
      lseek(fd_, 0, SEEK_SET);
      
      if((cnt = read(fd_, buf_, sizeof(buf_) - 1)) < 0) {
        perror("Read of Proc file failed:");
        return ProcInfo();
      }
      
      if(cnt > 0) {
        buf_[cnt] = '\0';
        
        
        try {
          Fetcher fetcher(buf_);
          fetcher >> pinfo.pid
          >> pinfo.comm
          >> pinfo.state
          >> pinfo.ppid
          >> pinfo.pgrp
          >> pinfo.session
          >> pinfo.tty
          >> pinfo.tpgid
          >> pinfo.flags
          >> pinfo.minflt
          >> pinfo.cminflt
          >> pinfo.majflt
          >> pinfo.cmajflt
          >> pinfo.utime
          >> pinfo.stime
          >> pinfo.cutime
          >> pinfo.cstime
          >> pinfo.priority
          >> pinfo.nice
          >> pinfo.num_threads
          >> pinfo.itrealvalue
          >> pinfo.starttime
          >> pinfo.vsize
          >> pinfo.rss
          >> pinfo.rlim
          >> pinfo.startcode
          >> pinfo.endcode
          >> pinfo.startstack
          >> pinfo.kstkesp
          >> pinfo.kstkeip
          >> pinfo.signal
          >> pinfo.blocked
          >> pinfo.sigignore
          >> pinfo.sigcatch
          >> pinfo.wchan;
        } catch (boost::bad_lexical_cast& iE) {
          LogWarning("ProcInfoFetcher")<<"Parsing of Prof file failed:"<<iE.what()<<std::endl;
          return ProcInfo();
        }
        
        // resident set size in pages
        pr_size = (double)pinfo.vsize;
        pr_rssize = (double)pinfo.rss;
        
        ret.vsize = pr_size / (1024.0*1024.0);
        ret.rss   = (pr_rssize * pg_size_) / (1024.0*1024.0);
      }
#else
      ret.vsize = 0;
      ret.rss = 0;
#endif
      return ret;
    }
ProcInfoFetcher& edm::service::ProcInfoFetcher::operator= ( ProcInfoFetcher const &  )

Member Data Documentation

char edm::service::ProcInfoFetcher::buf_[500] [mutable, private]

Definition at line 56 of file ProcInfoFetcher.h.

Referenced by fetch().

Definition at line 55 of file ProcInfoFetcher.h.

Referenced by fetch(), ProcInfoFetcher(), and ~ProcInfoFetcher().

Definition at line 54 of file ProcInfoFetcher.h.

Referenced by fetch().