From 5d7e3ca16e1c07e4b7a90eaba5059ed6e90977ec Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 17 Feb 2015 08:22:13 +0100 Subject: [PATCH 1/3] dbus-monitor: Add timestamp to --monitor mode. Refactor related code to use cross platform function _dbus_get_real_time() instead of gettimeofday(). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88896 --- cmake/tools/CMakeLists.txt | 3 +- dbus/dbus-internals.h | 2 +- tools/dbus-monitor.c | 77 +++++++++++++--------------------------------- tools/dbus-print-message.c | 17 +++++++--- tools/dbus-print-message.h | 2 +- tools/dbus-send.c | 2 +- 6 files changed, 38 insertions(+), 65 deletions(-) diff --git a/cmake/tools/CMakeLists.txt b/cmake/tools/CMakeLists.txt index 525dc05..d0f6e02 100644 --- a/cmake/tools/CMakeLists.txt +++ b/cmake/tools/CMakeLists.txt @@ -62,7 +62,8 @@ endif (DBUS_BUILD_X11) install_targets(/bin dbus-launch ) add_executable(dbus-monitor ${dbus_monitor_SOURCES}) -target_link_libraries(dbus-monitor ${DBUS_LIBRARIES}) +set_target_properties(dbus-monitor PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) +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/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 e4b8c8a..398b8e8 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; @@ -542,10 +542,17 @@ print_message (DBusMessage *message, dbus_bool_t literal) if (!literal) { - printf ("%s sender=%s -> dest=%s", - type_to_name (message_type), - sender ? sender : "(null sender)", - destination ? destination : "(null destination)"); + if (sec == 0) + printf ("%s sender=%s -> dest=%s", + type_to_name (message_type), + sender ? sender : "(null sender)", + destination ? destination : "(null destination)"); + else + printf ("%s time=%lu.%06lu sender=%s -> dest=%s", + type_to_name (message_type), + (unsigned long) sec, (unsigned long) usec, + sender ? sender : "(null sender)", + destination ? destination : "(null destination)"); switch (message_type) { 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