#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 390 of file ProcessDescriptor.cpp.
392 static bool first =
true;
395 void* mh = ::LoadLibrary(
"NTDll.dll" );
397 NtApi::NtQueryInformationProcess =
398 ( NtApi::__NtQueryInformationProcess )::GetProcAddress( (HINSTANCE)mh,
"NtQueryInformationProcess" );
◆ ~ProcessDescriptor()
| System::ProcessDescriptor::~ProcessDescriptor |
( |
| ) |
|
|
virtual |
◆ query() [1/7]
Definition at line 406 of file ProcessDescriptor.cpp.
407 if ( info == 0 )
return 0;
411 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
413 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessIoCounters, info,
sizeof( IO_COUNTERS ), 0 );
414 status = ( status == 0 ) ? 1 : 0;
415 #elif defined( _WIN32 ) // Windows 95,98...
416 #elif defined( __linux )
420 getrusage( RUSAGE_SELF, &
usage );
421 info->ReadOperationCount =
usage.ru_inblock;
422 info->WriteOperationCount =
usage.ru_oublock;
423 info->OtherOperationCount = 0;
424 info->ReadTransferCount =
usage.ru_inblock;
425 info->WriteTransferCount =
usage.ru_oublock;
426 info->OtherTransferCount = 0;
◆ query() [2/7]
Definition at line 626 of file ProcessDescriptor.cpp.
627 if ( info == 0 )
return 0;
631 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
633 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessTimes, info,
sizeof( KERNEL_USER_TIMES ), 0 );
634 status = ( status == 0 ) ? 1 : 0;
635 #elif defined( _WIN32 ) // Windows 95,98...
636 #elif defined( __linux ) // Linux
637 static long long prc_start = 0;
638 bool myself = pid <= 0 || pid == ::getpid();
639 if ( myself && prc_start == 0 ) {
644 static long long offset =
645 100 *
static_cast<long long>(
time(
nullptr ) ) -
static_cast<long long>( times( &tmsb ) );
646 prc_start = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
652 info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
653 info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
654 info->CreateTime = prc_start;
659 static long long offset =
660 100 *
static_cast<long long>(
time(
nullptr ) ) -
static_cast<long long>( times( &tmsb ) );
664 info->UserTime =
t.tms_utime * TICK_TO_100NSEC;
665 info->KernelTime =
t.tms_stime * TICK_TO_100NSEC;
666 info->CreateTime = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
672 #elif defined( __APPLE__ )
676 #else // no /proc file system: assume sys_start for the first call
678 static clock_t sys_start = times( 0 );
679 static long long offset = 100 *
long long(
time( 0 ) ) - sys_start;
680 clock_t now = times( &tmsb );
681 info->CreateTime = offset + now;
682 info->UserTime = tmsb.tms_utime;
683 info->KernelTime = tmsb.tms_stime;
684 info->CreateTime *= TICK_TO_100NSEC;
685 info->UserTime *= TICK_TO_100NSEC;
686 info->KernelTime *= TICK_TO_100NSEC;
◆ query() [3/7]
| long System::ProcessDescriptor::query |
( |
long |
pid, |
|
|
InfoType |
fetch, |
|
|
long * |
info |
|
) |
| |
Definition at line 477 of file ProcessDescriptor.cpp.
479 if ( info == 0 )
return 0;
484 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
486 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessPriorityBoost, info,
sizeof(
long ), 0 );
487 #elif defined( _WIN32 ) // Windows 95,98...
491 if ( pid > 0 ) status = 0;
495 status = ( status == 0 ) ? 1 : 0;
◆ query() [4/7]
Definition at line 434 of file ProcessDescriptor.cpp.
435 if ( info == 0 )
return 0;
439 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
442 sizeof( POOLED_USAGE_AND_LIMITS ), 0 );
443 status = ( status == 0 ) ? 1 : 0;
444 #elif defined( _WIN32 ) // Windows 95,98...
445 #elif defined( __linux ) // Linux
450 getrlimit( RLIMIT_DATA, &lim );
451 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
452 info->PeakPagedPoolUsage = lim.rlim_cur;
453 info->PagedPoolUsage = lim.rlim_cur;
454 info->PagedPoolLimit = lim.rlim_max;
456 getrlimit( RLIMIT_STACK, &lim );
457 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
458 info->PeakNonPagedPoolUsage = lim.rlim_cur;
459 info->NonPagedPoolUsage = lim.rlim_cur;
460 info->NonPagedPoolLimit = lim.rlim_max;
464 info->PeakPagefileUsage = prc.
rss * pg_size;
465 info->PagefileUsage = prc.
rss * pg_size;
466 info->PagefileLimit = 0xFFFFFFFF;
467 #elif defined( __APPLE__ )
◆ query() [5/7]
Definition at line 594 of file ProcessDescriptor.cpp.
595 if ( info == 0 )
return 0;
599 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
602 sizeof( PROCESS_BASIC_INFORMATION ), 0 );
603 status = ( status == 0 ) ? 1 : 0;
604 #elif defined( _WIN32 ) // Windows 95,98...
605 #elif defined( __linux ) // Linux
607 pid = processID( pid );
609 info->ExitStatus = 0;
611 info->BasePriority = 2 * 15 - prc.
priority;
614 info->AffinityMask = prc.
flags;
617 info->UniqueProcessId = pid;
618 info->InheritedFromUniqueProcessId = prc.
ppid;
◆ query() [6/7]
Definition at line 548 of file ProcessDescriptor.cpp.
549 if ( info == 0 )
return 0;
553 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
555 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessQuotaLimits, info,
sizeof( QUOTA_LIMITS ), 0 );
556 status = ( status == 0 ) ? 1 : 0;
557 #elif defined( _WIN32 ) // Windows 95,98...
558 #elif defined( __linux ) // Linux
562 if ( pid > 0 && pid != ::getpid() )
return 0;
565 getrlimit( RLIMIT_DATA, &lim );
566 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
567 info->PagedPoolLimit = lim.rlim_max;
569 getrlimit( RLIMIT_STACK, &lim );
570 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
571 info->NonPagedPoolLimit = lim.rlim_max;
572 info->MinimumWorkingSetSize = 0;
574 getrlimit( RLIMIT_RSS, &lim );
575 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
576 info->MaximumWorkingSetSize = lim.rlim_max;
578 getrlimit( RLIMIT_AS, &lim );
579 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
580 info->PagefileLimit = lim.rlim_max;
582 getrlimit( RLIMIT_CPU, &lim );
583 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
584 info->TimeLimit = lim.rlim_max;
585 #elif defined( __APPLE__ )
◆ query() [7/7]
Definition at line 505 of file ProcessDescriptor.cpp.
506 if ( info == 0 )
return 0;
510 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT
512 status = NtApi::NtQueryInformationProcess(
h.handle(),
ProcessVmCounters, info,
sizeof( VM_COUNTERS ), 0 );
513 status = ( status == 0 ) ? 1 : 0;
514 #elif defined( _WIN32 ) // Windows 95,98...
515 #elif defined( __linux ) // Linux
516 const ssize_t bufsize = 1024;
518 pid = processID( pid );
519 sprintf( buf,
"/proc/%ld/statm", pid );
520 long size, resident, share, trs, lrs, drs, dt;
521 int fd = open( buf, O_RDONLY );
522 ssize_t nread =
read(
fd, buf, bufsize );
524 if ( nread < bufsize && nread >= 0 ) buf[nread] =
'\0';
525 fd =
sscanf( buf,
"%ld %ld %ld %ld %ld %ld %ld", &
size, &resident, &share, &trs, &drs, &lrs, &dt );
528 info->PeakVirtualSize = prc.
vsize;
529 info->VirtualSize = prc.
vsize;
530 info->PeakWorkingSetSize = resident * pg_size;
531 info->WorkingSetSize = resident * pg_size;
532 info->QuotaPeakPagedPoolUsage = share * pg_size;
533 info->QuotaPagedPoolUsage = share * pg_size;
534 info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size;
535 info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size;
537 info->PagefileUsage = prc.
vsize - resident * pg_size;
538 info->PeakPagefileUsage = prc.
vsize - resident * pg_size;
539 #elif defined( __APPLE__ )
The documentation for this class was generated from the following files: