| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

Classes | Public Member Functions | Private Attributes

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

    {
    }

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

Definition at line 430 of file ProcessDescriptor.cpp.

                                                  {
    }

## Member Function Documentation

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

Definition at line 636 of file ProcessDescriptor.cpp.

                                                                              {
      long status = 1;
      ProcessHandle h(pid);
      PROCESS_BASIC_INFORMATION* vb = &m_PROCESS_BASIC_INFORMATION[h.item()];
      if ( fetch == ProcessBasics )   {
    #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
        status = NtApi::NtQueryInformationProcess(h.handle(),
                                                  ProcessBasicInformation,
                                                  vb,
                                                  sizeof(PROCESS_BASIC_INFORMATION),
                                                  0);
        status = (status==0) ? 1 : 0;
    #elif defined(_WIN32)                     // Windows 95,98...
    #elif defined(linux)                      // Linux
        linux_proc prc;
        readProcStat( processID(pid), prc);
        vb->ExitStatus                   = 0;
        vb->PebBaseAddress               = (PPEB)prc.startcode;
        vb->BasePriority                 = 2*15-prc.priority;
        // std::cout << "Base Priority=" << vb->BasePriority << "|"
        // << prc.priority << std::endl;
        vb->AffinityMask                 = prc.flags;
        // std::cout << "Flags        =" << vb->AffinityMask << "|"
        // << prc.flags << std::endl;
        vb->UniqueProcessId              = processID(pid);
        vb->InheritedFromUniqueProcessId = prc.ppid;
    #else                                     // All Other
    #endif                                    // End ALL OS
      }
      if ( info ) *info = *vb;
      return status;
    }

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

Definition at line 511 of file ProcessDescriptor.cpp.

                                                                               {
      long status = 1, *vb = &status;
      ProcessHandle h(pid);
      vb = &m_PRIORITYBOOST[h.item()];
      *vb = 0;
      switch ( fetch )    {
      case PriorityBoost:
    #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
        status = NtApi::NtQueryInformationProcess(h.handle(),
                                                  ProcessPriorityBoost,
                                                  vb,
                                                  sizeof(long),
                                                  0);
    #elif defined(_WIN32)                     // Windows 95,98...
    #else
        // Not applicable
        status = 0;
        *vb = 0;
    #endif                                    // End ALL OS
        status = (status==0) ? 1 : 0;
        break;
      default:
        status = -1;
        vb = &status;
        break;
      }
      if ( info ) *info = *vb;
      return status;
    }

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

Definition at line 433 of file ProcessDescriptor.cpp.

                                                             {
      long status = 1;
      ProcessHandle h(pid);
      IO_COUNTERS* vb = &m_IO_COUNTERS[h.item()];
      if ( fetch == IO )   {
    #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
        status = NtApi::NtQueryInformationProcess(h.handle(),
                                                  ProcessIoCounters,
                                                  vb,
                                                  sizeof(IO_COUNTERS),
                                                  0);
        status = (status==0) ? 1 : 0;
    #elif defined(_WIN32)                     // Windows 95,98...
    #elif defined(linux)
        linux_proc prc;
        readProcStat(processID(pid), prc);
        rusage usage;
        getrusage(RUSAGE_SELF, &usage);
        vb->ReadOperationCount    = usage.ru_inblock;
        vb->WriteOperationCount   = usage.ru_oublock;
        vb->OtherOperationCount   = 0;
        vb->ReadTransferCount     = usage.ru_inblock;
        vb->WriteTransferCount    = usage.ru_oublock;
        vb->OtherTransferCount    = 0;
    #else                                     // All Other
    #endif                                    // End ALL OS
      }
      if ( info ) *info = *vb;
      return status;
    }

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

Definition at line 541 of file ProcessDescriptor.cpp.

                                                                {
      long status = 1;
      ProcessHandle h(pid);
      VM_COUNTERS* vb = &m_VM_COUNTERS[h.item()];
      if ( fetch == Memory )   {
    #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
        status = NtApi::NtQueryInformationProcess(h.handle(),
                                                  ProcessVmCounters,
                                                  vb,
                                                  sizeof(VM_COUNTERS),
                                                  0);
        status = (status==0) ? 1 : 0;
    #elif defined(_WIN32)                     // Windows 95,98...
    #elif defined(linux)                      // Linux
        const ssize_t bufsize = 1024;
        char buf[bufsize];
        sprintf(buf,"/proc/%ld/statm", processID(pid));
        long size, resident, share, trs, lrs, drs, dt;
        int fd = open(buf,O_RDONLY);
        ssize_t nread = read(fd, buf, bufsize);
        close(fd);
        if ( nread < bufsize && nread >= 0 )
          buf[nread]='\0';
        fd = sscanf(buf, "%ld %ld %ld %ld %ld %ld %ld",
                         &size, &resident, &share, &trs, &drs, &lrs, &dt);
        linux_proc prc;
        readProcStat( processID(pid), prc);
        vb->PeakVirtualSize            = prc.vsize;
        vb->VirtualSize                = prc.vsize;
        vb->PeakWorkingSetSize         = resident * pg_size;
        vb->WorkingSetSize             = resident * pg_size;
        vb->QuotaPeakPagedPoolUsage    = share    * pg_size;
        vb->QuotaPagedPoolUsage        = share    * pg_size;
        vb->QuotaNonPagedPoolUsage     = (trs+drs)* pg_size;// drs = data/stack size
        vb->QuotaPeakNonPagedPoolUsage = (trs+drs)* pg_size;// trs = VmExe size
        vb->PageFaultCount             = prc.majflt + prc.minflt;
        vb->PagefileUsage              = prc.vsize-resident*pg_size;
        vb->PeakPagefileUsage          = prc.vsize-resident*pg_size;
    #elif defined(__APPLE__)
    #else                                     // All Other
    #endif                                    // End ALL OS
      }
      if ( info ) *info = *vb;
      return status;
    }

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

Definition at line 589 of file ProcessDescriptor.cpp.

                                                                 {
      long status = 1;
      ProcessHandle h(pid);
      QUOTA_LIMITS* vb = &m_QUOTA_LIMITS[h.item()];
      if ( fetch == Quota )   {
    #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
        status = NtApi::NtQueryInformationProcess(h.handle(),
                                                  ProcessQuotaLimits,
                                                  vb,
                                                  sizeof(QUOTA_LIMITS),
                                                  0);
        status = (status==0) ? 1 : 0;
    #elif defined(_WIN32)                     // Windows 95,98...
    #elif defined(linux)                      // Linux
        // On linux all this stuff typically is not set
        // (ie. rlim_max=RLIM_INFINITY...)
        rlimit lim;
        getrlimit(RLIMIT_DATA, &lim);
        if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
        vb->PagedPoolLimit        = lim.rlim_max;

        getrlimit(RLIMIT_STACK, &lim);
        if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
        vb->NonPagedPoolLimit     = lim.rlim_max;
        vb->MinimumWorkingSetSize = 0;

        getrlimit(RLIMIT_RSS, &lim);
        if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
        vb->MaximumWorkingSetSize = lim.rlim_max;

        getrlimit(RLIMIT_AS, &lim);
        if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
        vb->PagefileLimit         = lim.rlim_max;

        getrlimit(RLIMIT_CPU, &lim);
        if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
        vb->TimeLimit             = lim.rlim_max;
    #elif defined(__APPLE__)
    #else                                     // All Other
    #endif                                    // End ALL OS
      }
      if ( info ) *info = *vb;
      return status;
    }

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

Definition at line 671 of file ProcessDescriptor.cpp.

                                                                     {
      long status = 1;
      ProcessHandle h(pid);
      KERNEL_USER_TIMES* tb = &m_KERNEL_USER_TIMES[h.item()];;
      if ( fetch == Times )   {
    #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
        status = NtApi::NtQueryInformationProcess(h.handle(),
                                                  ProcessTimes,
                                                  tb,
                                                  sizeof(KERNEL_USER_TIMES),
                                                  0);
        status = (status==0) ? 1 : 0;
    #elif defined(_WIN32)                     // Windows 95,98...
    #elif defined(linux)                      // Linux
        // prc.startup is in ticks since system start :
        // need to offset for absolute time
        tms tmsb;
        static longlong prc_start = 0;
        //    static longlong offset = 100*longlong(time(0)) - longlong(times(0));
        static longlong offset = 100*longlong(time(0)) - longlong(times(&tmsb));
        if ( processID(pid) == s_myPid && prc_start == 0 ) {
          linux_proc prc;
          readProcStat( processID(pid), prc);
          prc_start = prc.starttime+offset;
        }

        if ( processID(pid) == s_myPid ) {
          struct rusage r;
          getrusage( RUSAGE_SELF, &r );
          tb->UserTime   = (static_cast<long long>(r.ru_utime.tv_sec) * 1000000 +
                            r.ru_utime.tv_usec) * 10;
          tb->KernelTime = (static_cast<long long>(r.ru_stime.tv_sec) * 1000000 +
                            r.ru_stime.tv_usec) * 10;
          tb->CreateTime = prc_start;
        }
        else {
          linux_proc prc;
          readProcStat( processID(pid), prc );

          tms t;
          times(&t);
          tb->UserTime   = t.tms_utime * TICK_TO_100NSEC;
          tb->KernelTime = t.tms_stime * TICK_TO_100NSEC;
          tb->CreateTime = (prc.starttime+offset);
        }
        tb->CreateTime *= TICK_TO_100NSEC;
        tb->ExitTime    = 0;

        status = 1;

    #elif defined(__APPLE__)
        // FIXME (MCl): Make an alternative function get timing on OSX
        // times() seems to cause a segmentation fault
    #else  // no /proc file system: assume sys_start for the first call
        tms tmsb;
        static clock_t sys_start = times(0);
        static longlong offset = 100*longlong(time(0)) - sys_start;
        clock_t now = times(&tmsb);
        tb->CreateTime    = offset + now;
        tb->UserTime      = tmsb.tms_utime;
        tb->KernelTime    = tmsb.tms_stime;
        tb->CreateTime   *= TICK_TO_100NSEC;
        tb->UserTime     *= TICK_TO_100NSEC;
        tb->KernelTime   *= TICK_TO_100NSEC;
        tb->ExitTime      = 0;
        status = 1;
    #endif
      }
      if ( info ) *info = *tb;
      return status;
    }

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

Definition at line 466 of file ProcessDescriptor.cpp.

                                                                            {
      long status = 1;
      ProcessHandle h(pid);
      POOLED_USAGE_AND_LIMITS* vb = &m_POOLED_USAGE_AND_LIMITS[h.item()];
      if ( fetch == Quota )   {
    #if defined(_WIN32) && WINVER>=0x0400     // Windows NT
        status = NtApi::NtQueryInformationProcess(h.handle(),
                                                  ProcessPooledUsageAndLimits,
                                                  vb,
                                                  sizeof(POOLED_USAGE_AND_LIMITS),
                                                  0);
        status = (status==0) ? 1 : 0;
    #elif defined(_WIN32)                     // Windows 95,98...
    #elif defined(linux)                      // Linux
        //rusage usage;
        //getrusage(RUSAGE_SELF, &usage);
        rlimit lim;

        getrlimit(RLIMIT_DATA, &lim);
        if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
        vb->PeakPagedPoolUsage = lim.rlim_cur;
        vb->PagedPoolUsage     = lim.rlim_cur;
        vb->PagedPoolLimit     = lim.rlim_max;

        getrlimit(RLIMIT_STACK, &lim);
        if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
        vb->PeakNonPagedPoolUsage = lim.rlim_cur;
        vb->NonPagedPoolUsage     = lim.rlim_cur;
        vb->NonPagedPoolLimit     = lim.rlim_max;

        linux_proc prc;
        readProcStat(processID(pid), prc);
        vb->PeakPagefileUsage     = prc.rss * pg_size;
        vb->PagefileUsage         = prc.rss * pg_size;
        vb->PagefileLimit         = 0xFFFFFFFF;
    #elif defined(__APPLE__)
    #else                                     // All Other
    #endif                                    // End ALL OS
      }
      if ( info ) *info = *vb;
      return status;
    }

## 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_v22r2/GaudiKernel/src/Lib/ProcessDescriptor.h
- /afs/.cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r2/GaudiKernel/src/Lib/ProcessDescriptor.cpp

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