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() [1/2]

ProcInfoFetcher::ProcInfoFetcher ( )

Definition at line 170 of file ProcInfoFetcher.cc.

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

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

◆ ~ProcInfoFetcher()

ProcInfoFetcher::~ProcInfoFetcher ( )

Definition at line 180 of file ProcInfoFetcher.cc.

References fd_.

180  {
181 #ifdef LINUX
182  close(fd_);
183 #endif
184  }

◆ ProcInfoFetcher() [2/2]

edm::service::ProcInfoFetcher::ProcInfoFetcher ( ProcInfoFetcher const &  )
delete

Member Function Documentation

◆ fetch()

ProcInfo ProcInfoFetcher::fetch ( ) const

Definition at line 185 of file ProcInfoFetcher.cc.

References buf_, cppFunctionSkipper::exception, fd_, pg_size_, fileinputsource_cfi::read, and runTheMatrix::ret.

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

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

◆ operator=()

ProcInfoFetcher& edm::service::ProcInfoFetcher::operator= ( ProcInfoFetcher const &  )
delete

Member Data Documentation

◆ buf_

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

Definition at line 53 of file ProcInfoFetcher.h.

Referenced by fetch().

◆ fd_

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

Definition at line 52 of file ProcInfoFetcher.h.

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

◆ pg_size_

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

Definition at line 51 of file ProcInfoFetcher.h.

Referenced by fetch().