1

The following minimal working example

from pycallgraph2 import PyCallGraph
from pycallgraph2.output import GraphvizOutput

with PyCallGraph(output=GraphvizOutput()):
    None

produces this output:

enter image description here

Why does PyCallGraph2 describe itself while profiling "Hello, World"? showed that we can exclude certain things in the namespace via the command line. Now I want to do this inside a script.

Galen
  • 1,128
  • 1
  • 14
  • 31

1 Answers1

1

I found an answer while I formulating the question. The older documentation for pycallgraph shows how to filter. If we make some necessary changes such as referring to pycallgraph2 instead of pycallgraph, we have:

from pycallgraph2 import PyCallGraph
from pycallgraph2 import Config
from pycallgraph2 import GlobbingFilter
from pycallgraph2.output import GraphvizOutput

config = Config()
config.trace_filter = GlobbingFilter(exclude=[
    'pycallgraph2.*'
])

with PyCallGraph(output=GraphvizOutput(), config=config):
    None

This gives the desired result:

enter image description here

Galen
  • 1,128
  • 1
  • 14
  • 31