From 118152459d0173d8a9c78900b9908512bb9aee45 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 Feb 2011 13:08:24 +0000 Subject: [PATCH 09/10] Also record peak values for queued bytes/fds in connection stats Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34040 --- bus/stats.c | 14 ++++++++++---- dbus/dbus-connection-internal.h | 6 +++++- dbus/dbus-connection.c | 15 +++++++++++++-- dbus/dbus-resources.c | 29 +++++++++++++++++++++++++++++ dbus/dbus-resources.h | 3 +++ dbus/dbus-transport.c | 10 +++++++++- dbus/dbus-transport.h | 4 +++- 7 files changed, 72 insertions(+), 9 deletions(-) diff --git a/bus/stats.c b/bus/stats.c index d395bc0..28fd49b 100644 --- a/bus/stats.c +++ b/bus/stats.c @@ -261,8 +261,8 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, DBusMessage *reply = NULL; DBusMessageIter iter, arr_iter; static dbus_uint32_t stats_serial = 0; - dbus_uint32_t in_messages, in_bytes, in_fds; - dbus_uint32_t out_messages, out_bytes, out_fds; + dbus_uint32_t in_messages, in_bytes, in_fds, in_peak_bytes, in_peak_fds; + dbus_uint32_t out_messages, out_bytes, out_fds, out_peak_bytes, out_peak_fds; BusRegistry *registry; BusService *service; DBusConnection *stats_connection; @@ -313,14 +313,20 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, _dbus_connection_get_stats (stats_connection, &in_messages, &in_bytes, &in_fds, - &out_messages, &out_bytes, &out_fds); + &in_peak_bytes, &in_peak_fds, + &out_messages, &out_bytes, &out_fds, + &out_peak_bytes, &out_peak_fds); if (!asv_add_uint32 (&iter, &arr_iter, "IncomingMessages", in_messages) || !asv_add_uint32 (&iter, &arr_iter, "IncomingBytes", in_bytes) || !asv_add_uint32 (&iter, &arr_iter, "IncomingFDs", in_fds) || + !asv_add_uint32 (&iter, &arr_iter, "PeakIncomingBytes", in_peak_bytes) || + !asv_add_uint32 (&iter, &arr_iter, "PeakIncomingFDs", in_peak_fds) || !asv_add_uint32 (&iter, &arr_iter, "OutgoingMessages", out_messages) || !asv_add_uint32 (&iter, &arr_iter, "OutgoingBytes", out_bytes) || - !asv_add_uint32 (&iter, &arr_iter, "OutgoingFDs", out_fds)) + !asv_add_uint32 (&iter, &arr_iter, "OutgoingFDs", out_fds) || + !asv_add_uint32 (&iter, &arr_iter, "PeakOutgoingBytes", out_peak_bytes) || + !asv_add_uint32 (&iter, &arr_iter, "PeakOutgoingFDs", out_peak_fds)) goto oom; /* end */ diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index 60d5145..3dc5989 100644 --- a/dbus/dbus-connection-internal.h +++ b/dbus/dbus-connection-internal.h @@ -108,9 +108,13 @@ 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 *in_peak_bytes, + dbus_uint32_t *in_peak_fds, dbus_uint32_t *out_messages, dbus_uint32_t *out_bytes, - dbus_uint32_t *out_fds); + dbus_uint32_t *out_fds, + dbus_uint32_t *out_peak_bytes, + dbus_uint32_t *out_peak_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 83d1978..7d5a8ef 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -6204,16 +6204,21 @@ _dbus_connection_get_stats (DBusConnection *connection, dbus_uint32_t *in_messages, dbus_uint32_t *in_bytes, dbus_uint32_t *in_fds, + dbus_uint32_t *in_peak_bytes, + dbus_uint32_t *in_peak_fds, dbus_uint32_t *out_messages, dbus_uint32_t *out_bytes, - dbus_uint32_t *out_fds) + dbus_uint32_t *out_fds, + dbus_uint32_t *out_peak_bytes, + dbus_uint32_t *out_peak_fds) { CONNECTION_LOCK (connection); if (in_messages != NULL) *in_messages = connection->n_incoming; - _dbus_transport_get_stats (connection->transport, in_bytes, in_fds); + _dbus_transport_get_stats (connection->transport, + in_bytes, in_fds, in_peak_bytes, in_peak_fds); if (out_messages != NULL) *out_messages = connection->n_outgoing; @@ -6224,6 +6229,12 @@ _dbus_connection_get_stats (DBusConnection *connection, if (out_fds != NULL) *out_fds = _dbus_counter_get_unix_fd_value (connection->outgoing_counter); + if (out_peak_bytes != NULL) + *out_peak_bytes = _dbus_counter_get_peak_size_value (connection->outgoing_counter); + + if (out_peak_fds != NULL) + *out_peak_fds = _dbus_counter_get_peak_unix_fd_value (connection->outgoing_counter); + CONNECTION_UNLOCK (connection); } #endif /* DBUS_ENABLE_STATS */ diff --git a/dbus/dbus-resources.c b/dbus/dbus-resources.c index 5f7001c..b4ba448 100644 --- a/dbus/dbus-resources.c +++ b/dbus/dbus-resources.c @@ -58,6 +58,11 @@ struct DBusCounter long size_value; /**< current size counter value */ long unix_fd_value; /**< current unix fd counter value */ +#ifdef DBUS_ENABLE_STATS + long peak_size_value; /**< largest ever size counter value */ + long peak_unix_fd_value; /**< largest ever unix fd counter value */ +#endif + long notify_size_guard_value; /**< call notify function when crossing this size value */ long notify_unix_fd_guard_value; /**< call notify function when crossing this unix fd value */ @@ -152,6 +157,11 @@ _dbus_counter_adjust_size (DBusCounter *counter, counter->size_value += delta; +#ifdef DBUS_ENABLE_STATS + if (counter->peak_size_value < counter->size_value) + counter->peak_size_value = counter->size_value; +#endif + #if 0 _dbus_verbose ("Adjusting counter %ld by %ld = %ld\n", old, delta, counter->size_value); @@ -182,6 +192,11 @@ _dbus_counter_adjust_unix_fd (DBusCounter *counter, counter->unix_fd_value += delta; +#ifdef DBUS_ENABLE_STATS + if (counter->peak_unix_fd_value < counter->unix_fd_value) + counter->peak_unix_fd_value = counter->unix_fd_value; +#endif + #if 0 _dbus_verbose ("Adjusting counter %ld by %ld = %ld\n", old, delta, counter->unix_fd_value); @@ -243,4 +258,18 @@ _dbus_counter_set_notify (DBusCounter *counter, counter->notify_data = user_data; } +#ifdef DBUS_ENABLE_STATS +long +_dbus_counter_get_peak_size_value (DBusCounter *counter) +{ + return counter->peak_size_value; +} + +long +_dbus_counter_get_peak_unix_fd_value (DBusCounter *counter) +{ + return counter->peak_unix_fd_value; +} +#endif + /** @} */ /* end of resource limits exported API */ diff --git a/dbus/dbus-resources.h b/dbus/dbus-resources.h index 4763a97..ebbdce9 100644 --- a/dbus/dbus-resources.h +++ b/dbus/dbus-resources.h @@ -51,6 +51,9 @@ void _dbus_counter_set_notify (DBusCounter *counter, DBusCounterNotifyFunction function, void *user_data); +/* if DBUS_ENABLE_STATS */ +long _dbus_counter_get_peak_size_value (DBusCounter *counter); +long _dbus_counter_get_peak_unix_fd_value (DBusCounter *counter); DBUS_END_DECLS diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index f95e8c9..7464b0f 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -1494,13 +1494,21 @@ _dbus_transport_set_allow_anonymous (DBusTransport *transport, void _dbus_transport_get_stats (DBusTransport *transport, dbus_uint32_t *queue_bytes, - dbus_uint32_t *queue_fds) + dbus_uint32_t *queue_fds, + dbus_uint32_t *peak_queue_bytes, + dbus_uint32_t *peak_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); + + if (peak_queue_bytes != NULL) + *peak_queue_bytes = _dbus_counter_get_peak_size_value (transport->live_messages); + + if (peak_queue_fds != NULL) + *peak_queue_fds = _dbus_counter_get_peak_unix_fd_value (transport->live_messages); } #endif /* DBUS_ENABLE_STATS */ diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h index 0aeab18..4b82151 100644 --- a/dbus/dbus-transport.h +++ b/dbus/dbus-transport.h @@ -100,7 +100,9 @@ void _dbus_transport_set_allow_anonymous (DBusTransport /* if DBUS_ENABLE_STATS */ void _dbus_transport_get_stats (DBusTransport *transport, dbus_uint32_t *queue_bytes, - dbus_uint32_t *queue_fds); + dbus_uint32_t *queue_fds, + dbus_uint32_t *peak_queue_bytes, + dbus_uint32_t *peak_queue_fds); DBUS_END_DECLS -- 1.7.2.3