From: Frank Ch. Eigler Date: Thu, 26 Nov 2020 00:41:03 +0000 (-0500) Subject: debuginfod: use clock_gettime(CLOCK_MONOTONIC) for intervals X-Git-Tag: elfutils-0.183~75 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ea5788a5bae5ac88148e4cddbe5fe7ea7628eadc;p=thirdparty%2Felfutils.git debuginfod: use clock_gettime(CLOCK_MONOTONIC) for intervals On Mark's request, use a monotonic clock for metrics/reports related to time interval measurement. gettimeofday can jump a bit, which could distort metrics. Tests unaffected. Signed-off-by: Frank Ch. Eigler --- diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 576b6673a..d38683837 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -3,6 +3,12 @@ * debuginfod-client.c (debuginfod_query_server): Initialize struct handle_data errbuf to the empty string. +2020-11-25 Frank Ch. Eigler + + * debuginfod.cxx (tmp_ms_metric): Switch from gettimeofday to + clock_gettime(CLOCK_MONOTONIC) for time-interval measurements. + (handler_cb, scan_source_paths, groom): Ditto. + 2020-11-23 Frank Ch. Eigler * debuginfod.cxx (tmp_ms_metric): New class for RAII timing metrics. diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 618620b4c..9da4c44a9 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -437,19 +437,19 @@ public: class tmp_ms_metric { // a RAII style wrapper for exception-safe scoped timing string m, n, v; - struct timeval tv_start; + struct timespec ts_start; public: tmp_ms_metric(const string& mname, const string& lname, const string& lvalue): m(mname), n(lname), v(lvalue) { - gettimeofday (& tv_start, NULL); + clock_gettime (CLOCK_MONOTONIC, & ts_start); } ~tmp_ms_metric() { - struct timeval tv_end; - gettimeofday (& tv_end, NULL); - double deltas = (tv_end.tv_sec - tv_start.tv_sec) - + (tv_end.tv_usec - tv_start.tv_usec)*0.000001; + struct timespec ts_end; + clock_gettime (CLOCK_MONOTONIC, & ts_end); + double deltas = (ts_end.tv_sec - ts_start.tv_sec) + + (ts_end.tv_nsec - ts_start.tv_nsec)/1.e9; add_metric (m + "_milliseconds_sum", n, v, (deltas*1000)); inc_metric (m + "_milliseconds_count", n, v); @@ -1862,8 +1862,8 @@ handler_cb (void * /*cls*/, #endif int http_code = 500; off_t http_size = -1; - struct timeval tv_start, tv_end; - gettimeofday (&tv_start, NULL); + struct timespec ts_start, ts_end; + clock_gettime (CLOCK_MONOTONIC, &ts_start); try { @@ -1938,8 +1938,8 @@ handler_cb (void * /*cls*/, rc = e.mhd_send_response (connection); } - gettimeofday (&tv_end, NULL); - double deltas = (tv_end.tv_sec - tv_start.tv_sec) + (tv_end.tv_usec - tv_start.tv_usec)*0.000001; + clock_gettime (CLOCK_MONOTONIC, &ts_end); + double deltas = (ts_end.tv_sec - ts_start.tv_sec) + (ts_end.tv_nsec - ts_start.tv_nsec)/1.e9; obatched(clog) << conninfo(connection) << ' ' << method << ' ' << url << ' ' << http_code << ' ' << http_size @@ -2856,8 +2856,8 @@ scan_source_paths() throw libc_exception(errno, "cannot fts_open"); defer_dtor fts_cleanup (fts, fts_close); - struct timeval tv_start, tv_end; - gettimeofday (&tv_start, NULL); + struct timespec ts_start, ts_end; + clock_gettime (CLOCK_MONOTONIC, &ts_start); unsigned fts_scanned = 0, fts_regex = 0; FTSENT *f; @@ -2934,8 +2934,8 @@ scan_source_paths() break; } } - gettimeofday (&tv_end, NULL); - double deltas = (tv_end.tv_sec - tv_start.tv_sec) + (tv_end.tv_usec - tv_start.tv_usec)*0.000001; + clock_gettime (CLOCK_MONOTONIC, &ts_end); + double deltas = (ts_end.tv_sec - ts_start.tv_sec) + (ts_end.tv_nsec - ts_start.tv_nsec)/1.e9; obatched(clog) << "fts traversed source paths in " << deltas << "s, scanned=" << fts_scanned << ", regex-skipped=" << fts_regex << endl; @@ -3025,8 +3025,8 @@ void groom() { obatched(clog) << "grooming database" << endl; - struct timeval tv_start, tv_end; - gettimeofday (&tv_start, NULL); + struct timespec ts_start, ts_end; + clock_gettime (CLOCK_MONOTONIC, &ts_start); database_stats_report(); @@ -3090,8 +3090,8 @@ void groom() fdcache.limit(0,0); // release the fdcache contents fdcache.limit(fdcache_fds,fdcache_mbs); // restore status quo parameters - gettimeofday (&tv_end, NULL); - double deltas = (tv_end.tv_sec - tv_start.tv_sec) + (tv_end.tv_usec - tv_start.tv_usec)*0.000001; + clock_gettime (CLOCK_MONOTONIC, &ts_end); + double deltas = (ts_end.tv_sec - ts_start.tv_sec) + (ts_end.tv_nsec - ts_start.tv_nsec)/1.e9; obatched(clog) << "groomed database in " << deltas << "s" << endl; }