| # Gaudi Framework, version v22r0 |

Home |  | Generated: 9 Feb 2011

# System::ProcessDescriptor Class Reference

Provides access to process information. More...

`#include <ProcessDescriptor.h>`

Collaboration diagram for System::ProcessDescriptor:
[legend]

List of all members.

## 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 110 of file ProcessDescriptor.h.

## Constructor & Destructor Documentation

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

Definition at line 258 of file ProcessDescriptor.cpp.

    00259 {
    00260 }

System::ProcessDescriptor::~ProcessDescriptor | ( |  | ) | `[virtual]`

Definition at line 262 of file ProcessDescriptor.cpp.

    00262                                               {
    00263 }

## Member Function Documentation

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

Definition at line 343 of file ProcessDescriptor.cpp.

    00343                                                                            {
    00344   long status = 1, *vb = &status;
    00345   ProcessHandle h(pid);
    00346   vb = &m_PRIORITYBOOST[h.item()];
    00347   *vb = 0;
    00348   switch ( fetch )    {
    00349   case PriorityBoost:
    00350 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00351     status = NtApi::NtQueryInformationProcess(h.handle(),
    00352                                               ProcessPriorityBoost,
    00353                                               vb,
    00354                                               sizeof(long),
    00355                                               0);
    00356 #elif defined(_WIN32)                     // Windows 95,98...
    00357 #else
    00358     // Not applicable
    00359     status = 0;
    00360     *vb = 0;
    00361 #endif                                    // End ALL OS
    00362     status = (status==0) ? 1 : 0;
    00363     break;
    00364   default:
    00365     status = -1;
    00366     vb = &status;
    00367     break;
    00368   }
    00369   if ( info ) *info = *vb;
    00370   return status;
    00371 }

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

Definition at line 265 of file ProcessDescriptor.cpp.

    00267                                                          {
    00268   long status = 1;
    00269   ProcessHandle h(pid);
    00270   IO_COUNTERS* vb = &m_IO_COUNTERS[h.item()];
    00271   if ( fetch == IO )   {
    00272 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00273     status = NtApi::NtQueryInformationProcess(h.handle(),
    00274                                               ProcessIoCounters,
    00275                                               vb,
    00276                                               sizeof(IO_COUNTERS),
    00277                                               0);
    00278     status = (status==0) ? 1 : 0;
    00279 #elif defined(_WIN32)                     // Windows 95,98...
    00280 #elif defined(linux)
    00281     linux_proc prc;
    00282     readProcStat(processID(pid), prc);
    00283     rusage usage;
    00284     getrusage(RUSAGE_SELF, &usage);
    00285     vb->ReadOperationCount    = usage.ru_inblock;
    00286     vb->WriteOperationCount   = usage.ru_oublock;
    00287     vb->OtherOperationCount   = 0;
    00288     vb->ReadTransferCount     = usage.ru_inblock;
    00289     vb->WriteTransferCount    = usage.ru_oublock;
    00290     vb->OtherTransferCount    = 0;
    00291 #else                                     // All Other
    00292 #endif                                    // End ALL OS
    00293   }
    00294   if ( info ) *info = *vb;
    00295   return status;
    00296 }

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

Definition at line 373 of file ProcessDescriptor.cpp.

    00375                                                             {
    00376   long status = 1;
    00377   ProcessHandle h(pid);
    00378   VM_COUNTERS* vb = &m_VM_COUNTERS[h.item()];
    00379   if ( fetch == Memory )   {
    00380 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00381     status = NtApi::NtQueryInformationProcess(h.handle(),
    00382                                               ProcessVmCounters,
    00383                                               vb,
    00384                                               sizeof(VM_COUNTERS),
    00385                                               0);
    00386     status = (status==0) ? 1 : 0;
    00387 #elif defined(_WIN32)                     // Windows 95,98...
    00388 #elif defined(linux)                      // Linux
    00389     const ssize_t bufsize = 1024;
    00390     char buf[bufsize];
    00391     sprintf(buf,"/proc/%ld/statm", processID(pid));
    00392     long size, resident, share, trs, lrs, drs, dt;
    00393     int fd = open(buf,O_RDONLY);
    00394     ssize_t nread = read(fd, buf, bufsize);
    00395     close(fd);
    00396     if ( nread < bufsize && nread >= 0 )
    00397       buf[nread]='\0';
    00398     fd = sscanf(buf, "%ld %ld %ld %ld %ld %ld %ld",
    00399                      &size, &resident, &share, &trs, &drs, &lrs, &dt);
    00400     linux_proc prc;
    00401     readProcStat( processID(pid), prc);
    00402     vb->PeakVirtualSize            = prc.vsize;
    00403     vb->VirtualSize                = prc.vsize;
    00404     vb->PeakWorkingSetSize         = resident * pg_size;
    00405     vb->WorkingSetSize             = resident * pg_size;
    00406     vb->QuotaPeakPagedPoolUsage    = share    * pg_size;
    00407     vb->QuotaPagedPoolUsage        = share    * pg_size;
    00408     vb->QuotaNonPagedPoolUsage     = (trs+drs)* pg_size;// drs = data/stack size
    00409     vb->QuotaPeakNonPagedPoolUsage = (trs+drs)* pg_size;// trs = VmExe size
    00410     vb->PageFaultCount             = prc.majflt + prc.minflt;
    00411     vb->PagefileUsage              = prc.vsize-resident*pg_size;
    00412     vb->PeakPagefileUsage          = prc.vsize-resident*pg_size;
    00413 #elif defined(__APPLE__)
    00414 #else                                     // All Other
    00415 #endif                                    // End ALL OS
    00416   }
    00417   if ( info ) *info = *vb;
    00418   return status;
    00419 }

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

Definition at line 421 of file ProcessDescriptor.cpp.

    00423                                                              {
    00424   long status = 1;
    00425   ProcessHandle h(pid);
    00426   QUOTA_LIMITS* vb = &m_QUOTA_LIMITS[h.item()];
    00427   if ( fetch == Quota )   {
    00428 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00429     status = NtApi::NtQueryInformationProcess(h.handle(),
    00430                                               ProcessQuotaLimits,
    00431                                               vb,
    00432                                               sizeof(QUOTA_LIMITS),
    00433                                               0);
    00434     status = (status==0) ? 1 : 0;
    00435 #elif defined(_WIN32)                     // Windows 95,98...
    00436 #elif defined(linux)                      // Linux
    00437     // On linux all this stuff typically is not set
    00438     // (ie. rlim_max=RLIM_INFINITY...)
    00439     rlimit lim;
    00440     getrlimit(RLIMIT_DATA, &lim);
    00441     if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
    00442     vb->PagedPoolLimit        = lim.rlim_max;
    00443
    00444     getrlimit(RLIMIT_STACK, &lim);
    00445     if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
    00446     vb->NonPagedPoolLimit     = lim.rlim_max;
    00447     vb->MinimumWorkingSetSize = 0;
    00448
    00449     getrlimit(RLIMIT_RSS, &lim);
    00450     if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
    00451     vb->MaximumWorkingSetSize = lim.rlim_max;
    00452
    00453     getrlimit(RLIMIT_AS, &lim);
    00454     if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
    00455     vb->PagefileLimit         = lim.rlim_max;
    00456
    00457     getrlimit(RLIMIT_CPU, &lim);
    00458     if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
    00459     vb->TimeLimit             = lim.rlim_max;
    00460 #elif defined(__APPLE__)
    00461 #else                                     // All Other
    00462 #endif                                    // End ALL OS
    00463   }
    00464   if ( info ) *info = *vb;
    00465   return status;
    00466 }

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

Definition at line 503 of file ProcessDescriptor.cpp.

    00505                                                                  {
    00506   long status = 1;
    00507   ProcessHandle h(pid);
    00508   KERNEL_USER_TIMES* tb = &m_KERNEL_USER_TIMES[h.item()];;
    00509   if ( fetch == Times )   {
    00510 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00511     status = NtApi::NtQueryInformationProcess(h.handle(),
    00512                                               ProcessTimes,
    00513                                               tb,
    00514                                               sizeof(KERNEL_USER_TIMES),
    00515                                               0);
    00516     status = (status==0) ? 1 : 0;
    00517 #elif defined(_WIN32)                     // Windows 95,98...
    00518 #elif defined(linux)                      // Linux
    00519     // prc.startup is in ticks since system start :
    00520     // need to offset for absolute time
    00521     tms tmsb;
    00522     static longlong prc_start = 0;
    00523     //    static longlong offset = 100*longlong(time(0)) - longlong(times(0));
    00524     static longlong offset = 100*longlong(time(0)) - longlong(times(&tmsb));
    00525     if ( processID(pid) == s_myPid && prc_start == 0 ) {
    00526       linux_proc prc;
    00527       readProcStat( processID(pid), prc);
    00528       prc_start = prc.starttime+offset;
    00529     }
    00530
    00531     if ( processID(pid) == s_myPid ) {
    00532       struct rusage r;
    00533       getrusage( RUSAGE_SELF, &r );
    00534       tb->UserTime   = (static_cast<long long>(r.ru_utime.tv_sec) * 1000000 +
    00535                         r.ru_utime.tv_usec) * 10;
    00536       tb->KernelTime = (static_cast<long long>(r.ru_stime.tv_sec) * 1000000 +
    00537                         r.ru_stime.tv_usec) * 10;
    00538       tb->CreateTime = prc_start;
    00539     }
    00540     else {
    00541       linux_proc prc;
    00542       readProcStat( processID(pid), prc );
    00543
    00544       tms t;
    00545       times(&t);
    00546       tb->UserTime   = t.tms_utime * TICK_TO_100NSEC;
    00547       tb->KernelTime = t.tms_stime * TICK_TO_100NSEC;
    00548       tb->CreateTime = (prc.starttime+offset);
    00549     }
    00550     tb->CreateTime *= TICK_TO_100NSEC;
    00551     tb->ExitTime    = 0;
    00552
    00553     status = 1;
    00554
    00555 #elif defined(__APPLE__)
    00556     // FIXME (MCl): Make an alternative function get timing on OSX
    00557     // times() seems to cause a segmentation fault
    00558 #else  // no /proc file system: assume sys_start for the first call
    00559     tms tmsb;
    00560     static clock_t sys_start = times(0);
    00561     static longlong offset = 100*longlong(time(0)) - sys_start;
    00562     clock_t now = times(&tmsb);
    00563     tb->CreateTime    = offset + now;
    00564     tb->UserTime      = tmsb.tms_utime;
    00565     tb->KernelTime    = tmsb.tms_stime;
    00566     tb->CreateTime   *= TICK_TO_100NSEC;
    00567     tb->UserTime     *= TICK_TO_100NSEC;
    00568     tb->KernelTime   *= TICK_TO_100NSEC;
    00569     tb->ExitTime      = 0;
    00570     status = 1;
    00571 #endif
    00572   }
    00573   if ( info ) *info = *tb;
    00574   return status;
    00575 }

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

Definition at line 298 of file ProcessDescriptor.cpp.

    00300                                                                         {
    00301   long status = 1;
    00302   ProcessHandle h(pid);
    00303   POOLED_USAGE_AND_LIMITS* vb = &m_POOLED_USAGE_AND_LIMITS[h.item()];
    00304   if ( fetch == Quota )   {
    00305 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00306     status = NtApi::NtQueryInformationProcess(h.handle(),
    00307                                               ProcessPooledUsageAndLimits,
    00308                                               vb,
    00309                                               sizeof(POOLED_USAGE_AND_LIMITS),
    00310                                               0);
    00311     status = (status==0) ? 1 : 0;
    00312 #elif defined(_WIN32)                     // Windows 95,98...
    00313 #elif defined(linux)                      // Linux
    00314     //rusage usage;
    00315     //getrusage(RUSAGE_SELF, &usage);
    00316     rlimit lim;
    00317
    00318     getrlimit(RLIMIT_DATA, &lim);
    00319     if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
    00320     vb->PeakPagedPoolUsage = lim.rlim_cur;
    00321     vb->PagedPoolUsage     = lim.rlim_cur;
    00322     vb->PagedPoolLimit     = lim.rlim_max;
    00323
    00324     getrlimit(RLIMIT_STACK, &lim);
    00325     if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
    00326     vb->PeakNonPagedPoolUsage = lim.rlim_cur;
    00327     vb->NonPagedPoolUsage     = lim.rlim_cur;
    00328     vb->NonPagedPoolLimit     = lim.rlim_max;
    00329
    00330     linux_proc prc;
    00331     readProcStat(processID(pid), prc);
    00332     vb->PeakPagefileUsage     = prc.rss * pg_size;
    00333     vb->PagefileUsage         = prc.rss * pg_size;
    00334     vb->PagefileLimit         = 0xFFFFFFFF;
    00335 #elif defined(__APPLE__)
    00336 #else                                     // All Other
    00337 #endif                                    // End ALL OS
    00338   }
    00339   if ( info ) *info = *vb;
    00340   return status;
    00341 }

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

Definition at line 468 of file ProcessDescriptor.cpp.

    00470                                                                           {
    00471   long status = 1;
    00472   ProcessHandle h(pid);
    00473   PROCESS_BASIC_INFORMATION* vb = &m_PROCESS_BASIC_INFORMATION[h.item()];
    00474   if ( fetch == ProcessBasics )   {
    00475 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00476     status = NtApi::NtQueryInformationProcess(h.handle(),
    00477                                               ProcessBasicInformation,
    00478                                               vb,
    00479                                               sizeof(PROCESS_BASIC_INFORMATION),
    00480                                               0);
    00481     status = (status==0) ? 1 : 0;
    00482 #elif defined(_WIN32)                     // Windows 95,98...
    00483 #elif defined(linux)                      // Linux
    00484     linux_proc prc;
    00485     readProcStat( processID(pid), prc);
    00486     vb->ExitStatus                   = 0;
    00487     vb->PebBaseAddress               = (PPEB)prc.startcode;
    00488     vb->BasePriority                 = 2*15-prc.priority;
    00489     // std::cout << "Base Priority=" << vb->BasePriority << "|"
    00490     // << prc.priority << std::endl;
    00491     vb->AffinityMask                 = prc.flags;
    00492     // std::cout << "Flags        =" << vb->AffinityMask << "|"
    00493     // << prc.flags << std::endl;
    00494     vb->UniqueProcessId              = processID(pid);
    00495     vb->InheritedFromUniqueProcessId = prc.ppid;
    00496 #else                                     // All Other
    00497 #endif                                    // End ALL OS
    00498   }
    00499   if ( info ) *info = *vb;
    00500   return status;
    00501 }

## Member Data Documentation

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

Definition at line 125 of file ProcessDescriptor.h.

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

Definition at line 127 of file ProcessDescriptor.h.

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

Definition at line 128 of file ProcessDescriptor.h.

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

Definition at line 124 of file ProcessDescriptor.h.

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

Definition at line 130 of file ProcessDescriptor.h.

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

Definition at line 129 of file ProcessDescriptor.h.

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

Definition at line 126 of file ProcessDescriptor.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r0/GaudiKernel/src/Lib/ProcessDescriptor.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r0/GaudiKernel/src/Lib/ProcessDescriptor.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines