#include </builds/gaudi/Gaudi/GaudiKernel/src/Lib/ProcessDescriptor.h>
|
| | ProcessDescriptor () |
| |
| virtual | ~ProcessDescriptor () |
| |
| 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) |
| |
Provides access to process information
- Author
- M.Frank
-
Sebastien Ponce
Definition at line 117 of file ProcessDescriptor.h.
◆ ProcessDescriptor()
| System::ProcessDescriptor::ProcessDescriptor |
( |
| ) |
|
Definition at line 374 of file ProcessDescriptor.cpp.
376 static bool first =
true;
379 void* mh = ::LoadLibrary(
"NTDll.dll" );
381 NtApi::NtQueryInformationProcess =
382 ( NtApi::__NtQueryInformationProcess )::GetProcAddress( (HINSTANCE)mh,
"NtQueryInformationProcess" );
◆ ~ProcessDescriptor()
| System::ProcessDescriptor::~ProcessDescriptor |
( |
| ) |
|
|
virtual |
◆ query() [1/7]
Definition at line 390 of file ProcessDescriptor.cpp.
391 if ( info == 0 )
return 0;
395 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
397 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessIoCounters, info,
sizeof( IO_COUNTERS ), 0 );
398 status = ( status == 0 ) ? 1 : 0;
399 #elif defined( _WIN32 ) // Windows 95,98...
400 #elif defined( __linux )
404 getrusage( RUSAGE_SELF, &
usage );
405 info->ReadOperationCount =
usage.ru_inblock;
406 info->WriteOperationCount =
usage.ru_oublock;
407 info->OtherOperationCount = 0;
408 info->ReadTransferCount =
usage.ru_inblock;
409 info->WriteTransferCount =
usage.ru_oublock;
410 info->OtherTransferCount = 0;
◆ query() [2/7]
Definition at line 610 of file ProcessDescriptor.cpp.
611 if ( info == 0 )
return 0;
615 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
617 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessTimes, info,
sizeof( KERNEL_USER_TIMES ), 0 );
618 status = ( status == 0 ) ? 1 : 0;
619 #elif defined( _WIN32 ) // Windows 95,98...
620 #elif defined( __linux ) // Linux
621 static long long prc_start = 0;
622 bool myself = pid <= 0 || pid == ::getpid();
623 if ( myself && prc_start == 0 ) {
628 static long long offset =
629 100 *
static_cast<long long>(
time(
nullptr ) ) -
static_cast<long long>( times( &tmsb ) );
630 prc_start = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
636 info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
637 info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
638 info->CreateTime = prc_start;
643 static long long offset =
644 100 *
static_cast<long long>(
time(
nullptr ) ) -
static_cast<long long>( times( &tmsb ) );
648 info->UserTime =
t.tms_utime * TICK_TO_100NSEC;
649 info->KernelTime =
t.tms_stime * TICK_TO_100NSEC;
650 info->CreateTime = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
656 #elif defined( __APPLE__ )
660 #else // no /proc file system: assume sys_start for the first call
662 static clock_t sys_start = times( 0 );
663 static long long offset = 100 *
long long(
time( 0 ) ) - sys_start;
664 clock_t now = times( &tmsb );
665 info->CreateTime = offset + now;
666 info->UserTime = tmsb.tms_utime;
667 info->KernelTime = tmsb.tms_stime;
668 info->CreateTime *= TICK_TO_100NSEC;
669 info->UserTime *= TICK_TO_100NSEC;
670 info->KernelTime *= TICK_TO_100NSEC;
◆ query() [3/7]
| long System::ProcessDescriptor::query |
( |
long |
pid, |
|
|
InfoType |
fetch, |
|
|
long * |
info |
|
) |
| |
Definition at line 461 of file ProcessDescriptor.cpp.
463 if ( info == 0 )
return 0;
468 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
470 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessPriorityBoost, info,
sizeof(
long ), 0 );
471 #elif defined( _WIN32 ) // Windows 95,98...
475 if ( pid > 0 ) status = 0;
479 status = ( status == 0 ) ? 1 : 0;
◆ query() [4/7]
Definition at line 418 of file ProcessDescriptor.cpp.
419 if ( info == 0 )
return 0;
423 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
426 sizeof( POOLED_USAGE_AND_LIMITS ), 0 );
427 status = ( status == 0 ) ? 1 : 0;
428 #elif defined( _WIN32 ) // Windows 95,98...
429 #elif defined( __linux ) // Linux
434 getrlimit( RLIMIT_DATA, &lim );
435 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
436 info->PeakPagedPoolUsage = lim.rlim_cur;
437 info->PagedPoolUsage = lim.rlim_cur;
438 info->PagedPoolLimit = lim.rlim_max;
440 getrlimit( RLIMIT_STACK, &lim );
441 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
442 info->PeakNonPagedPoolUsage = lim.rlim_cur;
443 info->NonPagedPoolUsage = lim.rlim_cur;
444 info->NonPagedPoolLimit = lim.rlim_max;
448 info->PeakPagefileUsage = prc.
rss * pg_size;
449 info->PagefileUsage = prc.
rss * pg_size;
450 info->PagefileLimit = 0xFFFFFFFF;
451 #elif defined( __APPLE__ )
◆ query() [5/7]
Definition at line 578 of file ProcessDescriptor.cpp.
579 if ( info == 0 )
return 0;
583 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
586 sizeof( PROCESS_BASIC_INFORMATION ), 0 );
587 status = ( status == 0 ) ? 1 : 0;
588 #elif defined( _WIN32 ) // Windows 95,98...
589 #elif defined( __linux ) // Linux
591 pid = processID( pid );
593 info->ExitStatus = 0;
595 info->BasePriority = 2 * 15 - prc.
priority;
598 info->AffinityMask = prc.
flags;
601 info->UniqueProcessId = pid;
602 info->InheritedFromUniqueProcessId = prc.
ppid;
◆ query() [6/7]
Definition at line 532 of file ProcessDescriptor.cpp.
533 if ( info == 0 )
return 0;
537 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
539 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessQuotaLimits, info,
sizeof( QUOTA_LIMITS ), 0 );
540 status = ( status == 0 ) ? 1 : 0;
541 #elif defined( _WIN32 ) // Windows 95,98...
542 #elif defined( __linux ) // Linux
546 if ( pid > 0 && pid != ::getpid() )
return 0;
549 getrlimit( RLIMIT_DATA, &lim );
550 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
551 info->PagedPoolLimit = lim.rlim_max;
553 getrlimit( RLIMIT_STACK, &lim );
554 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
555 info->NonPagedPoolLimit = lim.rlim_max;
556 info->MinimumWorkingSetSize = 0;
558 getrlimit( RLIMIT_RSS, &lim );
559 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
560 info->MaximumWorkingSetSize = lim.rlim_max;
562 getrlimit( RLIMIT_AS, &lim );
563 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
564 info->PagefileLimit = lim.rlim_max;
566 getrlimit( RLIMIT_CPU, &lim );
567 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
568 info->TimeLimit = lim.rlim_max;
569 #elif defined( __APPLE__ )
◆ query() [7/7]
Definition at line 489 of file ProcessDescriptor.cpp.
490 if ( info == 0 )
return 0;
494 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
496 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessVmCounters, info,
sizeof( VM_COUNTERS ), 0 );
497 status = ( status == 0 ) ? 1 : 0;
498 #elif defined( _WIN32 ) // Windows 95,98...
499 #elif defined( __linux ) // Linux
500 const ssize_t bufsize = 1024;
502 pid = processID( pid );
503 sprintf( buf,
"/proc/%ld/statm", pid );
504 long size, resident, share, trs, lrs, drs, dt;
505 int fd = open( buf, O_RDONLY );
506 ssize_t nread =
read(
fd, buf, bufsize );
508 if ( nread < bufsize && nread >= 0 ) buf[nread] =
'\0';
509 fd = sscanf( buf,
"%ld %ld %ld %ld %ld %ld %ld", &
size, &resident, &share, &trs, &drs, &lrs, &dt );
512 info->PeakVirtualSize = prc.
vsize;
513 info->VirtualSize = prc.
vsize;
514 info->PeakWorkingSetSize = resident * pg_size;
515 info->WorkingSetSize = resident * pg_size;
516 info->QuotaPeakPagedPoolUsage = share * pg_size;
517 info->QuotaPagedPoolUsage = share * pg_size;
518 info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size;
519 info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size;
521 info->PagefileUsage = prc.
vsize - resident * pg_size;
522 info->PeakPagefileUsage = prc.
vsize - resident * pg_size;
523 #elif defined( __APPLE__ )
The documentation for this class was generated from the following files: