| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# System::ProcessDescriptor Class Reference

Provides access to process information. More...

`#include <ProcessDescriptor.h>`

Collaboration diagram for System::ProcessDescriptor:

[legend]

List of all members.

## 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]
## Classes
class | ProcessHandle

## 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 256 of file ProcessDescriptor.cpp.

    00257 {
    00258 }

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

Definition at line 260 of file ProcessDescriptor.cpp.

    00260                                               {
    00261 }

## Member Function Documentation

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

Definition at line 466 of file ProcessDescriptor.cpp.

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

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

Definition at line 296 of file ProcessDescriptor.cpp.

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

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

Definition at line 501 of file ProcessDescriptor.cpp.

    00503                                                                  {
    00504   long status = 1;
    00505   ProcessHandle h(pid);
    00506   KERNEL_USER_TIMES* tb = &m_KERNEL_USER_TIMES[h.item()];;
    00507   if ( fetch == Times )   {
    00508 #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
    00509     status = NtApi::NtQueryInformationProcess(h.handle(),
    00510                                               ProcessTimes,
    00511                                               tb,
    00512                                               sizeof(KERNEL_USER_TIMES),
    00513                                               0);
    00514     status = (status==0) ? 1 : 0;
    00515 #elif defined(_WIN32)                     // Windows 95,98...
    00516 #elif defined(linux)                      // Linux
    00517     // prc.startup is in ticks since system start :
    00518     // need to offset for absolute time
    00519     tms tmsb;
    00520     static longlong prc_start = 0;
    00521     //    static longlong offset = 100*longlong(time(0)) - longlong(times(0));
    00522     static longlong offset = 100*longlong(time(0)) - longlong(times(&tmsb));
    00523     if ( processID(pid) == s_myPid && prc_start == 0 ) {
    00524       linux_proc prc;
    00525       readProcStat( processID(pid), prc);
    00526       prc_start = prc.starttime+offset;
    00527     }
    00528
    00529     if ( processID(pid) == s_myPid ) {
    00530       struct rusage r;
    00531       getrusage( RUSAGE_SELF, &r );
    00532       const double utime = static_cast<double>(r.ru_utime.tv_sec )*1e6 +
    00533                            static_cast<double>(r.ru_utime.tv_usec);
    00534       const double stime = static_cast<double>(r.ru_stime.tv_sec )*1e6 +
    00535                            static_cast<double>(r.ru_stime.tv_usec);
    00536       tb->UserTime   = static_cast<longlong>( utime * 10. );
    00537       tb->KernelTime = static_cast<longlong>( stime * 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,
|  | QUOTA_LIMITS * | buffer |
| ) |  |  |

Definition at line 419 of file ProcessDescriptor.cpp.

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

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

Definition at line 371 of file ProcessDescriptor.cpp.

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

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

Definition at line 263 of file ProcessDescriptor.cpp.

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

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

Definition at line 341 of file ProcessDescriptor.cpp.

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

## Member Data Documentation

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

Definition at line 124 of file ProcessDescriptor.h.

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

Definition at line 125 of file ProcessDescriptor.h.

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

Definition at line 126 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.

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

Definition at line 129 of file ProcessDescriptor.h.

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

Definition at line 130 of file ProcessDescriptor.h.

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

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