summaryrefslogtreecommitdiff
path: root/tools
diff options
authorThomi Richards <thomir@gmail.com>2012-01-25 22:54:16 -0500
committerTarmac <>2012-01-25 22:54:16 -0500
commit5eabaae2cffb7f19d9dd342f6b76c22a740c18ad (patch)
tree395fb5545985977eea8ccbd0720bf46c8db1457e /tools
parentad4de44ab6cfec8d0c0c4a9893475a6a0a5cc53e (diff)
parent7dad2938143592132357e407521287356b07be4e (diff)
Added 'Debug Unity Introspection Tree' script (duit.py). Use this to quickly discover what information is available in the introspection tree.. Fixes: . Appoved by Tim Penhey, Sam Spilsbury, Alex Launi.
Original authors: - Thomi Richards <thomir@gmail.com> - Thomi Richards <thomi.richards@canonical.com> (bzr r1864)
Diffstat (limited to 'tools')
-rwxr-xr-xtools/unity-introspection-visualiser.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/tools/unity-introspection-visualiser.py b/tools/unity-introspection-visualiser.py
new file mode 100755
index 000000000..fae236e2c
--- /dev/null
+++ b/tools/unity-introspection-visualiser.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+#
+# Script to generate a nice PNG file of the currently running unity introspection tree.
+from sys import argv
+import dbus
+
+try:
+ from autopilot.emulators.unity import Unity
+except ImportError:
+ print "Error: could not import the autopilot python module."
+ print "Make sure the autopilot module is in your $PYTHONPATH."
+ exit(1)
+
+try:
+ import pydot
+except ImportError:
+ print "Error: the 'pydot' module is required to run this script."
+ print "Try installing the 'python-pydot' package."
+ exit(1)
+
+NEXT_NODE_ID=1
+
+def string_rep(dbus_type):
+ """Get a string representation of various dbus types."""
+ if type(dbus_type) == dbus.Boolean:
+ return repr(bool(dbus_type))
+ if type(dbus_type) == dbus.String:
+ return str(dbus_type)
+ if type(dbus_type) in (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64):
+ return repr(int(dbus_type))
+ if type(dbus_type) == dbus.Double:
+ return repr(float(dbus_type))
+ if type(dbus_type) == dbus.Array:
+ return ', '.join([string_rep(i) for i in dbus_type])
+ else:
+ return repr(dbus_type)
+
+
+def escape(s):
+ """Escape a string so it can be use in a dot label."""
+ return pydot.quote_if_necessary(s).replace('<','\\<').replace('>', '\\>')
+
+
+def traverse_tree(state, parent, graph):
+ """Recursively traverse state tree, building dot graph as we go."""
+ global NEXT_NODE_ID
+ lbl = parent.get_comment() + "|"
+ # first, set labels for this node:
+ bits = ["%s=%s" % (k, string_rep(state[k])) for k in state.keys() if k != 'Children']
+ lbl += "\l".join(bits)
+ parent.set_label(escape('"{' + lbl + '}"'))
+ if state.has_key('Children'):
+ # Add all array nodes as children of this node.
+ for child_name, child_state in state['Children']:
+ child = pydot.Node(str(NEXT_NODE_ID))
+ NEXT_NODE_ID+=1
+ child.set_comment(child_name)
+ graph.add_node(child)
+ graph.add_edge(pydot.Edge(parent, child))
+
+ traverse_tree(child_state, child, graph)
+
+
+if __name__ == '__main__':
+ if len(argv) != 2:
+ print """Usage: %s output_file.png.
+
+This script queries the currently running Unity process and dumps the entire
+introspection tree into a graph, and renders this to a PNG file.
+""" % (argv[0])
+ exit(1)
+
+ u = Unity()
+ introspection_tree = u.get_state()
+ graph = pydot.Dot()
+ graph.set_simplify(False)
+ graph.set_node_defaults(shape='Mrecord')
+ graph.set_fontname('Ubuntu')
+ graph.set_fontsize('10')
+
+ gnode_unity = pydot.Node("Unity")
+ gnode_unity.set_comment("Unity")
+ traverse_tree(introspection_tree[0], gnode_unity, graph)
+
+ graph.write(argv[1], format='png')
+