Pycallgraph not generating graphd output in debug mode

921 Views Asked by At

I'm using Pycallgraph to generate output, but I want to save the intermediate graphd output (instead of generating an image) because I want to make some small modifications to it.

I'm running as:

PYTHONPATH=. pycallgraph -d graphviz -- ./ab_ndh_graph.py > out.graphd

Which is generating 2x things:

  1. pycallgraph.png -- this is the entire call graph (graphd output in out.graphd)
  2. filter_max_depth.png -- this is the code based call graph (correct, but no graphd output)

How can I get the graphd output to be generated for "filter_max_depth" instead?

File contents:

config = Config(max_depth=2)
config.trace_filter = GlobbingFilter(exclude=[
    'pycallgraph.*',
])
graphviz = GraphvizOutput(output_file='filter_max_depth.png')

with PyCallGraph(output=graphviz, config=config):
    o = AB_NDH()
    o.run()
1

There are 1 best solutions below

0
On

The GraphvizOutput class uses a temporary file to output the dot source to, and runs the dot command line tool on that file before cleaning it up again.

However, you can regenerate the same file contents rather easily by calling the generate() method after running PyCallGraph:

with open('filter_max_depth.graphd', 'w') as dotfile:
    dotfile.write(graphviz.generate())

You could also switch on the debug option of your config object; in that case the dot source is written to the log. Setting .debug flag on the config object:

config.debug = True

but then don't use -d on the command line:

PYTHONPATH=. pycallgraph graphviz -- ./ab_ndh_graph.py > out.graphd

Essentially, that's the same as adding print graphviz.generate() however.