| The Gaudi Framework v32r1 (f65d50dc)

Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
ProcStats Class Reference

`#include <src/ProcStats.h>`

Collaboration diagram for ProcStats:
[legend]

## Classes
struct | cleanup
class | unique_fd

## Public Member Functions
bool | fetch (procInfo &fill_me)
double | pageSize () const

## Static Public Member Functions
static ProcStats * | instance ()

## Private Member Functions
| ProcStats ()

## Private Attributes
unique_fd | fd
double | pg_size
procInfo | curr
std::string | fname
char | buf [500]
bool | valid

## Static Private Attributes
static ProcStats * | inst = 0

## Friends
struct | cleanup

## Detailed Description

Definition at line 41 of file ProcStats.h.

## Constructor & Destructor Documentation

## ◆ ProcStats()

ProcStats::ProcStats | ( |  | ) |
| private

Definition at line 247 of file ProcStats.cpp.

247 : valid( false ) {
248 #if defined( __linux__ ) or defined( __APPLE__ )
249 pg_size = sysconf( _SC_PAGESIZE ); // getpagesize();
250
251 fname = "/proc/" + std::to_string( getpid() ) + "/stat";
252
253 fd.open( fname.c_str(), O_RDONLY );
254 if ( !fd ) {
255 cerr << "Failed to open " << fname << endl;
256 return;
257 }
258 #endif // __linux__ or __APPLE__
259 valid = true;
260 }
std::to_string
T to_string(T... args)
std::endl
T endl(T... args)
ProcStats::unique_fd::open
unique_fd & open(Args &&... args)
Definition: ProcStats.h:75
ProcStats::pg_size
double pg_size
Definition: ProcStats.h:95
ProcStats::fname
std::string fname
Definition: ProcStats.h:97
ProcStats::fd
unique_fd fd
Definition: ProcStats.h:94
ProcStats::valid
bool valid
Definition: ProcStats.h:99
std::string::c_str
T c_str(T... args)

## Member Function Documentation

## ◆ fetch()

bool ProcStats::fetch | ( | procInfo & | fill_me | ) |

Definition at line 262 of file ProcStats.cpp.

262 {
263 if ( valid == false ) return false;
264
265 #if defined( __linux__ ) or defined( __APPLE__ )
266 double pr_size, pr_rssize;
267 linux_proc pinfo;
268 int cnt;
269
270 fd.lseek( 0, SEEK_SET );
271
272 if ( ( cnt = fd.read( buf, sizeof( buf ) ) ) < 0 ) {
273 cout << "LINUX Read of Proc file failed:" << endl;
274 return false;
275 }
276
277 if ( cnt > 0 ) {
278 buf[std::min( static_cast<std::size_t>( cnt ), sizeof( buf ) - 1 )] = '\0';
279
280 sscanf( buf,
281 // 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
282 // 30 1 2 3 4 5
283 "%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 "
284 "%lu %lu %lu %lu %lu %lu %lu",
285 &pinfo.pid, pinfo.comm, &pinfo.state, &pinfo.ppid, &pinfo.pgrp, &pinfo.session, &pinfo.tty, &pinfo.tpgid,
286 &pinfo.flags, &pinfo.minflt, &pinfo.cminflt, &pinfo.majflt, &pinfo.cmajflt, &pinfo.utime, &pinfo.stime,
287 &pinfo.cutime, &pinfo.cstime, &pinfo.priority, &pinfo.nice, &pinfo.num_threads, &pinfo.itrealvalue,
288 &pinfo.starttime, &pinfo.vsize, &pinfo.rss, &pinfo.rlim, &pinfo.startcode, &pinfo.endcode,
289 &pinfo.startstack, &pinfo.kstkesp, &pinfo.kstkeip, &pinfo.signal, &pinfo.blocked, &pinfo.sigignore,
290 &pinfo.sigcatch, &pinfo.wchan );
291
292 // resident set size in pages
293 pr_size = (double)pinfo.vsize;
294 pr_rssize = (double)pinfo.rss;
295
296 f.vsize = pr_size / ( 1024 * 1024 );
297 f.rss = pr_rssize * pg_size / ( 1024 * 1024 );
298 }
299
300 #else
301 f.vsize = 0;
302 f.rss = 0;
303 #endif // __linux__ or __APPLE__
304
305 bool rc = ( curr == f ) ? false : true;
306
307 curr.rss = f.rss;
308 curr.vsize = f.vsize;
309
310 return rc;
311 }
linux_proc::minflt
unsigned long minflt
Definition: ProcessDescriptor.cpp:268
linux_proc::kstkesp
unsigned long kstkesp
Definition: ProcessDescriptor.cpp:287
linux_proc::signal
unsigned long signal
Definition: ProcessDescriptor.cpp:289
linux_proc::wchan
unsigned long wchan
Definition: ProcessDescriptor.cpp:293
linux_proc::sigcatch
unsigned long sigcatch
Definition: ProcessDescriptor.cpp:292
linux_proc::state
char state
Definition: ProcessDescriptor.cpp:261
linux_proc::tty
int tty
Definition: ProcessDescriptor.cpp:265
std::sscanf
T sscanf(T... args)
linux_proc::flags
unsigned long flags
Definition: ProcessDescriptor.cpp:267
linux_proc::pid
int pid
Definition: ProcessDescriptor.cpp:259
linux_proc
Definition: ProcessDescriptor.cpp:258
std::endl
T endl(T... args)
linux_proc::comm
char comm[400]
Definition: ProcessDescriptor.cpp:260
linux_proc::num_threads
long num_threads
Definition: ProcessDescriptor.cpp:278
ProcStats::pg_size
double pg_size
Definition: ProcStats.h:95
ProcStats::curr
procInfo curr
Definition: ProcStats.h:96
linux_proc::session
int session
Definition: ProcessDescriptor.cpp:264
std::min
T min(T... args)
linux_proc::cstime
long cstime
Definition: ProcessDescriptor.cpp:275
linux_proc::pgrp
int pgrp
Definition: ProcessDescriptor.cpp:263
procInfo::rss
double rss
Definition: ProcStats.h:38
ProcStats::fd
unique_fd fd
Definition: ProcStats.h:94
linux_proc::cutime
long cutime
Definition: ProcessDescriptor.cpp:274
linux_proc::nice
long nice
Definition: ProcessDescriptor.cpp:277
IOTest.rc
rc
Definition: IOTest.py:101
linux_proc::itrealvalue
long itrealvalue
Definition: ProcessDescriptor.cpp:279
linux_proc::vsize
unsigned long vsize
Definition: ProcessDescriptor.cpp:281
linux_proc::startstack
unsigned long startstack
Definition: ProcessDescriptor.cpp:286
linux_proc::rss
long rss
Definition: ProcessDescriptor.cpp:282
linux_proc::cminflt
unsigned long cminflt
Definition: ProcessDescriptor.cpp:269
linux_proc::tpgid
int tpgid
Definition: ProcessDescriptor.cpp:266
linux_proc::majflt
unsigned long majflt
Definition: ProcessDescriptor.cpp:270
linux_proc::starttime
unsigned long long starttime
Definition: ProcessDescriptor.cpp:280
linux_proc::cmajflt
unsigned long cmajflt
Definition: ProcessDescriptor.cpp:271
linux_proc::kstkeip
unsigned long kstkeip
Definition: ProcessDescriptor.cpp:288
linux_proc::priority
long priority
Definition: ProcessDescriptor.cpp:276
linux_proc::startcode
unsigned long startcode
Definition: ProcessDescriptor.cpp:284
ProcStats::valid
bool valid
Definition: ProcStats.h:99
linux_proc::utime
unsigned long utime
Definition: ProcessDescriptor.cpp:272
linux_proc::ppid
int ppid
Definition: ProcessDescriptor.cpp:262
ProcStats::buf
char buf[500]
Definition: ProcStats.h:98
linux_proc::blocked
unsigned long blocked
Definition: ProcessDescriptor.cpp:290
procInfo::vsize
double vsize
Definition: ProcStats.h:37
linux_proc::endcode
unsigned long endcode
Definition: ProcessDescriptor.cpp:285
linux_proc::stime
unsigned long stime
Definition: ProcessDescriptor.cpp:273
linux_proc::sigignore
unsigned long sigignore
Definition: ProcessDescriptor.cpp:291
linux_proc::rlim
unsigned long rlim
Definition: ProcessDescriptor.cpp:283

## ◆ instance()

ProcStats * ProcStats::instance | ( |  | ) |
| static

Definition at line 239 of file ProcStats.cpp.

239 {
240 static cleanup c;
241 if ( !inst ) inst = new ProcStats;
242 return inst;
243 }
ProcStats::inst
static ProcStats * inst
Definition: ProcStats.h:101
gaudirun.c
c
Definition: gaudirun.py:487
ProcStats::cleanup
friend struct cleanup
Definition: ProcStats.h:56
ProcStats::ProcStats
ProcStats()
Definition: ProcStats.cpp:247

## ◆ pageSize()

double ProcStats::pageSize | ( |  | ) | const
| inline

Definition at line 46 of file ProcStats.h.

46 { return pg_size; }
ProcStats::pg_size
double pg_size
Definition: ProcStats.h:95

## Friends And Related Function Documentation

## ◆ cleanup

friend struct cleanup
| friend

Definition at line 56 of file ProcStats.h.

## Member Data Documentation

## ◆ buf

char ProcStats::buf[500]
| private

Definition at line 98 of file ProcStats.h.

## ◆ curr

procInfo ProcStats::curr
| private

Definition at line 96 of file ProcStats.h.

## ◆ fd

unique_fd ProcStats::fd
| private

Definition at line 94 of file ProcStats.h.

## ◆ fname

std::string ProcStats::fname
| private

Definition at line 97 of file ProcStats.h.

## ◆ inst

ProcStats * ProcStats::inst = 0
| static private

Definition at line 101 of file ProcStats.h.

## ◆ pg_size

double ProcStats::pg_size
| private

Definition at line 95 of file ProcStats.h.

## ◆ valid

bool ProcStats::valid
| private

Definition at line 99 of file ProcStats.h.

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

- GaudiAud/src/ProcStats.h
- GaudiAud/src/ProcStats.cpp