Modules

jonga module

Call tracing for class method inheritance documentation

current_function(frame)[source]

Get reference to currently running function from inspect/trace stack frame.

Parameters:
frame : stack frame

Stack frame obtained via trace or inspect

Returns:
fnc : function reference

Currently running function

function_qname(fnc)[source]

Get qualified name of a function (the fully qualified name without the module prefix)

Parameters:
fnc : function reference
A function reference
Returns:
fqn : string
The qualified name the function
function_fqname(fnc)[source]

Get fully qualified name of a function

Parameters:
fnc : function reference

A function reference

Returns:
fqn : string

The fully qualified name the function

current_module_name(frame)[source]

Get name of module of currently running function from inspect/trace stack frame.

Parameters:
frame : stack frame

Stack frame obtained via trace or inspect

Returns:
modname : string

Currently running function module name

class CallTracer(srcmodflt=None, dstmodflt=None, srcqnmflt=None, dstqnmflt=None, fnmsub=None, grpflt=None, lnksub=None)[source]

Bases: object

Manage construction of a call graph for methods within a class hierarchy

__init__(srcmodflt=None, dstmodflt=None, srcqnmflt=None, dstqnmflt=None, fnmsub=None, grpflt=None, lnksub=None)[source]

Initialise a CallTracer object.

Parameters:
srcmodflt : None or regex string, optional (default None)

A regex for call filtering based on calling function module. A function call is only recorded if the regex matches the name of the calling function module. If None, filtering is disabled.

dstmodflt : None or regex string, optional (default None)

A regex for call filtering based on caller function. A function call is only recorded if the regex matches the name of the called function module. If None, filtering is disabled.

srcqnmflt : None or regex string, optional (default None)

A regex for call filtering based on calling function qname. A function call is only recorded if the regex matches the name of the calling function. If None, filtering is disabled.

dstqnmflt : None or regex string, optional (default None)

A regex for call filtering based on caller function qname. A function call is only recorded if the regex matches the name of the called function. If None, filtering is disabled.

fnmsub : None or tuple of two regex strings, optional (default None)

A tuple of match and replace regex strings for computing graph node names from function qnames. If None, node names are function qnames.

grpflt : None or regex string, optional (default None)

A regex string for extracting part of the function fqname as a group name. If None, groups are not defined.

lnksub : None or tuple of two regex strings, optional (default None)

A tuple of match and replace regex strings for computing node href attributes from node names. If None, href attributes are not defined.

reset()[source]

Reset record of called functions, deleting all accumulated call information

start()[source]

Start tracing

stop()[source]

Stop tracing

graph(fnm=None, size=None, fntsz=None, fntfm=None, clrgen=None, rmsz=False, prog='dot')[source]

Construct call graph

Parameters:
fnm : None or string, optional (default None)

Filename of graph file to be written. File type is determined by the file extentions (e.g. dot for ‘graph.dot’ and SVG for ‘graph.svg’). If None, a file is not written.

size : string or None, optional (default None)

Graph image size specification string.

fntsz : int or None, optional (default None)

Font size for text.

fntnm : string or None, optional (default None)

Font family specification string.

clrgen : function or None, optional (default None)

Function to call to generate the group colours. This function should take an integer specifying the number of groups as an argument and return a list of graphviz-compatible colour specification strings.

rmsz : bool, optional (default False)

If True, remove the width and height specifications from an SVG format output file so that the size scales properly when viewed in a web browser

prog : string, optional (default ‘dot’)

Name of graphviz layout program to use.

Returns:
pgr : pygraphviz.AGraph

Call graph of traced function calls

class ContextCallTracer(ct, pth=None, **kwargs)[source]

Bases: object

A wrapper class for CallTracer that enables its use as a context manager. At the end of the context a call graph image is generated and written to a path specified in the initialiser.

__init__(ct, pth=None, **kwargs)[source]

Initialise context manager.

Parameters:
ct : class:CallTracer object

Specify the call tracer object to be used as a context manager.

pth : string or None, optional (default None)

Specify the path of the graph image file to be written by CallTracer.graph() at the end of the context. A graph is not generated if it is None.

**kwargs

Keyword arguments for CallTracer.graph()

calltracer()[source]

Return the call tracer object associated with this ContextCallTracer instance.