def inner(*args, **kwds): try: graphviz = GraphvizOutput() graphviz.output_file = "{fold}_{count}.{type}".format( fold=os.path.join(self.output_folder, func.__name__), count=self.graph_count, type=self.output_type) graphviz.output_type = self.output_type self.graph_count += 1 with PyCallGraph(output=graphviz): return func(*args, **kwds) except: return func(*args, **kwds)
def gscontext(filename, exclude=None, max_depth=None): """Generate a call graph for the enclosed context Output a call graph to the chosen filename (introspecting the format along the way), optionally excluding some items. Args: filename (str): The output filename exclude (Optional[list]): The globbing strings to exclude. Defaults to ['graphstack.*']. max_depth (Optional[int]): The maximum recursion depth to plot. Defaults to infinite. """ globkwargs = { 'exclude': [ 'graphstack.*', ], } if exclude is not None: globkwargs['exclude'].extend(exclude) if max_depth is not None: globkwargs['max_depth'] = max_depth # Configure exclusion filtering config = Config() config.trace_filter = GlobbingFilter(**globkwargs) # Configure GraphViz output fnsplit = os.path.splitext(filename) if len(fnsplit) == 1: outfile = filename + '.pdf' filetype = 'pdf' elif len(fnsplit) == 2: outfile = filename filetype = fnsplit[1][1:] graphviz = GraphvizOutput(output_file=outfile) graphviz.output_type = filetype # Set up context manager with PyCallGraph(output=graphviz, config=config): yield
config.trace_grouper = Grouper(groups=[ "csv2df.reader.*" , "csv2df.parser.*" , "csv2df.emitter.*" , "csv2df.validator.*" , # currently not used "csv2df.runner.*" , 'csv2df.util_row_splitter.*', 'csv2df.specification.*', ]) config.trace_filter = GlobbingFilter config.trace_filter = GlobbingFilter(exclude=[ 'csv2df.util_row_splitter.*', 'csv2df.specification.*', "csv2df.reader.*" , "config.*" , ]) graphviz = GraphvizOutput() graphviz.output_file = 'pcg_example_Vintage.svg' graphviz.output_type = 'svg' with PyCallGraph(output=graphviz, config=config): #################### END PyCallGraph "decoration" vint = Vintage(year, month)
from pycallgraph import PyCallGraph, Config from pycallgraph.output import GraphvizOutput import pendulum config = Config() config.include_stdlib = True config.debug = True config.verbose = True output = GraphvizOutput() output.output_file = "pendulum_parse_call_graph.png" output.output_type = "png" with PyCallGraph(output=output, config=config): date = pendulum.parse("2018-01-01") output = GraphvizOutput() output.output_file = "pendulum_parse_bad_call_graph.png" output.output_type = "png" with PyCallGraph(output=output, config=config): try: date = pendulum.parse("15512-412") except Exception: pass output = GraphvizOutput() output.output_file = "pendulum_parse_strict_bad_call_graph.png" output.output_type = "png" with PyCallGraph(output=output, config=config): try: date = pendulum.parse("18-01-01", strict=True)