From 793e55c244e59f150d080e2822405d1034c870e1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 Feb 2011 12:51:33 +0000 Subject: [PATCH 07/10] DBusConnection, DBusTransport: add queue statistics Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34040 --- dbus/dbus-connection-internal.h | 9 +++++++++ dbus/dbus-connection.c | 30 ++++++++++++++++++++++++++++++ dbus/dbus-transport.c | 14 ++++++++++++++ dbus/dbus-transport.h | 4 ++++ 4 files changed, 57 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index cdf3f59..60d5145 100644 --- a/dbus/dbus-connection-internal.h +++ b/dbus/dbus-connection-internal.h @@ -103,6 +103,15 @@ void _dbus_connection_test_get_locks (DBusConnectio DBusCondVar **dispatch_cond_loc, DBusCondVar **io_path_cond_loc); +/* if DBUS_ENABLE_STATS */ +void _dbus_connection_get_stats (DBusConnection *connection, + dbus_uint32_t *in_messages, + dbus_uint32_t *in_bytes, + dbus_uint32_t *in_fds, + dbus_uint32_t *out_messages, + dbus_uint32_t *out_bytes, + dbus_uint32_t *out_fds); + /* This _dbus_bus_* stuff doesn't really belong here, but dbus-bus-internal.h seems * silly for one function */ diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 6779b6a..83d1978 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -6198,6 +6198,36 @@ dbus_connection_get_outgoing_size (DBusConnection *connection) return res; } +#ifdef DBUS_ENABLE_STATS +void +_dbus_connection_get_stats (DBusConnection *connection, + dbus_uint32_t *in_messages, + dbus_uint32_t *in_bytes, + dbus_uint32_t *in_fds, + dbus_uint32_t *out_messages, + dbus_uint32_t *out_bytes, + dbus_uint32_t *out_fds) +{ + CONNECTION_LOCK (connection); + + if (in_messages != NULL) + *in_messages = connection->n_incoming; + + _dbus_transport_get_stats (connection->transport, in_bytes, in_fds); + + if (out_messages != NULL) + *out_messages = connection->n_outgoing; + + if (out_bytes != NULL) + *out_bytes = _dbus_counter_get_size_value (connection->outgoing_counter); + + if (out_fds != NULL) + *out_fds = _dbus_counter_get_unix_fd_value (connection->outgoing_counter); + + CONNECTION_UNLOCK (connection); +} +#endif /* DBUS_ENABLE_STATS */ + /** * Gets the approximate number of uni fds of all messages in the * outgoing message queue. diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index a078f7c..f95e8c9 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -1490,4 +1490,18 @@ _dbus_transport_set_allow_anonymous (DBusTransport *transport, transport->allow_anonymous = value != FALSE; } +#ifdef DBUS_ENABLE_STATS +void +_dbus_transport_get_stats (DBusTransport *transport, + dbus_uint32_t *queue_bytes, + dbus_uint32_t *queue_fds) +{ + if (queue_bytes != NULL) + *queue_bytes = _dbus_counter_get_size_value (transport->live_messages); + + if (queue_fds != NULL) + *queue_fds = _dbus_counter_get_unix_fd_value (transport->live_messages); +} +#endif /* DBUS_ENABLE_STATS */ + /** @} */ diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h index 0db048a..0aeab18 100644 --- a/dbus/dbus-transport.h +++ b/dbus/dbus-transport.h @@ -97,6 +97,10 @@ dbus_bool_t _dbus_transport_set_auth_mechanisms (DBusTransport void _dbus_transport_set_allow_anonymous (DBusTransport *transport, dbus_bool_t value); +/* if DBUS_ENABLE_STATS */ +void _dbus_transport_get_stats (DBusTransport *transport, + dbus_uint32_t *queue_bytes, + dbus_uint32_t *queue_fds); DBUS_END_DECLS -- 1.7.2.3