@@ -382,29 +382,25 @@ fn format_rusage_data(child: Child) -> Option<String> {
382
382
/// supplied on Linux (the `rusage` struct has other fields in it but they are
383
383
/// currently unsupported by Linux).
384
384
fn format_rusage_data ( _child : Child ) -> Option < String > {
385
- let rusage: libc:: rusage = unsafe {
386
- let mut recv = std:: mem:: zeroed ( ) ;
387
- // -1 is RUSAGE_CHILDREN, which means to get the rusage for all children
388
- // (and grandchildren, etc) processes that have respectively terminated
389
- // and been waited for.
390
- let retval = libc:: getrusage ( -1 , & mut recv) ;
391
- if retval != 0 {
392
- return None ;
393
- }
394
- recv
395
- } ;
385
+ use nix:: sys:: resource:: { getrusage, UsageWho } ;
386
+
387
+ // RUSAGE_CHILDREN (= -1) means to get the rusage for all children
388
+ // (and grandchildren, etc) processes that have respectively terminated
389
+ // and been waited for.
390
+ let rusage = getrusage ( UsageWho :: RUSAGE_CHILDREN ) . ok ( ) ?;
391
+
396
392
// Mac OS X reports the maxrss in bytes, not kb.
397
393
let divisor = if env:: consts:: OS == "macos" { 1024 } else { 1 } ;
398
- let maxrss = ( rusage. ru_maxrss + ( divisor - 1 ) ) / divisor;
394
+ let maxrss = ( rusage. max_rss ( ) + ( divisor - 1 ) ) / divisor;
399
395
400
396
let mut init_str = format ! (
401
397
"user: {USER_SEC}.{USER_USEC:03} \
402
398
sys: {SYS_SEC}.{SYS_USEC:03} \
403
399
max rss (kb): {MAXRSS}",
404
- USER_SEC = rusage. ru_utime . tv_sec,
405
- USER_USEC = rusage. ru_utime . tv_usec,
406
- SYS_SEC = rusage. ru_stime . tv_sec,
407
- SYS_USEC = rusage. ru_stime . tv_usec,
400
+ USER_SEC = rusage. user_time ( ) . tv_sec( ) ,
401
+ USER_USEC = rusage. user_time ( ) . tv_usec( ) ,
402
+ SYS_SEC = rusage. system_time ( ) . tv_sec( ) ,
403
+ SYS_USEC = rusage. system_time ( ) . tv_usec( ) ,
408
404
MAXRSS = maxrss
409
405
) ;
410
406
@@ -413,20 +409,20 @@ fn format_rusage_data(_child: Child) -> Option<String> {
413
409
// either means no events of that type occurred, or that the platform
414
410
// does not support it.
415
411
416
- let minflt = rusage. ru_minflt ;
417
- let majflt = rusage. ru_majflt ;
412
+ let minflt = rusage. minor_page_faults ( ) ;
413
+ let majflt = rusage. major_page_faults ( ) ;
418
414
if minflt != 0 || majflt != 0 {
419
415
init_str. push_str ( & format ! ( " page reclaims: {minflt} page faults: {majflt}" ) ) ;
420
416
}
421
417
422
- let inblock = rusage. ru_inblock ;
423
- let oublock = rusage. ru_oublock ;
418
+ let inblock = rusage. block_reads ( ) ;
419
+ let oublock = rusage. block_writes ( ) ;
424
420
if inblock != 0 || oublock != 0 {
425
421
init_str. push_str ( & format ! ( " fs block inputs: {inblock} fs block outputs: {oublock}" ) ) ;
426
422
}
427
423
428
- let nvcsw = rusage. ru_nvcsw ;
429
- let nivcsw = rusage. ru_nivcsw ;
424
+ let nvcsw = rusage. voluntary_context_switches ( ) ;
425
+ let nivcsw = rusage. involuntary_context_switches ( ) ;
430
426
if nvcsw != 0 || nivcsw != 0 {
431
427
init_str. push_str ( & format ! (
432
428
" voluntary ctxt switches: {nvcsw} involuntary ctxt switches: {nivcsw}"
0 commit comments