diff options
| author | Thomi Richards <thomi.richards@canonical.com> | 2012-02-06 14:32:18 -0500 |
|---|---|---|
| committer | Tarmac <> | 2012-02-06 14:32:18 -0500 |
| commit | 97ff8857636c694cf1c273630dede8f7668fa422 (patch) | |
| tree | bc3ab3fce5b19e37f56d6cbe6c6fe8ff0097c5c5 | |
| parent | f4034244f9ea2a2d9231a058921f5b81e897b75f (diff) | |
| parent | c9fd689d49f996f49a39480f52e5492d75e137e0 (diff) | |
Unity introspection tree debug script now has option to display image instead of saving it to disk, and can handle any file format supported by dot.. Fixes: . Approved by Jason Smith.
(bzr r1902)
| -rwxr-xr-x | tools/unity-introspection-visualiser.py | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/tools/unity-introspection-visualiser.py b/tools/unity-introspection-visualiser.py index fae236e2c..bdefe0b51 100755 --- a/tools/unity-introspection-visualiser.py +++ b/tools/unity-introspection-visualiser.py @@ -2,7 +2,9 @@ # # Script to generate a nice PNG file of the currently running unity introspection tree. -from sys import argv +from argparse import ArgumentParser +from os import remove +from os.path import splitext import dbus try: @@ -21,6 +23,7 @@ except ImportError: NEXT_NODE_ID=1 + def string_rep(dbus_type): """Get a string representation of various dbus types.""" if type(dbus_type) == dbus.Boolean: @@ -60,16 +63,17 @@ def traverse_tree(state, parent, graph): 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. + parser = ArgumentParser() + mg = parser.add_mutually_exclusive_group(required=True) + mg.add_argument('-o', '--output', nargs=1, + help='Store output in specified file on disk.') + mg.add_argument('-d','--display', action='store_true', + help='Display output in image viewer.') -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) + args = parser.parse_args() u = Unity() introspection_tree = u.get_state() @@ -78,10 +82,27 @@ introspection tree into a graph, and renders this to a PNG file. 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') + if args.output: + base, extension = splitext(args.output[0]) + write_method_name = 'write_' + extension[1:] + if hasattr(graph, write_method_name): + getattr(graph, write_method_name)(args.output[0]) + else: + print "Error: unsupported format: '%s'" % (extension) + elif args.display: + from tempfile import NamedTemporaryFile + from subprocess import call + tf = NamedTemporaryFile(suffix='.png', delete=False) + tf.write(graph.create_png()) + tf.close() + call(["eog", tf.name]) + remove(tf.name) + else: + print 'unknown output mode!' + |
