2014-07-09 37 views
2

我使用Pycallgraph生成输出,但我想保存中间图形输出(而不是生成图像),因为我想对它进行一些小的修改。pycallgraph在调试模式下不生成图形输出

我正在为:

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

这是产生2倍的东西:

  1. pycallgraph.png - 这是整个调用图(在 out.graphd graphd输出)
  2. filter_max_depth.png - 这是基于代码的调用 图(正确,但没有图形输出)

如何才能获得为“filter_max_depth”生成的图形输出?

文件内容:

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() 

回答

0

GraphvizOutput类使用临时文件输出dot源,并再次清除它之前运行在该文件中的dot命令行工具。

但是,您可以运行PyCallGraph后再生相同的文件内容,而很容易地通过调用generate()方法:

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

你也可以打开你的config对象的调试选项;在那种情况下,dot源被写入日志。在config对象上设置.debug标志:

config.debug = True 

但随后做在命令行上不使用-d

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

从本质上讲,这是一样的但是加入print graphviz.generate()

相关问题