| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Member Functions | Private Attributes | List of all members
System::ProcessDescriptor Class Reference

Provides access to process information. More...

`#include <src/Lib/ProcessDescriptor.h>`

Collaboration diagram for System::ProcessDescriptor:
[legend]

## Classes
class | ProcessHandle

## Public Member Functions
| ProcessDescriptor ()
virtual | ~ProcessDescriptor ()
long | query (long pid, InfoType info, PROCESS_BASIC_INFORMATION *buffer)
long | query (long pid, InfoType info, POOLED_USAGE_AND_LIMITS *buffer)
long | query (long pid, InfoType info, KERNEL_USER_TIMES *buffer)
long | query (long pid, InfoType info, QUOTA_LIMITS *buffer)
long | query (long pid, InfoType info, VM_COUNTERS *buffer)
long | query (long pid, InfoType info, IO_COUNTERS *buffer)
long | query (long pid, InfoType info, long *buffer)

## Private Attributes
long | m_PRIORITYBOOST [2]
IO_COUNTERS | m_IO_COUNTERS [2]
VM_COUNTERS | m_VM_COUNTERS [2]
KERNEL_USER_TIMES | m_KERNEL_USER_TIMES [2]
POOLED_USAGE_AND_LIMITS | m_POOLED_USAGE_AND_LIMITS [2]
QUOTA_LIMITS | m_QUOTA_LIMITS [2]
PROCESS_BASIC_INFORMATION | m_PROCESS_BASIC_INFORMATION [2]

## Detailed Description

Provides access to process information.

Author
  M.Frank
  Sebastien Ponce

Definition at line 109 of file ProcessDescriptor.h.

## Constructor & Destructor Documentation

System::ProcessDescriptor::ProcessDescriptor | ( |  | ) |

Definition at line 428 of file ProcessDescriptor.cpp.

429 {
430 }

System::ProcessDescriptor::~ProcessDescriptor | ( |  | ) |
| virtual

Definition at line 432 of file ProcessDescriptor.cpp.

432 {
433 }

## Member Function Documentation

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

Definition at line 638 of file ProcessDescriptor.cpp.

640 {
641 long status = 1;
642 ProcessHandle h(pid);
643 PROCESS_BASIC_INFORMATION* vb = &m_PROCESS_BASIC_INFORMATION[h.item()];
644 if ( fetch == ProcessBasics ) {
645 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
646 status = NtApi::NtQueryInformationProcess(h.handle(),
647 ProcessBasicInformation,
648 vb,
649 sizeof(PROCESS_BASIC_INFORMATION),
650 0);
651 status = (status==0) ? 1 : 0;
652 #elif defined(_WIN32) // Windows 95,98...
653 #elif defined(__linux) // Linux
654 linux_proc prc;
655 readProcStat( processID(pid), prc);
656 vb->ExitStatus = 0;
657 vb->PebBaseAddress = (PPEB)prc.startcode;
658 vb->BasePriority = 2*15-prc.priority;
659 // std::cout << "Base Priority=" << vb->BasePriority << "|"
660 // << prc.priority << std::endl;
661 vb->AffinityMask = prc.flags;
662 // std::cout << "Flags =" << vb->AffinityMask << "|"
663 // << prc.flags << std::endl;
664 vb->UniqueProcessId = processID(pid);
665 vb->InheritedFromUniqueProcessId = prc.ppid;
666 #else // All Other
667 #endif // End ALL OS
668 }
669 if ( info ) *info = *vb;
670 return status;
671 }
System::ProcessBasicInformation
Definition: ProcessDescriptor.cpp:21
linux_proc::flags
unsigned long flags
Definition: ProcessDescriptor.cpp:269
linux_proc
Definition: ProcessDescriptor.cpp:260
readProcStat
void readProcStat(long pid, linux_proc &pinfo)
Definition: ProcessDescriptor.cpp:303
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
linux_proc::priority
long priority
Definition: ProcessDescriptor.cpp:278
linux_proc::startcode
unsigned long startcode
Definition: ProcessDescriptor.cpp:286
System::PPEB
struct _PEB * PPEB
Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.
Definition: ProcessDescriptor.h:17
linux_proc::ppid
int ppid
Definition: ProcessDescriptor.cpp:264
System::ProcessDescriptor::m_PROCESS_BASIC_INFORMATION
PROCESS_BASIC_INFORMATION m_PROCESS_BASIC_INFORMATION[2]
Definition: ProcessDescriptor.h:129
System::ProcessBasics
Definition: SystemBase.h:21
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32

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

Definition at line 468 of file ProcessDescriptor.cpp.

470 {
471 long status = 1;
472 ProcessHandle h(pid);
473 POOLED_USAGE_AND_LIMITS* vb = &m_POOLED_USAGE_AND_LIMITS[h.item()];
474 if ( fetch == Quota ) {
475 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
476 status = NtApi::NtQueryInformationProcess(h.handle(),
477 ProcessPooledUsageAndLimits,
478 vb,
479 sizeof(POOLED_USAGE_AND_LIMITS),
480 0);
481 status = (status==0) ? 1 : 0;
482 #elif defined(_WIN32) // Windows 95,98...
483 #elif defined(__linux) // Linux
484 //rusage usage;
485 //getrusage(RUSAGE_SELF, &usage);
486 rlimit lim;
487
488 getrlimit(RLIMIT_DATA, &lim);
489 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
490 vb->PeakPagedPoolUsage = lim.rlim_cur;
491 vb->PagedPoolUsage = lim.rlim_cur;
492 vb->PagedPoolLimit = lim.rlim_max;
493
494 getrlimit(RLIMIT_STACK, &lim);
495 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
496 vb->PeakNonPagedPoolUsage = lim.rlim_cur;
497 vb->NonPagedPoolUsage = lim.rlim_cur;
498 vb->NonPagedPoolLimit = lim.rlim_max;
499
500 linux_proc prc;
501 readProcStat(processID(pid), prc);
502 vb->PeakPagefileUsage = prc.rss * pg_size;
503 vb->PagefileUsage = prc.rss * pg_size;
504 vb->PagefileLimit = 0xFFFFFFFF;
505 #elif defined(__APPLE__)
506 #else // All Other
507 #endif // End ALL OS
508 }
509 if ( info ) *info = *vb;
510 return status;
511 }
linux_proc
Definition: ProcessDescriptor.cpp:260
readProcStat
void readProcStat(long pid, linux_proc &pinfo)
Definition: ProcessDescriptor.cpp:303
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
System::Quota
Definition: SystemBase.h:24
System::ProcessDescriptor::m_POOLED_USAGE_AND_LIMITS
POOLED_USAGE_AND_LIMITS m_POOLED_USAGE_AND_LIMITS[2]
Definition: ProcessDescriptor.h:127
linux_proc::rss
long rss
Definition: ProcessDescriptor.cpp:284
System::ProcessPooledUsageAndLimits
Definition: ProcessDescriptor.cpp:35
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32

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

Definition at line 673 of file ProcessDescriptor.cpp.

675 {
676 long status = 1;
677 ProcessHandle h(pid);
678 KERNEL_USER_TIMES* tb = &m_KERNEL_USER_TIMES[h.item()];;
679 if ( fetch == Times ) {
680 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
681 status = NtApi::NtQueryInformationProcess(h.handle(),
682 ProcessTimes,
683 tb,
684 sizeof(KERNEL_USER_TIMES),
685 0);
686 status = (status==0) ? 1 : 0;
687 #elif defined(_WIN32) // Windows 95,98...
688 #elif defined(__linux) // Linux
689 // prc.startup is in ticks since system start :
690 // need to offset for absolute time
691 tms tmsb;
692 static longlong prc_start = 0;
693 // static longlong offset = 100*longlong(time(0)) - longlong(times(0));
694 static longlong offset = 100*longlong(time(nullptr)) - longlong(times(&tmsb));
695 if ( processID(pid) == s_myPid && prc_start == 0 ) {
696 linux_proc prc;
697 readProcStat( processID(pid), prc);
698 prc_start = prc.starttime+offset;
699 }
700
701 if ( processID(pid) == s_myPid ) {
702 struct rusage r;
703 getrusage( RUSAGE_SELF, &r );
704 tb->UserTime = (static_cast<long long>(r.ru_utime.tv_sec) * 1000000 +
705 r.ru_utime.tv_usec) * 10;
706 tb->KernelTime = (static_cast<long long>(r.ru_stime.tv_sec) * 1000000 +
707 r.ru_stime.tv_usec) * 10;
708 tb->CreateTime = prc_start;
709 }
710 else {
711 linux_proc prc;
712 readProcStat( processID(pid), prc );
713
714 tms t;
715 times(&t);
716 tb->UserTime = t.tms_utime * TICK_TO_100NSEC;
717 tb->KernelTime = t.tms_stime * TICK_TO_100NSEC;
718 tb->CreateTime = (prc.starttime+offset);
719 }
720 tb->CreateTime *= TICK_TO_100NSEC;
721 tb->ExitTime = 0;
722
723 status = 1;
724
725 #elif defined(__APPLE__)
726 // FIXME (MCl): Make an alternative function get timing on OSX
727 // times() seems to cause a segmentation fault
728 #else // no /proc file system: assume sys_start for the first call
729 tms tmsb;
730 static clock_t sys_start = times(0);
731 static longlong offset = 100*longlong(time(0)) - sys_start;
732 clock_t now = times(&tmsb);
733 tb->CreateTime = offset + now;
734 tb->UserTime = tmsb.tms_utime;
735 tb->KernelTime = tmsb.tms_stime;
736 tb->CreateTime *= TICK_TO_100NSEC;
737 tb->UserTime *= TICK_TO_100NSEC;
738 tb->KernelTime *= TICK_TO_100NSEC;
739 tb->ExitTime = 0;
740 status = 1;
741 #endif
742 }
743 if ( info ) *info = *tb;
744 return status;
745 }
plotSpeedupsPyRoot.time
tuple time
Definition: plotSpeedupsPyRoot.py:146
System::Times
Definition: SystemBase.h:20
linux_proc
Definition: ProcessDescriptor.cpp:260
System::ProcessDescriptor::m_KERNEL_USER_TIMES
KERNEL_USER_TIMES m_KERNEL_USER_TIMES[2]
Definition: ProcessDescriptor.h:126
readProcStat
void readProcStat(long pid, linux_proc &pinfo)
Definition: ProcessDescriptor.cpp:303
__longlong
Definition: Kernel.h:56
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
linux_proc::starttime
unsigned long long starttime
Definition: ProcessDescriptor.cpp:282
System::ProcessTimes
Definition: ProcessDescriptor.cpp:25
s_myPid
#define s_myPid
Definition: ProcessDescriptor.cpp:373
longlong
__longlong longlong
Definition: Kernel.h:57
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32

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

Definition at line 591 of file ProcessDescriptor.cpp.

593 {
594 long status = 1;
595 ProcessHandle h(pid);
596 QUOTA_LIMITS* vb = &m_QUOTA_LIMITS[h.item()];
597 if ( fetch == Quota ) {
598 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
599 status = NtApi::NtQueryInformationProcess(h.handle(),
600 ProcessQuotaLimits,
601 vb,
602 sizeof(QUOTA_LIMITS),
603 0);
604 status = (status==0) ? 1 : 0;
605 #elif defined(_WIN32) // Windows 95,98...
606 #elif defined(__linux) // Linux
607 // On linux all this stuff typically is not set
608 // (ie. rlim_max=RLIM_INFINITY...)
609 rlimit lim;
610 getrlimit(RLIMIT_DATA, &lim);
611 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
612 vb->PagedPoolLimit = lim.rlim_max;
613
614 getrlimit(RLIMIT_STACK, &lim);
615 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
616 vb->NonPagedPoolLimit = lim.rlim_max;
617 vb->MinimumWorkingSetSize = 0;
618
619 getrlimit(RLIMIT_RSS, &lim);
620 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
621 vb->MaximumWorkingSetSize = lim.rlim_max;
622
623 getrlimit(RLIMIT_AS, &lim);
624 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
625 vb->PagefileLimit = lim.rlim_max;
626
627 getrlimit(RLIMIT_CPU, &lim);
628 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
629 vb->TimeLimit = lim.rlim_max;
630 #elif defined(__APPLE__)
631 #else // All Other
632 #endif // End ALL OS
633 }
634 if ( info ) *info = *vb;
635 return status;
636 }
System::ProcessDescriptor::m_QUOTA_LIMITS
QUOTA_LIMITS m_QUOTA_LIMITS[2]
Definition: ProcessDescriptor.h:128
System::ProcessQuotaLimits
Definition: ProcessDescriptor.cpp:22
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
System::Quota
Definition: SystemBase.h:24
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32

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

Definition at line 543 of file ProcessDescriptor.cpp.

545 {
546 long status = 1;
547 ProcessHandle h(pid);
548 VM_COUNTERS* vb = &m_VM_COUNTERS[h.item()];
549 if ( fetch == Memory ) {
550 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
551 status = NtApi::NtQueryInformationProcess(h.handle(),
552 ProcessVmCounters,
553 vb,
554 sizeof(VM_COUNTERS),
555 0);
556 status = (status==0) ? 1 : 0;
557 #elif defined(_WIN32) // Windows 95,98...
558 #elif defined(__linux) // Linux
559 const ssize_t bufsize = 1024;
560 char buf[bufsize];
561 sprintf(buf,"/proc/%ld/statm", processID(pid));
562 long size, resident, share, trs, lrs, drs, dt;
563 int fd = open(buf,O_RDONLY);
564 ssize_t nread = read(fd, buf, bufsize);
565 close(fd);
566 if ( nread < bufsize && nread >= 0 )
567 buf[nread]='\0';
568 fd = sscanf(buf, "%ld %ld %ld %ld %ld %ld %ld",
569 &size, &resident, &share, &trs, &drs, &lrs, &dt);
570 linux_proc prc;
571 readProcStat( processID(pid), prc);
572 vb->PeakVirtualSize = prc.vsize;
573 vb->VirtualSize = prc.vsize;
574 vb->PeakWorkingSetSize = resident * pg_size;
575 vb->WorkingSetSize = resident * pg_size;
576 vb->QuotaPeakPagedPoolUsage = share * pg_size;
577 vb->QuotaPagedPoolUsage = share * pg_size;
578 vb->QuotaNonPagedPoolUsage = (trs+drs)* pg_size;// drs = data/stack size
579 vb->QuotaPeakNonPagedPoolUsage = (trs+drs)* pg_size;// trs = VmExe size
580 vb->PageFaultCount = prc.majflt + prc.minflt;
581 vb->PagefileUsage = prc.vsize-resident*pg_size;
582 vb->PeakPagefileUsage = prc.vsize-resident*pg_size;
583 #elif defined(__APPLE__)
584 #else // All Other
585 #endif // End ALL OS
586 }
587 if ( info ) *info = *vb;
588 return status;
589 }
linux_proc::minflt
unsigned long minflt
Definition: ProcessDescriptor.cpp:270
System::Memory
Definition: SystemBase.h:23
std::sscanf
T sscanf(T...args)
linux_proc
Definition: ProcessDescriptor.cpp:260
readProcStat
void readProcStat(long pid, linux_proc &pinfo)
Definition: ProcessDescriptor.cpp:303
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
linux_proc::vsize
unsigned long vsize
Definition: ProcessDescriptor.cpp:283
linux_proc::majflt
unsigned long majflt
Definition: ProcessDescriptor.cpp:272
std::sprintf
T sprintf(T...args)
System::ProcessDescriptor::m_VM_COUNTERS
VM_COUNTERS m_VM_COUNTERS[2]
Definition: ProcessDescriptor.h:125
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
System::ProcessVmCounters
Definition: ProcessDescriptor.cpp:24

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

Definition at line 435 of file ProcessDescriptor.cpp.

437 {
438 long status = 1;
439 ProcessHandle h(pid);
440 IO_COUNTERS* vb = &m_IO_COUNTERS[h.item()];
441 if ( fetch == IO ) {
442 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
443 status = NtApi::NtQueryInformationProcess(h.handle(),
444 ProcessIoCounters,
445 vb,
446 sizeof(IO_COUNTERS),
447 0);
448 status = (status==0) ? 1 : 0;
449 #elif defined(_WIN32) // Windows 95,98...
450 #elif defined(__linux)
451 linux_proc prc;
452 readProcStat(processID(pid), prc);
453 rusage usage;
454 getrusage(RUSAGE_SELF, &usage);
455 vb->ReadOperationCount = usage.ru_inblock;
456 vb->WriteOperationCount = usage.ru_oublock;
457 vb->OtherOperationCount = 0;
458 vb->ReadTransferCount = usage.ru_inblock;
459 vb->WriteTransferCount = usage.ru_oublock;
460 vb->OtherTransferCount = 0;
461 #else // All Other
462 #endif // End ALL OS
463 }
464 if ( info ) *info = *vb;
465 return status;
466 }
linux_proc
Definition: ProcessDescriptor.cpp:260
usage
void usage(std::string argv0)
Definition: listcomponents.cpp:38
System::ProcessIoCounters
Definition: ProcessDescriptor.cpp:23
readProcStat
void readProcStat(long pid, linux_proc &pinfo)
Definition: ProcessDescriptor.cpp:303
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
System::ProcessDescriptor::m_IO_COUNTERS
IO_COUNTERS m_IO_COUNTERS[2]
Definition: ProcessDescriptor.h:124
System::IO
Definition: SystemBase.h:27
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32

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

Definition at line 513 of file ProcessDescriptor.cpp.

513 {
514 long status = 1, *vb = &status;
515 ProcessHandle h(pid);
516 vb = &m_PRIORITYBOOST[h.item()];
517 *vb = 0;
518 switch ( fetch ) {
519 case PriorityBoost:
520 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
521 status = NtApi::NtQueryInformationProcess(h.handle(),
522 ProcessPriorityBoost,
523 vb,
524 sizeof(long),
525 0);
526 #elif defined(_WIN32) // Windows 95,98...
527 #else
528 // Not applicable
529 status = 0;
530 *vb = 0;
531 #endif // End ALL OS
532 status = (status==0) ? 1 : 0;
533 break;
534 default:
535 status = -1;
536 vb = &status;
537 break;
538 }
539 if ( info ) *info = *vb;
540 return status;
541 }
System::ProcessDescriptor::m_PRIORITYBOOST
long m_PRIORITYBOOST[2]
Definition: ProcessDescriptor.h:123
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
System::ProcessPriorityBoost
Definition: ProcessDescriptor.cpp:43
System::PriorityBoost
Definition: SystemBase.h:22
System::ProcessHandle
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32

## Member Data Documentation

IO_COUNTERS System::ProcessDescriptor::m_IO_COUNTERS[2]
| private

Definition at line 124 of file ProcessDescriptor.h.

KERNEL_USER_TIMES System::ProcessDescriptor::m_KERNEL_USER_TIMES[2]
| private

Definition at line 126 of file ProcessDescriptor.h.

POOLED_USAGE_AND_LIMITS System::ProcessDescriptor::m_POOLED_USAGE_AND_LIMITS[2]
| private

Definition at line 127 of file ProcessDescriptor.h.

long System::ProcessDescriptor::m_PRIORITYBOOST[2]
| private

Definition at line 123 of file ProcessDescriptor.h.

PROCESS_BASIC_INFORMATION System::ProcessDescriptor::m_PROCESS_BASIC_INFORMATION[2]
| private

Definition at line 129 of file ProcessDescriptor.h.

QUOTA_LIMITS System::ProcessDescriptor::m_QUOTA_LIMITS[2]
| private

Definition at line 128 of file ProcessDescriptor.h.

VM_COUNTERS System::ProcessDescriptor::m_VM_COUNTERS[2]
| private

Definition at line 125 of file ProcessDescriptor.h.

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

- GaudiKernel/src/Lib/ProcessDescriptor.h
- GaudiKernel/src/Lib/ProcessDescriptor.cpp