CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::service::ProcInfoFetcher Class Reference

#include <ProcInfoFetcher.h>

Public Member Functions

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

Private Attributes

char buf_ [500]
 
int fd_
 
double pg_size_
 

Detailed Description

Definition at line 41 of file ProcInfoFetcher.h.

Constructor & Destructor Documentation

ProcInfoFetcher::ProcInfoFetcher ( )

Definition at line 171 of file ProcInfoFetcher.cc.

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

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

Definition at line 181 of file ProcInfoFetcher.cc.

References fd_.

181  {
182 #ifdef LINUX
183  close(fd_);
184 #endif
185  }
edm::service::ProcInfoFetcher::ProcInfoFetcher ( ProcInfoFetcher const &  )
delete

Member Function Documentation

ProcInfo ProcInfoFetcher::fetch ( ) const

Definition at line 186 of file ProcInfoFetcher.cc.

References buf_, fd_, pg_size_, edm::service::ProcInfo::rss, and edm::service::ProcInfo::vsize.

Referenced by edm::service::ResourceEnforcer::check().

186  {
187  ProcInfo ret;
188 
189 #ifdef __linux__
190  double pr_size = 0.0, pr_rssize = 0.0;
191 
192  linux_proc pinfo;
193  int cnt;
194 
195  lseek(fd_, 0, SEEK_SET);
196 
197  if ((cnt = read(fd_, buf_, sizeof(buf_) - 1)) < 0) {
198  perror("Read of Proc file failed:");
199  return ProcInfo();
200  }
201 
202  if (cnt > 0) {
203  buf_[cnt] = '\0';
204 
205  try {
206  Fetcher fetcher(buf_);
207  fetcher >> pinfo.pid >> pinfo.comm >> pinfo.state >> pinfo.ppid >> pinfo.pgrp >> pinfo.session >> pinfo.tty >>
208  pinfo.tpgid >> pinfo.flags >> pinfo.minflt >> pinfo.cminflt >> pinfo.majflt >> pinfo.cmajflt >>
209  pinfo.utime >> pinfo.stime >> pinfo.cutime >> pinfo.cstime >> pinfo.priority >> pinfo.nice >>
210  pinfo.num_threads >> pinfo.itrealvalue >> pinfo.starttime >> pinfo.vsize >> pinfo.rss >> pinfo.rlim >>
211  pinfo.startcode >> pinfo.endcode >> pinfo.startstack >> pinfo.kstkesp >> pinfo.kstkeip >> pinfo.signal >>
212  pinfo.blocked >> pinfo.sigignore >> pinfo.sigcatch >> pinfo.wchan;
213  } catch (boost::bad_lexical_cast& iE) {
214  LogWarning("ProcInfoFetcher") << "Parsing of Prof file failed:" << iE.what() << std::endl;
215  return ProcInfo();
216  }
217 
218  // resident set size in pages
219  pr_size = (double)pinfo.vsize;
220  pr_rssize = (double)pinfo.rss;
221 
222  ret.vsize = pr_size / (1024.0 * 1024.0);
223  ret.rss = (pr_rssize * pg_size_) / (1024.0 * 1024.0);
224  }
225 #else
226  ret.vsize = 0;
227  ret.rss = 0;
228 #endif
229  return ret;
230  }
ProcInfoFetcher& edm::service::ProcInfoFetcher::operator= ( ProcInfoFetcher const &  )
delete

Member Data Documentation

char edm::service::ProcInfoFetcher::buf_[500]
mutableprivate

Definition at line 53 of file ProcInfoFetcher.h.

Referenced by fetch().

int edm::service::ProcInfoFetcher::fd_
private

Definition at line 52 of file ProcInfoFetcher.h.

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

double edm::service::ProcInfoFetcher::pg_size_
private

Definition at line 51 of file ProcInfoFetcher.h.

Referenced by fetch().