From fc983cf9f43ade592ccf7abaf0de4994984bfd10 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 Feb 2011 12:31:08 +0000 Subject: [PATCH 06/10] BusConnections: add usage stats for well-known names, match rules Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34040 --- bus/connection.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bus/connection.h | 13 ++++++ 2 files changed, 133 insertions(+), 0 deletions(-) diff --git a/bus/connection.c b/bus/connection.c index 8e7d222..139bc2c 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -62,6 +62,16 @@ struct BusConnections DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */ int stamp; /**< Incrementing number */ BusExpireList *pending_replies; /**< List of pending replies */ + +#ifdef DBUS_ENABLE_STATS + int total_match_rules; + int peak_match_rules; + int peak_match_rules_per_conn; + + int total_bus_names; + int peak_bus_names; + int peak_bus_names_per_conn; +#endif }; static dbus_int32_t connection_data_slot = -1; @@ -87,6 +97,11 @@ typedef struct long connection_tv_sec; /**< Time when we connected (seconds component) */ long connection_tv_usec; /**< Time when we connected (microsec component) */ int stamp; /**< connections->stamp last time we were traversed */ + +#ifdef DBUS_ENABLE_STATS + int peak_match_rules; + int peak_bus_names; +#endif } BusConnectionData; static dbus_bool_t bus_pending_reply_expired (BusExpireList *list, @@ -1224,6 +1239,16 @@ bus_connection_send_oom_error (DBusConnection *connection, d->oom_preallocated = NULL; } +#ifdef DBUS_ENABLE_STATS +static void +update_peak (int *peak, + int n) +{ + if (*peak < n) + *peak = n; +} +#endif + void bus_connection_add_match_rule_link (DBusConnection *connection, DBusList *link) @@ -1236,6 +1261,15 @@ bus_connection_add_match_rule_link (DBusConnection *connection, _dbus_list_append_link (&d->match_rules, link); d->n_match_rules += 1; + +#ifdef DBUS_ENABLE_STATS + update_peak (&d->peak_match_rules, d->n_match_rules); + update_peak (&d->connections->peak_match_rules_per_conn, d->n_match_rules); + + d->connections->total_match_rules += 1; + update_peak (&d->connections->peak_match_rules, + d->connections->total_match_rules); +#endif } dbus_bool_t @@ -1267,6 +1301,10 @@ bus_connection_remove_match_rule (DBusConnection *connection, d->n_match_rules -= 1; _dbus_assert (d->n_match_rules >= 0); + +#ifdef DBUS_ENABLE_STATS + d->connections->total_match_rules -= 1; +#endif } int @@ -1292,6 +1330,16 @@ bus_connection_add_owned_service_link (DBusConnection *connection, _dbus_list_append_link (&d->services_owned, link); d->n_services_owned += 1; + +#ifdef DBUS_ENABLE_STATS + update_peak (&d->peak_bus_names, d->n_services_owned); + update_peak (&d->connections->peak_bus_names_per_conn, + d->n_services_owned); + + d->connections->total_bus_names += 1; + update_peak (&d->connections->peak_bus_names, + d->connections->total_bus_names); +#endif } dbus_bool_t @@ -1323,6 +1371,10 @@ bus_connection_remove_owned_service (DBusConnection *connection, d->n_services_owned -= 1; _dbus_assert (d->n_services_owned >= 0); + +#ifdef DBUS_ENABLE_STATS + d->connections->total_bus_names -= 1; +#endif } int @@ -2306,3 +2358,71 @@ bus_transaction_add_cancel_hook (BusTransaction *transaction, return TRUE; } + +#ifdef DBUS_ENABLE_STATS +int +bus_connections_get_n_active (BusConnections *connections) +{ + return connections->n_completed; +} + +int +bus_connections_get_n_incomplete (BusConnections *connections) +{ + return connections->n_incomplete; +} + +int +bus_connections_get_total_match_rules (BusConnections *connections) +{ + return connections->total_match_rules; +} + +int +bus_connections_get_peak_match_rules (BusConnections *connections) +{ + return connections->peak_match_rules; +} + +int +bus_connections_get_peak_match_rules_per_conn (BusConnections *connections) +{ + return connections->peak_match_rules_per_conn; +} + +int +bus_connections_get_total_bus_names (BusConnections *connections) +{ + return connections->total_bus_names; +} + +int +bus_connections_get_peak_bus_names (BusConnections *connections) +{ + return connections->peak_bus_names; +} + +int +bus_connections_get_peak_bus_names_per_conn (BusConnections *connections) +{ + return connections->peak_bus_names_per_conn; +} + +int +bus_connection_get_peak_match_rules (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + return d->peak_match_rules; +} + +int +bus_connection_get_peak_bus_names (DBusConnection *connection) +{ + BusConnectionData *d; + + d = BUS_CONNECTION_DATA (connection); + return d->peak_bus_names; +} +#endif /* DBUS_ENABLE_STATS */ diff --git a/bus/connection.h b/bus/connection.h index 4b9a754..c936021 100644 --- a/bus/connection.h +++ b/bus/connection.h @@ -138,4 +138,17 @@ dbus_bool_t bus_transaction_add_cancel_hook (BusTransaction * void *data, DBusFreeFunction free_data_function); +/* called by stats.c, only present if DBUS_ENABLE_STATS */ +int bus_connections_get_n_active (BusConnections *connections); +int bus_connections_get_n_incomplete (BusConnections *connections); +int bus_connections_get_total_match_rules (BusConnections *connections); +int bus_connections_get_peak_match_rules (BusConnections *connections); +int bus_connections_get_peak_match_rules_per_conn (BusConnections *connections); +int bus_connections_get_total_bus_names (BusConnections *connections); +int bus_connections_get_peak_bus_names (BusConnections *connections); +int bus_connections_get_peak_bus_names_per_conn (BusConnections *connections); + +int bus_connection_get_peak_match_rules (DBusConnection *connection); +int bus_connection_get_peak_bus_names (DBusConnection *connection); + #endif /* BUS_CONNECTION_H */ -- 1.7.2.3