From 6a5e90f2d91892248f5f7defe1c610e00298d789 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sat, 16 Dec 2017 14:15:28 -0800 Subject: Log output updates. Add a Qt message handler that calls g_log. Add milliseconds to the g_log_message_handler timestamp. Change-Id: I5b1c1d902b6b05cd8daa01741b19d6c2048dfb9a Reviewed-on: https://code.wireshark.org/review/24865 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- wsutil/time_util.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ wsutil/time_util.h | 6 ++++++ 2 files changed, 58 insertions(+) (limited to 'wsutil') diff --git a/wsutil/time_util.c b/wsutil/time_util.c index b35061478f..03aa37dc76 100644 --- a/wsutil/time_util.c +++ b/wsutil/time_util.c @@ -113,6 +113,58 @@ void log_resource_usage(gboolean reset_delta, const char *format, ...) { } +/* Copied from pcapio.c pcapng_write_interface_statistics_block()*/ +guint64 +create_timestamp(void) { + guint64 timestamp; +#ifdef _WIN32 + FILETIME now; +#else + struct timeval now; +#endif + +#ifdef _WIN32 + /* + * Current time, represented as 100-nanosecond intervals since + * January 1, 1601, 00:00:00 UTC. + * + * I think DWORD might be signed, so cast both parts of "now" + * to guint32 so that the sign bit doesn't get treated specially. + * + * Windows 8 provides GetSystemTimePreciseAsFileTime which we + * might want to use instead. + */ + GetSystemTimeAsFileTime(&now); + timestamp = (((guint64)(guint32)now.dwHighDateTime) << 32) + + (guint32)now.dwLowDateTime; + + /* + * Convert to same thing but as 1-microsecond, i.e. 1000-nanosecond, + * intervals. + */ + timestamp /= 10; + + /* + * Subtract difference, in microseconds, between January 1, 1601 + * 00:00:00 UTC and January 1, 1970, 00:00:00 UTC. + */ + timestamp -= G_GUINT64_CONSTANT(11644473600000000); +#else + /* + * Current time, represented as seconds and microseconds since + * January 1, 1970, 00:00:00 UTC. + */ + gettimeofday(&now, NULL); + + /* + * Convert to delta in microseconds. + */ + timestamp = (guint64)(now.tv_sec) * 1000000 + + (guint64)(now.tv_usec); +#endif + return timestamp; +} + /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * diff --git a/wsutil/time_util.h b/wsutil/time_util.h index 51a3aa64c3..1775bb62a3 100644 --- a/wsutil/time_util.h +++ b/wsutil/time_util.h @@ -45,6 +45,12 @@ void get_resource_usage(double *user_time, double *sys_time); WS_DLL_PUBLIC void log_resource_usage(gboolean reset_delta, const char *format, ...); +/** + * Fetch the number of microseconds since midnight (0 hour), January 1, 1970. + */ +WS_DLL_PUBLIC +guint64 create_timestamp(void); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit v1.2.3