如何使用过滤器从 pycallgraph 中删除整个调用树
How do I remove an entire call tree from pycallgraph with a filter
我想看看我一直在处理的 python3 包中的特定操作发生了什么。我使用 pycallgraph,它看起来很棒。但我不知道如何从输出中删除整个调用树。
我做了一个快速脚本make_call_graphs.py
:
import doms.client.schedule as sched
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
from pycallgraph import Config
from pycallgraph import GlobbingFilter
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
'_find_and_load',
'_find_and_load.*', # Tried a few similar variations
'_handle_fromlist',
'_handle_fromlist.*',
])
with PyCallGraph(output=GraphvizOutput(output_file='schedule_hourly_call_graph.png'), config=config):
sched.hourly()
在我开始使用 GlobbingFilter
之前,_find_and_load
位于我的 doms
库调用堆栈之外的树的顶部。过滤器似乎只删除了顶级块,但每个后续调用都保留在输出中。 (请参阅下面的之前和之后)
显然我可以读取结果并将我不想看到的每个调用都复制到过滤器中,但这很愚蠢。我该怎么做才能删除 doms
框外的所有内容?有 RecursiveFilter
或我可以使用的东西吗?
之前:
后:
解决方案比我原先想象的要容易得多,而且就在我面前:include
kwarg 给 GlobbingFilter
。
config.trace_filter = GlobbingFilter(include=['__main__', 'doms.*'])
我想看看我一直在处理的 python3 包中的特定操作发生了什么。我使用 pycallgraph,它看起来很棒。但我不知道如何从输出中删除整个调用树。
我做了一个快速脚本make_call_graphs.py
:
import doms.client.schedule as sched
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
from pycallgraph import Config
from pycallgraph import GlobbingFilter
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
'_find_and_load',
'_find_and_load.*', # Tried a few similar variations
'_handle_fromlist',
'_handle_fromlist.*',
])
with PyCallGraph(output=GraphvizOutput(output_file='schedule_hourly_call_graph.png'), config=config):
sched.hourly()
在我开始使用 GlobbingFilter
之前,_find_and_load
位于我的 doms
库调用堆栈之外的树的顶部。过滤器似乎只删除了顶级块,但每个后续调用都保留在输出中。 (请参阅下面的之前和之后)
显然我可以读取结果并将我不想看到的每个调用都复制到过滤器中,但这很愚蠢。我该怎么做才能删除 doms
框外的所有内容?有 RecursiveFilter
或我可以使用的东西吗?
之前:
解决方案比我原先想象的要容易得多,而且就在我面前:include
kwarg 给 GlobbingFilter
。
config.trace_filter = GlobbingFilter(include=['__main__', 'doms.*'])