The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
System::ProcessDescriptor Class Reference

Provides access to process information. More...

#include </builds/gaudi/Gaudi/GaudiKernel/src/Lib/ProcessDescriptor.h>

Classes

class  ProcessHandle
 

Public Member Functions

 ProcessDescriptor ()=default
 
virtual ~ProcessDescriptor ()=default
 
long query (long pid, InfoType fetch, PROCESS_BASIC_INFORMATION *info)
 
long query (long pid, InfoType fetch, POOLED_USAGE_AND_LIMITS *info)
 
long query (long pid, InfoType fetch, KERNEL_USER_TIMES *info)
 
long query (long pid, InfoType fetch, QUOTA_LIMITS *info)
 
long query (long pid, InfoType fetch, VM_COUNTERS *info)
 
long query (long pid, InfoType fetch, IO_COUNTERS *info)
 
long query (long pid, InfoType fetch, long *info)
 

Detailed Description

Provides access to process information.

Author
M.Frank
Sebastien Ponce

Definition at line 117 of file ProcessDescriptor.h.

Constructor & Destructor Documentation

◆ ProcessDescriptor()

System::ProcessDescriptor::ProcessDescriptor ( )
default

◆ ~ProcessDescriptor()

virtual System::ProcessDescriptor::~ProcessDescriptor ( )
virtualdefault

Member Function Documentation

◆ query() [1/7]

long System::ProcessDescriptor::query ( long pid,
InfoType fetch,
IO_COUNTERS * info )

Definition at line 343 of file ProcessDescriptor.cpp.

343 {
344 if ( info == 0 ) return 0;
345 long status = 1;
346
347 if ( fetch == IO ) {
348#if defined( __linux )
349 linux_proc prc;
350 readProcStat( processID( pid ), prc );
351 rusage usage;
352 getrusage( RUSAGE_SELF, &usage );
353 info->ReadOperationCount = usage.ru_inblock;
354 info->WriteOperationCount = usage.ru_oublock;
355 info->OtherOperationCount = 0;
356 info->ReadTransferCount = usage.ru_inblock;
357 info->WriteTransferCount = usage.ru_oublock;
358 info->OtherTransferCount = 0;
359#else // All Other
360 if ( pid ) {}
361#endif // End ALL OS
362 }
363 return status;
364}
void readProcStat(long pid, linux_proc &pinfo)

◆ query() [2/7]

long System::ProcessDescriptor::query ( long pid,
InfoType fetch,
KERNEL_USER_TIMES * info )

Definition at line 528 of file ProcessDescriptor.cpp.

528 {
529 if ( info == 0 ) return 0;
530 long status = 1;
531
532 if ( fetch == Times ) {
533#if defined( __linux ) // Linux
534 static long long prc_start = 0;
535 bool myself = pid <= 0 || pid == ::getpid(); // avoid unnecessary calls to getpid if pid<0
536 if ( myself && prc_start == 0 ) { // called only once to set prc_start
537 linux_proc prc;
538 readProcStat( processID( pid ), prc );
539 // prc.startup is in ticks since system start, need to offset for absolute time
540 tms tmsb;
541 static long long offset =
542 100 * static_cast<long long>( time( nullptr ) ) - static_cast<long long>( times( &tmsb ) );
543 prc_start = ( prc.starttime + offset ) * TICK_TO_100NSEC;
544 }
545
546 if ( myself ) { // myself
547 tms tmsb;
548 times( &tmsb );
549 info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
550 info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
551 info->CreateTime = prc_start;
552 } else { // other process
553 linux_proc prc;
554 readProcStat( processID( pid ), prc );
555 tms tmsb;
556 static long long offset =
557 100 * static_cast<long long>( time( nullptr ) ) - static_cast<long long>( times( &tmsb ) );
558
559 tms t;
560 times( &t );
561 info->UserTime = t.tms_utime * TICK_TO_100NSEC;
562 info->KernelTime = t.tms_stime * TICK_TO_100NSEC;
563 info->CreateTime = ( prc.starttime + offset ) * TICK_TO_100NSEC;
564 }
565 info->ExitTime = 0;
566
567 status = 1;
568
569#elif defined( __APPLE__ )
570 if ( pid ) {}
571// FIXME (MCl): Make an alternative function get timing on OSX
572// times() seems to cause a segmentation fault
573#else // no /proc file system: assume sys_start for the first call
574 tms tmsb;
575 static clock_t sys_start = times( 0 );
576 static long long offset = 100 * long long( time( 0 ) ) - sys_start;
577 clock_t now = times( &tmsb );
578 info->CreateTime = offset + now;
579 info->UserTime = tmsb.tms_utime;
580 info->KernelTime = tmsb.tms_stime;
581 info->CreateTime *= TICK_TO_100NSEC;
582 info->UserTime *= TICK_TO_100NSEC;
583 info->KernelTime *= TICK_TO_100NSEC;
584 info->ExitTime = 0;
585 status = 1;
586#endif
587 }
588
589 return status;
590}
unsigned long long starttime

◆ query() [3/7]

long System::ProcessDescriptor::query ( long pid,
InfoType fetch,
long * info )

Definition at line 403 of file ProcessDescriptor.cpp.

403 {
404
405 if ( info == 0 ) return 0;
406 long status = 1;
407
408 switch ( fetch ) {
409 case PriorityBoost:
410 // Not applicable
411 status = 0;
412 *info = 0;
413 status = ( status == 0 ) ? 1 : 0;
414 break;
415 default:
416 status = -1;
417 *info = -1;
418 break;
419 }
420 return status;
421}
@ PriorityBoost
Definition SystemBase.h:15

◆ query() [4/7]

long System::ProcessDescriptor::query ( long pid,
InfoType fetch,
POOLED_USAGE_AND_LIMITS * info )

Definition at line 366 of file ProcessDescriptor.cpp.

366 {
367 if ( info == 0 ) return 0;
368 long status = 1;
369
370 if ( fetch == Quota ) {
371#if defined( __linux ) // Linux
372 // rusage usage;
373 // getrusage(RUSAGE_SELF, &usage);
374 rlimit lim;
375
376 getrlimit( RLIMIT_DATA, &lim );
377 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
378 info->PeakPagedPoolUsage = lim.rlim_cur;
379 info->PagedPoolUsage = lim.rlim_cur;
380 info->PagedPoolLimit = lim.rlim_max;
381
382 getrlimit( RLIMIT_STACK, &lim );
383 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
384 info->PeakNonPagedPoolUsage = lim.rlim_cur;
385 info->NonPagedPoolUsage = lim.rlim_cur;
386 info->NonPagedPoolLimit = lim.rlim_max;
387
388 linux_proc prc;
389 readProcStat( processID( pid ), prc );
390 info->PeakPagefileUsage = prc.rss * pg_size;
391 info->PagefileUsage = prc.rss * pg_size;
392 info->PagefileLimit = 0xFFFFFFFF;
393#elif defined( __APPLE__ )
394 if ( pid ) {}
395#else // All Other
396 if ( pid ) {}
397#endif // End ALL OS
398 }
399
400 return status;
401}

◆ query() [5/7]

long System::ProcessDescriptor::query ( long pid,
InfoType fetch,
PROCESS_BASIC_INFORMATION * info )

Definition at line 502 of file ProcessDescriptor.cpp.

502 {
503 if ( info == 0 ) return 0;
504 long status = 1;
505
506 if ( fetch == ProcessBasics ) {
507#if defined( __linux ) // Linux
508 linux_proc prc;
509 pid = processID( pid );
510 readProcStat( pid, prc );
511 info->ExitStatus = 0;
512 info->PebBaseAddress = (PPEB)prc.startcode;
513 info->BasePriority = 2 * 15 - prc.priority;
514 // std::cout << "Base Priority=" << info->BasePriority << "|"
515 // << prc.priority << std::endl;
516 info->AffinityMask = prc.flags;
517 // std::cout << "Flags =" << info->AffinityMask << "|"
518 // << prc.flags << std::endl;
519 info->UniqueProcessId = pid;
520 info->InheritedFromUniqueProcessId = prc.ppid;
521#else // All Other
522 if ( pid ) {}
523#endif // End ALL OS
524 }
525 return status;
526}
@ ProcessBasics
Definition SystemBase.h:15
struct _PEB * PPEB
Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.
unsigned long startcode

◆ query() [6/7]

long System::ProcessDescriptor::query ( long pid,
InfoType fetch,
QUOTA_LIMITS * info )

Definition at line 461 of file ProcessDescriptor.cpp.

461 {
462 if ( info == 0 ) return 0;
463 long status = 1;
464
465 if ( fetch == Quota ) {
466#if defined( __linux ) // Linux
467 // On linux all this stuff typically is not set
468 // (ie. rlim_max=RLIM_INFINITY...)
469
470 if ( pid > 0 && pid != ::getpid() ) return 0; // only possible for myself
471
472 rlimit lim;
473 getrlimit( RLIMIT_DATA, &lim );
474 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
475 info->PagedPoolLimit = lim.rlim_max;
476
477 getrlimit( RLIMIT_STACK, &lim );
478 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
479 info->NonPagedPoolLimit = lim.rlim_max;
480 info->MinimumWorkingSetSize = 0;
481
482 getrlimit( RLIMIT_RSS, &lim );
483 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
484 info->MaximumWorkingSetSize = lim.rlim_max;
485
486 getrlimit( RLIMIT_AS, &lim );
487 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
488 info->PagefileLimit = lim.rlim_max;
489
490 getrlimit( RLIMIT_CPU, &lim );
491 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
492 info->TimeLimit = lim.rlim_max;
493#elif defined( __APPLE__ )
494 if ( pid ) {}
495#else // All Other
496 if ( pid ) {}
497#endif // End ALL OS
498 }
499 return status;
500}

◆ query() [7/7]

long System::ProcessDescriptor::query ( long pid,
InfoType fetch,
VM_COUNTERS * info )

Definition at line 423 of file ProcessDescriptor.cpp.

423 {
424 if ( info == 0 ) return 0;
425 long status = 1;
426
427 if ( fetch == Memory ) {
428#if defined( __linux ) // Linux
429 const ssize_t bufsize = 1024;
430 char buf[bufsize];
431 pid = processID( pid );
432 sprintf( buf, "/proc/%ld/statm", pid );
433 long size, resident, share, trs, lrs, drs, dt;
434 int fd = open( buf, O_RDONLY );
435 ssize_t nread = read( fd, buf, bufsize );
436 close( fd );
437 if ( nread < bufsize && nread >= 0 ) buf[nread] = '\0';
438 fd = sscanf( buf, "%ld %ld %ld %ld %ld %ld %ld", &size, &resident, &share, &trs, &drs, &lrs, &dt );
439 linux_proc prc;
440 readProcStat( pid, prc );
441 info->PeakVirtualSize = prc.vsize;
442 info->VirtualSize = prc.vsize;
443 info->PeakWorkingSetSize = resident * pg_size;
444 info->WorkingSetSize = resident * pg_size;
445 info->QuotaPeakPagedPoolUsage = share * pg_size;
446 info->QuotaPagedPoolUsage = share * pg_size;
447 info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size; // drs = data/stack size
448 info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size; // trs = VmExe size
449 info->PageFaultCount = prc.majflt + prc.minflt;
450 info->PagefileUsage = prc.vsize - resident * pg_size;
451 info->PeakPagefileUsage = prc.vsize - resident * pg_size;
452#elif defined( __APPLE__ )
453 if ( pid ) {}
454#else // All Other
455 if ( pid ) {}
456#endif // End ALL OS
457 }
458 return status;
459}
constexpr auto size(const T &, Args &&...) noexcept
read(f, regex=".*", skipevents=0)
unsigned long vsize
unsigned long majflt
unsigned long minflt

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