From f9c570d37d6738d6e4028c785ad88aafae1148fc Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Wed, 9 Feb 2011 12:02:03 +0000 Subject: [PATCH] bustle-dbus-monitor: add message size in the log The size is added in the log file both for NameOwnerChanged messages and other messages. --- bustle-dbus-monitor.c | 33 +++++++++++++++++++++++++++++---- 1 files changed, 29 insertions(+), 4 deletions(-) diff --git a/bustle-dbus-monitor.c b/bustle-dbus-monitor.c index 0ebaded..9b7cedb 100644 --- a/bustle-dbus-monitor.c +++ b/bustle-dbus-monitor.c @@ -67,8 +67,23 @@ gettimeofday (struct timeval *__p, #define PROFILE_TIMED_FORMAT "%s\t%lu\t%lu" #define TRAP_NULL_STRING(str) ((str) ? (str) : "") +static int +dbus_message_get_size (DBusMessage *message) +{ + char *buffer; + int size = -1; + int ret; + + ret = dbus_message_marshal (message, &buffer, &size); + if (!ret) + return -1; + free (buffer); + return size; +} + static void print_name_owner_changed (struct timeval *t, + int size, const char *name, const char *old_owner, const char *new_owner) @@ -79,7 +94,8 @@ print_name_owner_changed (struct timeval *t, printf (PROFILE_TIMED_FORMAT, "nameownerchanged", t->tv_sec, t->tv_usec); /* Use '!' to represent "no name here". */ - printf ("\t%s\t%s\t%s\n", name, + printf ("\t%d\t%s\t%s\t%s\n", + size, name, (*old_owner == '\0' ? "!" : old_owner), (*new_owner == '\0' ? "!" : new_owner)); } @@ -111,7 +127,8 @@ name_owner_changed_cb (DBusMessage *message) return; } - print_name_owner_changed (&t, name, old_owner, new_owner); + print_name_owner_changed (&t, dbus_message_get_size (message), + name, old_owner, new_owner); } typedef enum @@ -124,6 +141,7 @@ typedef enum PROFILE_ATTRIBUTE_FLAG_INTERFACE = 32, PROFILE_ATTRIBUTE_FLAG_MEMBER = 64, PROFILE_ATTRIBUTE_FLAG_ERROR_NAME = 128, + PROFILE_ATTRIBUTE_FLAG_SIZE = 256, } ProfileAttributeFlags; static void @@ -132,6 +150,9 @@ profile_print_with_attrs (const char *type, DBusMessage *message, { printf (PROFILE_TIMED_FORMAT, type, t->tv_sec, t->tv_usec); + if (attrs & PROFILE_ATTRIBUTE_FLAG_SIZE) + printf ("\t%d", dbus_message_get_size (message)); + if (attrs & PROFILE_ATTRIBUTE_FLAG_SERIAL) printf ("\t%u", dbus_message_get_serial (message)); @@ -174,6 +195,7 @@ print_message_profile (DBusMessage *message) { case DBUS_MESSAGE_TYPE_METHOD_CALL: profile_print_with_attrs ("mc", message, &t, + PROFILE_ATTRIBUTE_FLAG_SIZE | PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_DESTINATION | @@ -183,6 +205,7 @@ print_message_profile (DBusMessage *message) break; case DBUS_MESSAGE_TYPE_METHOD_RETURN: profile_print_with_attrs ("mr", message, &t, + PROFILE_ATTRIBUTE_FLAG_SIZE | PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_DESTINATION | @@ -190,6 +213,7 @@ print_message_profile (DBusMessage *message) break; case DBUS_MESSAGE_TYPE_ERROR: profile_print_with_attrs ("err", message, &t, + PROFILE_ATTRIBUTE_FLAG_SIZE | PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_DESTINATION | @@ -197,6 +221,7 @@ print_message_profile (DBusMessage *message) break; case DBUS_MESSAGE_TYPE_SIGNAL: profile_print_with_attrs ("sig", message, &t, + PROFILE_ATTRIBUTE_FLAG_SIZE | PROFILE_ATTRIBUTE_FLAG_SERIAL | PROFILE_ATTRIBUTE_FLAG_SENDER | PROFILE_ATTRIBUTE_FLAG_PATH | @@ -263,7 +288,7 @@ get_well_known_names (DBusConnection *connection) /* First, print the unique names */ for (i = 0; i < n_names; i++) if (*names[i] == ':') - print_name_owner_changed (&t, names[i], "", names[i]); + print_name_owner_changed (&t, 0, names[i], "", names[i]); /* Now print the well-known names */ for (i = 0; i < n_names; i++) @@ -301,7 +326,7 @@ get_well_known_names (DBusConnection *connection) return; } - print_name_owner_changed (&t, names[i], "", owner); + print_name_owner_changed (&t, 0, names[i], "", owner); } dbus_free_string_array (names); -- 1.7.2.3