From 18c1fa8d1df7aecbe9b10ea1c202f0238d4732ae Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 23 Feb 2015 22:00:46 +0100 Subject: [PATCH] dbus-monitor: Add timestamp to --monitor mode. Use cross platform function _dbus_get_real_time() for fetching current time. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88896 --- cmake/tools/CMakeLists.txt | 2 +- dbus/dbus-sysdeps.h | 1 + tools/dbus-monitor.c | 77 +++++++++++++--------------------------------- tools/dbus-print-message.c | 2 +- tools/dbus-print-message.h | 2 +- tools/dbus-send.c | 2 +- 6 files changed, 26 insertions(+), 60 deletions(-) diff --git a/cmake/tools/CMakeLists.txt b/cmake/tools/CMakeLists.txt index 525dc05..643a0b6 100644 --- a/cmake/tools/CMakeLists.txt +++ b/cmake/tools/CMakeLists.txt @@ -62,7 +62,7 @@ endif (DBUS_BUILD_X11) install_targets(/bin dbus-launch ) add_executable(dbus-monitor ${dbus_monitor_SOURCES}) -target_link_libraries(dbus-monitor ${DBUS_LIBRARIES}) +target_link_libraries(dbus-monitor ${DBUS_INTERNAL_LIBRARIES}) install_targets(/bin dbus-monitor ) # create the /var/lib/dbus directory for dbus-uuidgen diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index e7a556b..2dbc420 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -336,6 +336,7 @@ DBUS_PRIVATE_EXPORT void _dbus_get_monotonic_time (long *tv_sec, long *tv_usec); +DBUS_PRIVATE_EXPORT void _dbus_get_real_time (long *tv_sec, long *tv_usec); diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index 14ceae9..6ebb13c 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -48,53 +48,16 @@ /* http://www.tcpdump.org/linktypes.html */ #define LINKTYPE_DBUS 231 -#ifdef DBUS_WIN - -/* gettimeofday is not defined on windows */ -#define DBUS_SECONDS_SINCE_1601 11644473600LL -#define DBUS_USEC_IN_SEC 1000000LL - -#ifdef DBUS_WINCE - -#ifndef _IOLBF -#define _IOLBF 0x40 -#endif -#ifndef _IONBF -#define _IONBF 0x04 -#endif - -void -GetSystemTimeAsFileTime (LPFILETIME ftp) -{ - SYSTEMTIME st; - GetSystemTime (&st); - SystemTimeToFileTime (&st, ftp); -} -#endif - -static int -gettimeofday (struct timeval *__p, - void *__t) -{ - union { - unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */ - FILETIME ft; - } now; - - GetSystemTimeAsFileTime (&now.ft); - __p->tv_usec = (long) ((now.ns100 / 10LL) % DBUS_USEC_IN_SEC); - __p->tv_sec = (long)(((now.ns100 / 10LL) / DBUS_SECONDS_SINCE_1601) - DBUS_SECONDS_SINCE_1601); - - return 0; -} -#endif - static DBusHandlerResult monitor_filter_func (DBusConnection *connection, DBusMessage *message, void *user_data) { - print_message (message, FALSE); + long sec = 0, usec = 0; + + _dbus_get_real_time (&sec, &usec); + + print_message (message, FALSE, sec, usec); if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, @@ -130,9 +93,9 @@ profile_print_headers (void) static void profile_print_with_attrs (const char *type, DBusMessage *message, - struct timeval *t, ProfileAttributeFlags attrs) + long sec, long usec, ProfileAttributeFlags attrs) { - printf ("%s\t%lu.%06lu", type, (unsigned long) t->tv_sec, (unsigned long) t->tv_usec); + printf ("%s\t%lu.%06lu", type, (unsigned long) sec, (unsigned long) usec); if (attrs & PROFILE_ATTRIBUTE_FLAG_SERIAL) printf ("\t%u", dbus_message_get_serial (message)); @@ -165,13 +128,7 @@ static void print_message_profile (DBusMessage *message) { static dbus_bool_t first = TRUE; - struct timeval t; - - if (gettimeofday (&t, NULL) < 0) - { - printf ("un\n"); - return; - } + long sec = 0, usec = 0; if (first) { @@ -179,10 +136,18 @@ print_message_profile (DBusMessage *message) first = FALSE; } + _dbus_get_real_time (&sec, &usec); + + if (sec == 0) + { + printf("un\n"); + return; + } + switch (dbus_message_get_type (message)) { case DBUS_MESSAGE_TYPE_METHOD_CALL: - profile_print_with_attrs ("mc", message, &t, + profile_print_with_attrs ("mc", message, sec, usec, PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_DESTINATION | @@ -191,21 +156,21 @@ print_message_profile (DBusMessage *message) PROFILE_ATTRIBUTE_FLAG_MEMBER); break; case DBUS_MESSAGE_TYPE_METHOD_RETURN: - profile_print_with_attrs ("mr", message, &t, + profile_print_with_attrs ("mr", message, sec, usec, PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_DESTINATION | PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL); break; case DBUS_MESSAGE_TYPE_ERROR: - profile_print_with_attrs ("err", message, &t, + profile_print_with_attrs ("err", message, sec, usec, PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_DESTINATION | PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL); break; case DBUS_MESSAGE_TYPE_SIGNAL: - profile_print_with_attrs ("sig", message, &t, + profile_print_with_attrs ("sig", message, sec, usec, PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_DESTINATION | @@ -214,7 +179,7 @@ print_message_profile (DBusMessage *message) PROFILE_ATTRIBUTE_FLAG_MEMBER); break; default: - printf ("%s\t%lu.%06lu", "tun", (unsigned long) t.tv_sec, (unsigned long) t.tv_usec); + printf ("%s\t%lu.%06lu", "tun", (unsigned long) sec, (unsigned long) usec); break; } } diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c index 216ebae..52e2c02 100644 --- a/tools/dbus-print-message.c +++ b/tools/dbus-print-message.c @@ -529,7 +529,7 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth) } void -print_message (DBusMessage *message, dbus_bool_t literal) +print_message (DBusMessage *message, dbus_bool_t literal, long sec, long usec) { DBusMessageIter iter; const char *sender; diff --git a/tools/dbus-print-message.h b/tools/dbus-print-message.h index 26700d8..d45bc79 100644 --- a/tools/dbus-print-message.h +++ b/tools/dbus-print-message.h @@ -26,6 +26,6 @@ #include #include -void print_message (DBusMessage *message, dbus_bool_t literal); +void print_message (DBusMessage *message, dbus_bool_t literal, long sec, long usec); #endif /* DBUS_PRINT_MESSAGE_H */ diff --git a/tools/dbus-send.c b/tools/dbus-send.c index d3ff258..354bd6d 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -573,7 +573,7 @@ main (int argc, char *argv[]) if (reply) { - print_message (reply, print_reply_literal); + print_message (reply, print_reply_literal, 0, 0); dbus_message_unref (reply); } } -- 1.8.4.5