From: hugo303 Date: Wed, 14 Nov 2012 09:13:46 +0000 (+0000) Subject: * Calculation of duration for test runs now use clock_gettime() instead of X-Git-Tag: 0.10.0~505 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad19a872bda2b6ada73a88cb02e7694926bf1ebf;p=check * Calculation of duration for test runs now use clock_gettime() instead of gettimeofday(). Definition of DIFF_IN_USEC() moved to check_impl.h. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@675 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/src/check_impl.h b/src/check_impl.h index 371772a..01f0f56 100644 --- a/src/check_impl.h +++ b/src/check_impl.h @@ -27,6 +27,11 @@ Include stdio.h & list.h before this header */ +/** calculate the difference in useconds out of two "struct timespec"s */ +#define DIFF_IN_USEC(begin, end) \ + ( (((end).tv_sec - (begin).tv_sec) * 1000000) + \ + ((end).tv_nsec/1000) - ((begin).tv_nsec/1000) ) + typedef struct TF { TFun fn; int loop_start; diff --git a/src/check_log.c b/src/check_log.c index 2bfee88..f1e2b4b 100644 --- a/src/check_log.c +++ b/src/check_log.c @@ -231,13 +231,15 @@ void xml_lfun (SRunner *sr CK_ATTRIBUTE_UNUSED, FILE *file, enum print_output pr { TestResult *tr; Suite *s; - static struct timeval inittv; + static struct timespec ts_start; static char t[sizeof "yyyy-mm-dd hh:mm:ss"] = {0}; if (t[0] == 0) { + struct timeval inittv; struct tm now; gettimeofday(&inittv, NULL); + clock_gettime(CLOCK_MONOTONIC, &ts_start); localtime_r(&(inittv.tv_sec), &now); strftime(t, sizeof("yyyy-mm-dd hh:mm:ss"), "%Y-%m-%d %H:%M:%S", &now); } @@ -251,14 +253,14 @@ void xml_lfun (SRunner *sr CK_ATTRIBUTE_UNUSED, FILE *file, enum print_output pr break; case CLENDLOG_SR: { - struct timeval now; + struct timespec ts_end; + unsigned int duration; /* calculate time the test were running */ - gettimeofday(&now, NULL); - timersub(&now, &inittv, &now); - - fprintf(file, " %lu.%06lu\n", - now.tv_sec, now.tv_usec); + clock_gettime(CLOCK_MONOTONIC, &ts_end); + duration = DIFF_IN_USEC(ts_start, ts_end); + fprintf(file, " %u.%06u\n", + duration / 1000000, duration % 1000000); fprintf(file, "\n"); } break; diff --git a/src/check_run.c b/src/check_run.c index 968e784..d5d341f 100644 --- a/src/check_run.c +++ b/src/check_run.c @@ -51,11 +51,6 @@ enum tf_type { }; -/** calculate the difference in useconds out of two "struct timeval"s */ -#define DIFF_IN_USEC(begin, end) \ - ( (((end).tv_sec - (begin).tv_sec) * 1000000) + \ - ((end).tv_nsec/1000) - ((begin).tv_nsec/1000) ) - /* all functions are defined in the same order they are declared. functions that depend on forking are gathered all together. non-static functions are at the end of the file. */