diff --git a/src/engine/execunix.c b/src/engine/execunix.c index 8ee4d9dbf..21a223d9e 100644 --- a/src/engine/execunix.c +++ b/src/engine/execunix.c @@ -64,8 +64,6 @@ static int get_free_cmdtab_slot(); /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ static clock_t tps; -static int old_time_initialized; -static struct tms old_time; /* We hold stdout & stderr child process information in two element arrays * indexed as follows. @@ -178,13 +176,6 @@ void exec_cmd exit( EXITBAD ); } - /* Initialize old_time only once. */ - if ( !old_time_initialized ) - { - times( &old_time ); - old_time_initialized = 1; - } - /* Start the command */ timestamp_current( &cmdtab[ slot ].start_dt ); @@ -513,6 +504,7 @@ void exec_wait() int status; int rstat; timing_info time_info; + struct rusage cmd_usage; /* We found a terminated child process - our search is done. */ finished = 1; @@ -523,7 +515,7 @@ void exec_wait() close_streams( i, ERR ); /* Reap the child and release resources. */ - while ( ( pid = waitpid( cmdtab[ i ].pid, &status, 0 ) ) == -1 ) + while ( ( pid = wait4( cmdtab[ i ].pid, &status, 0, &cmd_usage ) ) == -1 ) if ( errno != EINTR ) break; if ( pid != cmdtab[ i ].pid ) @@ -539,15 +531,10 @@ void exec_wait() : EXIT_OK; { - struct tms new_time; - times( &new_time ); - time_info.system = (double)( new_time.tms_cstime - - old_time.tms_cstime ) / CLOCKS_PER_SEC; - time_info.user = (double)( new_time.tms_cutime - - old_time.tms_cutime ) / CLOCKS_PER_SEC; + time_info.system = ((double)(cmd_usage.ru_stime.tv_sec)*1000000.0+(double)(cmd_usage.ru_stime.tv_usec))/1000000.0; + time_info.user = ((double)(cmd_usage.ru_utime.tv_sec)*1000000.0+(double)(cmd_usage.ru_utime.tv_usec))/1000000.0; timestamp_copy( &time_info.start, &cmdtab[ i ].start_dt ); timestamp_current( &time_info.end ); - old_time = new_time; } /* Drive the completion. */ diff --git a/src/engine/make1.c b/src/engine/make1.c index 7dbf7c8da..b7fe51728 100644 --- a/src/engine/make1.c +++ b/src/engine/make1.c @@ -854,7 +854,9 @@ static void make1c_closure { call_timing_rule( t, time ); if ( DEBUG_EXECCMD ) - out_printf( "%f sec system; %f sec user\n", time->system, time->user ); + out_printf( "%f sec system; %f sec user, %f sec clock\n", + time->system, time->user, + timestamp_delta_seconds(&time->start, &time->end) ); /* Assume -p0 is in effect, i.e. cmd_stdout contains merged output. */ call_action_rule( t, status_orig, time, cmd->buf->value, cmd_stdout ); diff --git a/src/engine/timestamp.c b/src/engine/timestamp.c index 17510bcd0..b6fd906ef 100644 --- a/src/engine/timestamp.c +++ b/src/engine/timestamp.c @@ -261,3 +261,11 @@ void timestamp_done() hashdone( bindhash ); } } + +/* + * timestamp_delta_seconds() - seconds from time a to b. + */ +double timestamp_delta_seconds( timestamp const * const a , timestamp const * const b ) +{ + return ((b->secs*1000000.0+b->nsecs)-(a->secs*1000000.0+a->nsecs))/1000000.0; +} diff --git a/src/engine/timestamp.h b/src/engine/timestamp.h index ecedb5f92..e9b41753c 100644 --- a/src/engine/timestamp.h +++ b/src/engine/timestamp.h @@ -42,5 +42,6 @@ void timestamp_from_filetime( timestamp * const, FILETIME const * const ); #endif void timestamp_done(); +double timestamp_delta_seconds( timestamp const * const, timestamp const * const ); #endif