output.Output — Base class for all output modules¶
Every output module subclasses pycallgraph.output.Output and
implements done() to write the collected
trace out in its own format.
- class pycallgraph.output.Output(**kwargs)[source]¶
Base class for all outputters.
- normalize_path(path)[source]¶
Expand both
~and environment variables inpath.A path may legitimately use both forms (
~/graphs/$RUN.json), so each expansion is applied in turn rather than choosing between them.
- sanity_check()[source]¶
Basic checks for certain libraries or external applications. Raise or warn if there is a problem.
- set_config(config)[source]¶
Move the output options from a Config onto this output.
Only attributes the output already declares (typically its constructor defaults, set from the command line as output options) are copied. This used to copy every attribute of the config unless the output had a callable of the same name, which put the argparse parser, the selected output-type name and unrelated config state onto the output.
Concrete outputs¶
These are the outputs registered by default and selectable from the command line. See Outputs in the guide for what each one produces.
- class pycallgraph.output.GephiOutput(**kwargs)[source]¶
Writing your own output¶
Subclass pycallgraph.output.Output, implement done(), and pass an
instance to pycallgraph.PyCallGraph (or to the trace decorator):
from pycallgraph import PyCallGraph
from pycallgraph.output import Output
class LengthOutput(Output):
'''Print how many functions were traced.'''
def __init__(self, **kwargs):
self.output_file = None
Output.__init__(self, **kwargs)
def done(self):
self.verbose('traced {0} functions'.format(
len(self.processor.call_dict)))
with PyCallGraph(output=LengthOutput()):
my_main_function()
Useful attributes available in done():
self.processor– theTraceProcessorthat holds the collected statistics.self.output_file– set it (usually from a--output-fileargument) and callnormalize_path()before opening it, so~and environment variables are expanded.
Register a class in pycallgraph.output.outputters if it should also be
selectable from the command line. Implement add_arguments to declare its
own options.