fold the calc of time delta into a func
Subsystems (2)
PATCH v3 1/2 fold the calc of time delta into a func
This piece of code will be used by more than one function after introducing the next patch
Signed-off-by Pingfan Liu <[email protected]>
--- print_info.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
print_info.c +16 -12
@@ -337,6 +337,19 @@ print_usage(void)MSG ("\n" ); } +static void calc_delta (struct timeval *tv_start,struct timeval *delta) +{ +struct timeval tv_end; + +gettimeofday (&tv_end,NULL ); + delta->tv_sec = tv_end.tv_sec - tv_start->tv_sec; + delta->tv_usec = tv_end.tv_usec - tv_start->tv_usec; +if (delta->tv_usec <0 ) { + delta->tv_sec--; + delta->tv_usec +=1000000 ; + } +} +void print_progress (const char *msg,unsigned long current,unsigned long end) {
@@ -369,19 +382,10 @@ print_progress(const char *msg, unsigned long current, unsigned long end)void print_execution_time (char *step_name,struct timeval *tv_start) { -struct timeval tv_end; -time_t diff_sec; -suseconds_t diff_usec; +struct timeval delta; -gettimeofday (&tv_end,NULL ); - - diff_sec = tv_end.tv_sec - tv_start->tv_sec; - diff_usec = tv_end.tv_usec - tv_start->tv_usec; -if (diff_usec <0 ) { - diff_sec--; - diff_usec +=1000000 ; - } +calc_delta (tv_start, &delta);REPORT_MSG ("STEP [%s] : %ld.%06ld seconds\n" , - step_name, diff_sec, diff_usec); + step_name, delta.tv_sec, delta.tv_usec); }
Signature · 7 lines
2.7.4 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec