428 {
429 if ( info == 0 ) return 0;
430 long status = 1;
431
433#if defined( __linux )
434 const ssize_t bufsize = 1024;
435 char buf[bufsize];
436 pid = processID( pid );
437 snprintf( buf, sizeof( buf ), "/proc/%ld/statm", pid );
438 long size, resident, share, trs, lrs, drs, dt;
439 int fd = open( buf, O_RDONLY );
440 ssize_t nread =
read( fd, buf, bufsize );
441 close( fd );
442 if ( nread < bufsize && nread >= 0 ) buf[nread] = '\0';
443 fd = sscanf( buf,
"%ld %ld %ld %ld %ld %ld %ld", &size, &resident, &share, &trs, &drs, &lrs, &dt );
444 linux_proc prc;
446 info->PeakVirtualSize = prc.
vsize;
447 info->VirtualSize = prc.
vsize;
448 info->PeakWorkingSetSize = resident * pg_size;
449 info->WorkingSetSize = resident * pg_size;
450 info->QuotaPeakPagedPoolUsage = share * pg_size;
451 info->QuotaPagedPoolUsage = share * pg_size;
452 info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size;
453 info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size;
455 info->PagefileUsage = prc.
vsize - resident * pg_size;
456 info->PeakPagefileUsage = prc.
vsize - resident * pg_size;
457#elif defined( __APPLE__ )
458
459
460 mach_task_basic_info_data_t taskInfo;
461 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
462
463 kern_return_t kr = task_info( mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount );
464 if ( kr == KERN_SUCCESS ) {
465 info->VirtualSize = taskInfo.virtual_size;
466 info->PeakVirtualSize = taskInfo.virtual_size;
467 info->WorkingSetSize = taskInfo.resident_size;
468 info->PeakWorkingSetSize = taskInfo.resident_size_max;
469 info->QuotaPagedPoolUsage = 0;
470 info->QuotaPeakPagedPoolUsage = 0;
471 info->QuotaNonPagedPoolUsage = 0;
472 info->QuotaPeakNonPagedPoolUsage = 0;
473 info->PagefileUsage = taskInfo.virtual_size - taskInfo.resident_size;
474 info->PeakPagefileUsage = taskInfo.virtual_size - taskInfo.resident_size;
475
476
478 if ( getrusage( RUSAGE_SELF, &usage ) == 0 ) {
479 info->PageFaultCount =
static_cast<unsigned long>(
usage.ru_majflt +
usage.ru_minflt );
480 } else {
481 info->PageFaultCount = 0;
482 }
483 status = 1;
484 } else {
485
486 info->VirtualSize = 0;
487 info->PeakVirtualSize = 0;
488 info->WorkingSetSize = 0;
489 info->PeakWorkingSetSize = 0;
490 info->PageFaultCount = 0;
491 info->QuotaPagedPoolUsage = 0;
492 info->QuotaPeakPagedPoolUsage = 0;
493 info->QuotaNonPagedPoolUsage = 0;
494 info->QuotaPeakNonPagedPoolUsage = 0;
495 info->PagefileUsage = 0;
496 info->PeakPagefileUsage = 0;
497 status = 0;
498 }
499 (void)pid;
500#else
501 if ( pid ) {}
502#endif
503 }
504 return status;
505}
constexpr auto size(const T &, Args &&...) noexcept
read(f, regex=".*", skipevents=0)