Sections
Timeline
View Tickets
New Ticket
Sub-Sections
Download
Unified Diff
Zip Archive
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Changeset 18

Show
Ignore:
Timestamp:
14/02/07 21:23:08 (22 months ago)
Author:
gak
Message:

Added docstrings. Renamed make_graph to make_dot_graph

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pycallgraph.py

    r16 r18  
    2727# statistical data 
    2828def reset_trace(): 
     29    """Resets all collected statistics. This is run automatically by 
     30    start_trace(reset=True) and when the module is loaded. 
     31    """ 
    2932    global call_dict 
    3033    call_dict = {} 
     
    5558# settings for building dot files 
    5659settings = { 
    57    'node_attributes': { 
     60    'node_attributes': { 
    5861       'label': r'%(func)s\ncalls: %(hits)i', 
    5962       'color': '%(col)s', 
     
    6568 
    6669class PyCallGraphException(Exception): 
     70    """Exception used for pycallgraph""" 
    6771    pass 
    6872 
     
    7175 
    7276    Objects are matched against the exclude list first, then the include list. 
    73     Anything that passes through without matching either, is excluded.""" 
     77    Anything that passes through without matching either, is excluded. 
     78    """ 
    7479    def __init__(self, include=None, exclude=None, max_depth=None): 
    7580        if include is None and exclude is None: 
     
    98103 
    99104def start_trace(reset=True, filter=None): 
     105    """Begins a trace. Setting reset to True will reset all previously recorded 
     106    trace data. filter needs to point to a callable function that accepts the 
     107    parameters (call_stack, module_name, class_name, func_name, full_name). 
     108    Every call will be passed into this function and it is up to the function 
     109    to decide if it should be included or not. Returning False means the call 
     110    will be filtered out and not included in the call graph. 
     111    """ 
    100112    global trace_filter 
    101113    if reset: 
     
    108120 
    109121def stop_trace(): 
     122    """Stops the currently running trace, if any.""" 
    110123    sys.settrace(None) 
    111124 
    112125def tracer(frame, event, arg): 
     126    """This is an internal function that is called every time a call is made 
     127    during a trace. It keeps track of relationships between calls. 
     128    """ 
    113129    global func_count_max, trace_filter 
    114130 
     
    167183 
    168184def get_dot(stop=True): 
     185    """Returns a string containing a DOT file. Setting stop to True will cause 
     186    the trace to stop. 
     187    """ 
    169188    if stop: 
    170189        stop_trace() 
     
    193212 
    194213def save_dot(filename): 
     214    """Generates a DOT file and writes it into filename.""" 
    195215    open(filename, 'w').write(get_dot()) 
    196216 
    197 def make_graph(filename, format='png', tool='dot', stop=True): 
     217def make_graph(filename, format=None, tool=None, stop=None): 
     218    """This has been changed to make_dot_graph.""" 
     219    raise PyCallGraphException( \ 
     220        "make_graph is depricated. Please use make_dot_graph") 
     221 
     222def make_dot_graph(filename, format='png', tool='dot', stop=True): 
     223    """Creates a graph using a graphviz tool that supports the dot language. It 
     224    will output into a file specified by filename with the format specified. 
     225    Setting stop to True will stop the current trace. 
     226    """ 
    198227    if stop: 
    199228        stop_trace() 
     
    210239 
    211240if __name__ == '__main__': 
    212  
    213241    f = 'test.png' 
    214242    print 'Starting trace'