diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-07-16 23:51:32 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-07-17 06:26:09 +0000 |
commit | 80dc3d4f5c4d041c982a11b42b04251c888b6610 (patch) | |
tree | ebb68ac5f603b613634e55b751c0cc9ac2f5d217 | |
parent | 6658f97a59697818ececde5f5d002bc6c9ce7bc3 (diff) |
capchild,ifaces: use g_get_monotonic_time
Simplify timing code by relying on g_get_monotonic_time which has the
additional benefit that it is unaffected by clock jumps.
Change-Id: Ib61b848eb5e20d68d486a07e3528ccafb03f8814
Reviewed-on: https://code.wireshark.org/review/33976
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | capchild/capture_sync.c | 26 | ||||
-rw-r--r-- | ui/iface_lists.c | 11 |
2 files changed, 12 insertions, 25 deletions
diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c index 4991bed501..c46871d229 100644 --- a/capchild/capture_sync.c +++ b/capchild/capture_sync.c @@ -1064,15 +1064,14 @@ sync_pipe_run_command(char* const argv[], gchar **data, gchar **primary_msg, gchar **secondary_msg, void (*update_cb)(void)) { int ret, i; - GTimeVal start_time; - GTimeVal end_time; - float elapsed; + gint64 start_time; + double elapsed; int logging_enabled; /* check if logging is actually enabled, otherwise don't expend the CPU generating logging */ logging_enabled=( (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO) & G_LOG_LEVEL_MASK & prefs.console_log_level); if(logging_enabled){ - g_get_current_time(&start_time); + start_time = g_get_monotonic_time(); g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_INFO, "sync_pipe_run_command() starts"); for(i=0; argv[i] != 0; i++) { g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " argv[%d]: %s", i, argv[i]); @@ -1082,9 +1081,7 @@ sync_pipe_run_command(char* const argv[], gchar **data, gchar **primary_msg, ret=sync_pipe_run_command_actual(argv, data, primary_msg, secondary_msg, update_cb); if(logging_enabled){ - g_get_current_time(&end_time); - elapsed = (float) ((end_time.tv_sec - start_time.tv_sec) + - ((end_time.tv_usec - start_time.tv_usec) / 1e6)); + elapsed = (g_get_monotonic_time() - start_time) / 1e6; g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_INFO, "sync_pipe_run_command() ends, taking %.3fs, result=%d", elapsed, ret); @@ -1752,15 +1749,10 @@ sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp) int retry_waitpid = 3; #endif int ret = -1; - GTimeVal start_time; - GTimeVal end_time; - float elapsed; + gint64 start_time; + double elapsed; - /* - * GLIB_CHECK_VERSION(2,28,0) adds g_get_real_time which could minimize or - * replace this - */ - g_get_current_time(&start_time); + start_time = g_get_monotonic_time(); g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: wait till child closed"); g_assert(fork_child != WS_INVALID_PID); @@ -1850,9 +1842,7 @@ sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp) } #endif - g_get_current_time(&end_time); - elapsed = (float) ((end_time.tv_sec - start_time.tv_sec) + - ((end_time.tv_usec - start_time.tv_usec) / 1e6)); + elapsed = (g_get_monotonic_time() - start_time) / 1e6; g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_wait_for_child: capture child closed after %.3fs", elapsed); return ret; } diff --git a/ui/iface_lists.c b/ui/iface_lists.c index fa9153b4b3..1ed591886b 100644 --- a/ui/iface_lists.c +++ b/ui/iface_lists.c @@ -425,13 +425,12 @@ scan_local_interfaces(void (*update_cb)(void)) void fill_in_local_interfaces(void(*update_cb)(void)) { - GTimeVal start_time; - GTimeVal end_time; - float elapsed; + gint64 start_time; + double elapsed; static gboolean initialized = FALSE; /* record the time we started, so we can log total time later */ - g_get_current_time(&start_time); + start_time = g_get_monotonic_time(); g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "fill_in_local_interfaces() starts"); if (!initialized) { @@ -440,9 +439,7 @@ fill_in_local_interfaces(void(*update_cb)(void)) initialized = TRUE; } /* log how long it took */ - g_get_current_time(&end_time); - elapsed = (float) ((end_time.tv_sec - start_time.tv_sec) + - ((end_time.tv_usec - start_time.tv_usec) / 1e6)); + elapsed = (g_get_monotonic_time() - start_time) / 1e6; g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "fill_in_local_interfaces() ends, taking %.3fs", elapsed); } |