summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Crequy <alban.crequy@collabora.co.uk>2014-08-21 15:28:41 +0100
committerWill Thompson <will@willthompson.co.uk>2018-05-09 06:33:34 +0100
commit5847d3905a86917587889814ff2f10ab3651b9d5 (patch)
tree7db13ec0e6096b443a693e26be5ba207fe4078e9
parent18400a90dbe96caeaafea91866147b804b75385c (diff)
downloadd-feet-6-display-statistics-and-match-rules-from-the-new-stats-interface.tar.gz
display statistics and match rules from the D-Bus Stats interface6-display-statistics-and-match-rules-from-the-new-stats-interface
This requires dbus 1.9.0 for the new GetAllMatchRules call on the Stats interface and for compiling the Stats interface by default. The Stats interface is enabled by default on the session bus. On the system bus, it is not enabled for non-root users by default but it can be enabled as shown in /usr/share/doc/dbus/examples/example-system-enable-stats.conf If the feature is not available in D-Bus, D-Feet ignores the error and continues as before. https://bugzilla.gnome.org/show_bug.cgi?id=735167
-rw-r--r--src/dfeet/introspection.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/dfeet/introspection.py b/src/dfeet/introspection.py
index a0bb75c..22f3905 100644
--- a/src/dfeet/introspection.py
+++ b/src/dfeet/introspection.py
@@ -158,6 +158,10 @@ class AddressInfo():
"""introspect the given bus name and update the tree model"""
# cleanup current tree model
self.__treemodel.clear()
+
+ # Statistics
+ self.__get_stats()
+
# start introspection
self.__dbus_node_introspect("/")
@@ -259,6 +263,53 @@ class AddressInfo():
None, GLib.VariantType.new("(s)"), Gio.DBusCallFlags.NONE, -1,
None, self.__dbus_node_introspect_cb, object_path)
+ def __get_stats_cb(self, connection, result_async, data):
+ """callback when the GetConnectionStats dbus function call finished"""
+ try:
+ res = connection.call_finish(result_async)
+ except:
+ # The stats interface might not be enabled. Ignore.
+ pass
+ else:
+ stats_iter = self.__treemodel.append(None, ["<b>Statistics</b>", None])
+ for k, v in sorted(res[0].items()):
+ self.__treemodel.append(stats_iter, [k + " = " + str(v), None])
+
+ def __get_match_rules_cb(self, connection, result_async, data):
+ """callback when the GetAllMatchRules dbus function call finished"""
+ try:
+ res = connection.call_finish(result_async)
+ except:
+ # The stats interface might not be enabled. Ignore.
+ pass
+ else:
+ if self.unique_name not in res[0]:
+ return
+
+ rules_iter = self.__treemodel.append(None, ["<b>Match rules</b>", None])
+ for v in res[0][self.unique_name]:
+ self.__treemodel.append(rules_iter, [v, None])
+
+ def __get_stats(self):
+ if self.name == 'org.freedesktop.DBus':
+ self.connection.call(
+ 'org.freedesktop.DBus', '/org/freedesktop/DBus',
+ 'org.freedesktop.DBus.Debug.Stats', 'GetStats',
+ None, GLib.VariantType.new("(a{sv})"), Gio.DBusCallFlags.NONE,
+ -1, None, self.__get_stats_cb, None)
+ elif self.name is not None:
+ self.connection.call(
+ 'org.freedesktop.DBus', '/org/freedesktop/DBus',
+ 'org.freedesktop.DBus.Debug.Stats', 'GetConnectionStats',
+ GLib.Variant('(s)', (self.name,)),
+ GLib.VariantType.new("(a{sv})"), Gio.DBusCallFlags.NONE,
+ -1, None, self.__get_stats_cb, None)
+ self.connection.call(
+ 'org.freedesktop.DBus', '/org/freedesktop/DBus',
+ 'org.freedesktop.DBus.Debug.Stats', 'GetAllMatchRules',
+ None, GLib.VariantType.new("(a{sas})"), Gio.DBusCallFlags.NONE, -1,
+ None, self.__get_match_rules_cb, None)
+
if __name__ == "__main__":
"""for debugging"""