On Fri, Aug 17, 2018 at 09:04:39PM +0300, Vladimir Sementsov-Ogievskiy wrote: > Render block nodes graph with help of graphviz. This new function is > for debugging, so there is no sense to put it into qemu.py as a method > of QEMUMachine. Let's instead put it separately. > > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> > --- > scripts/render_block_graph.py | 78 > +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 78 insertions(+) > create mode 100644 scripts/render_block_graph.py > > diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py > new file mode 100644 > index 0000000000..7048a0bac8 > --- /dev/null > +++ b/scripts/render_block_graph.py > @@ -0,0 +1,78 @@ > +# Render Qemu Block Graph [...]
What about making the script work from the command-line? Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py old mode 100644 new mode 100755 index 7048a0bac8..e29fe0fc41 --- a/scripts/render_block_graph.py +++ b/scripts/render_block_graph.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # Render Qemu Block Graph # # Copyright (c) 2017 Parallels International GmbH @@ -16,8 +17,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import os +import os, sys from graphviz import Digraph +from qmp.qmp import QEMUMonitorProtocol def perm(arr): s = 'w' if 'write' in arr else '_' @@ -27,16 +29,16 @@ def perm(arr): s += 's' if 'resize' in arr else '_' return s -def render_block_graph(vm, filename, pointers=False, format='png'): +def render_block_graph(qmp, filename, pointers=False, format='png'): ''' Render graph in text (dot) representation into "@filename" and representation in @format into "@filename.@format" ''' - nodes = vm.command('query-named-block-nodes') + nodes = qmp.command('query-named-block-nodes') nodes_info = {n['node-name']: n for n in nodes} - block_graph = vm.command('x-query-block-graph') + block_graph = qmp.command('x-query-block-graph') graph = Digraph(comment='Block Nodes Graph') graph.format = format @@ -76,3 +78,9 @@ def render_block_graph(vm, filename, pointers=False, format='png'): graph.edge(str(e['parent']), str(e['child']), label=label) graph.render(filename) + +if __name__ == '__main__': + #TODO: use argparse for command-line arguments + qmp = QEMUMonitorProtocol(sys.argv[1]) + qmp.connect() + render_block_graph(qmp, sys.argv[2]) -- Eduardo