#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 118 of file ProcessDescriptor.h.
◆ ProcessDescriptor()
System::ProcessDescriptor::ProcessDescriptor |
( |
| ) |
|
Definition at line 391 of file ProcessDescriptor.cpp.
393 static bool first =
true;
396 void* mh = ::LoadLibrary(
"NTDll.dll" );
398 NtApi::NtQueryInformationProcess =
399 ( NtApi::__NtQueryInformationProcess )::GetProcAddress( (HINSTANCE)mh,
"NtQueryInformationProcess" );
◆ ~ProcessDescriptor()
System::ProcessDescriptor::~ProcessDescriptor |
( |
| ) |
|
|
virtual |
◆ query() [1/7]
Definition at line 407 of file ProcessDescriptor.cpp.
408 if ( info == 0 )
return 0;
412 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
414 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessIoCounters, info,
sizeof( IO_COUNTERS ), 0 );
415 status = ( status == 0 ) ? 1 : 0;
416 #elif defined( _WIN32 ) // Windows 95,98...
417 #elif defined( __linux )
421 getrusage( RUSAGE_SELF, &
usage );
422 info->ReadOperationCount =
usage.ru_inblock;
423 info->WriteOperationCount =
usage.ru_oublock;
424 info->OtherOperationCount = 0;
425 info->ReadTransferCount =
usage.ru_inblock;
426 info->WriteTransferCount =
usage.ru_oublock;
427 info->OtherTransferCount = 0;
◆ query() [2/7]
Definition at line 627 of file ProcessDescriptor.cpp.
628 if ( info == 0 )
return 0;
632 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
634 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessTimes, info,
sizeof( KERNEL_USER_TIMES ), 0 );
635 status = ( status == 0 ) ? 1 : 0;
636 #elif defined( _WIN32 ) // Windows 95,98...
637 #elif defined( __linux ) // Linux
638 static long long prc_start = 0;
639 bool myself = pid <= 0 || pid == ::getpid();
640 if ( myself && prc_start == 0 ) {
645 static long long offset =
646 100 *
static_cast<long long>(
time(
nullptr ) ) -
static_cast<long long>( times( &tmsb ) );
647 prc_start = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
653 info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
654 info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
655 info->CreateTime = prc_start;
660 static long long offset =
661 100 *
static_cast<long long>(
time(
nullptr ) ) -
static_cast<long long>( times( &tmsb ) );
665 info->UserTime =
t.tms_utime * TICK_TO_100NSEC;
666 info->KernelTime =
t.tms_stime * TICK_TO_100NSEC;
667 info->CreateTime = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
673 #elif defined( __APPLE__ )
677 #else // no /proc file system: assume sys_start for the first call
679 static clock_t sys_start = times( 0 );
680 static long long offset = 100 *
long long(
time( 0 ) ) - sys_start;
681 clock_t now = times( &tmsb );
682 info->CreateTime = offset + now;
683 info->UserTime = tmsb.tms_utime;
684 info->KernelTime = tmsb.tms_stime;
685 info->CreateTime *= TICK_TO_100NSEC;
686 info->UserTime *= TICK_TO_100NSEC;
687 info->KernelTime *= TICK_TO_100NSEC;
◆ query() [3/7]
long System::ProcessDescriptor::query |
( |
long |
pid, |
|
|
InfoType |
fetch, |
|
|
long * |
info |
|
) |
| |
Definition at line 478 of file ProcessDescriptor.cpp.
480 if ( info == 0 )
return 0;
485 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
487 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessPriorityBoost, info,
sizeof(
long ), 0 );
488 #elif defined( _WIN32 ) // Windows 95,98...
492 if ( pid > 0 ) status = 0;
496 status = ( status == 0 ) ? 1 : 0;
◆ query() [4/7]
Definition at line 435 of file ProcessDescriptor.cpp.
436 if ( info == 0 )
return 0;
440 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
443 sizeof( POOLED_USAGE_AND_LIMITS ), 0 );
444 status = ( status == 0 ) ? 1 : 0;
445 #elif defined( _WIN32 ) // Windows 95,98...
446 #elif defined( __linux ) // Linux
451 getrlimit( RLIMIT_DATA, &lim );
452 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
453 info->PeakPagedPoolUsage = lim.rlim_cur;
454 info->PagedPoolUsage = lim.rlim_cur;
455 info->PagedPoolLimit = lim.rlim_max;
457 getrlimit( RLIMIT_STACK, &lim );
458 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
459 info->PeakNonPagedPoolUsage = lim.rlim_cur;
460 info->NonPagedPoolUsage = lim.rlim_cur;
461 info->NonPagedPoolLimit = lim.rlim_max;
465 info->PeakPagefileUsage = prc.
rss * pg_size;
466 info->PagefileUsage = prc.
rss * pg_size;
467 info->PagefileLimit = 0xFFFFFFFF;
468 #elif defined( __APPLE__ )
◆ query() [5/7]
Definition at line 595 of file ProcessDescriptor.cpp.
596 if ( info == 0 )
return 0;
600 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
603 sizeof( PROCESS_BASIC_INFORMATION ), 0 );
604 status = ( status == 0 ) ? 1 : 0;
605 #elif defined( _WIN32 ) // Windows 95,98...
606 #elif defined( __linux ) // Linux
608 pid = processID( pid );
610 info->ExitStatus = 0;
612 info->BasePriority = 2 * 15 - prc.
priority;
615 info->AffinityMask = prc.
flags;
618 info->UniqueProcessId = pid;
619 info->InheritedFromUniqueProcessId = prc.
ppid;
◆ query() [6/7]
Definition at line 549 of file ProcessDescriptor.cpp.
550 if ( info == 0 )
return 0;
554 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
556 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessQuotaLimits, info,
sizeof( QUOTA_LIMITS ), 0 );
557 status = ( status == 0 ) ? 1 : 0;
558 #elif defined( _WIN32 ) // Windows 95,98...
559 #elif defined( __linux ) // Linux
563 if ( pid > 0 && pid != ::getpid() )
return 0;
566 getrlimit( RLIMIT_DATA, &lim );
567 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
568 info->PagedPoolLimit = lim.rlim_max;
570 getrlimit( RLIMIT_STACK, &lim );
571 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
572 info->NonPagedPoolLimit = lim.rlim_max;
573 info->MinimumWorkingSetSize = 0;
575 getrlimit( RLIMIT_RSS, &lim );
576 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
577 info->MaximumWorkingSetSize = lim.rlim_max;
579 getrlimit( RLIMIT_AS, &lim );
580 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
581 info->PagefileLimit = lim.rlim_max;
583 getrlimit( RLIMIT_CPU, &lim );
584 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
585 info->TimeLimit = lim.rlim_max;
586 #elif defined( __APPLE__ )
◆ query() [7/7]
Definition at line 506 of file ProcessDescriptor.cpp.
507 if ( info == 0 )
return 0;
511 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
513 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessVmCounters, info,
sizeof( VM_COUNTERS ), 0 );
514 status = ( status == 0 ) ? 1 : 0;
515 #elif defined( _WIN32 ) // Windows 95,98...
516 #elif defined( __linux ) // Linux
517 const ssize_t bufsize = 1024;
519 pid = processID( pid );
520 sprintf( buf,
"/proc/%ld/statm", pid );
521 long size, resident, share, trs, lrs, drs, dt;
522 int fd = open( buf, O_RDONLY );
523 ssize_t nread =
read(
fd, buf, bufsize );
525 if ( nread < bufsize && nread >= 0 ) buf[nread] =
'\0';
526 fd =
sscanf( buf,
"%ld %ld %ld %ld %ld %ld %ld", &
size, &resident, &share, &trs, &drs, &lrs, &dt );
529 info->PeakVirtualSize = prc.
vsize;
530 info->VirtualSize = prc.
vsize;
531 info->PeakWorkingSetSize = resident * pg_size;
532 info->WorkingSetSize = resident * pg_size;
533 info->QuotaPeakPagedPoolUsage = share * pg_size;
534 info->QuotaPagedPoolUsage = share * pg_size;
535 info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size;
536 info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size;
538 info->PagefileUsage = prc.
vsize - resident * pg_size;
539 info->PeakPagefileUsage = prc.
vsize - resident * pg_size;
540 #elif defined( __APPLE__ )
The documentation for this class was generated from the following files: