Changeset 18
- Timestamp:
- 14/02/07 21:23:08 (22 months ago)
- Files:
-
- 1 modified
-
trunk/pycallgraph.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pycallgraph.py
r16 r18 27 27 # statistical data 28 28 def reset_trace(): 29 """Resets all collected statistics. This is run automatically by 30 start_trace(reset=True) and when the module is loaded. 31 """ 29 32 global call_dict 30 33 call_dict = {} … … 55 58 # settings for building dot files 56 59 settings = { 57 'node_attributes': {60 'node_attributes': { 58 61 'label': r'%(func)s\ncalls: %(hits)i', 59 62 'color': '%(col)s', … … 65 68 66 69 class PyCallGraphException(Exception): 70 """Exception used for pycallgraph""" 67 71 pass 68 72 … … 71 75 72 76 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 """ 74 79 def __init__(self, include=None, exclude=None, max_depth=None): 75 80 if include is None and exclude is None: … … 98 103 99 104 def 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 """ 100 112 global trace_filter 101 113 if reset: … … 108 120 109 121 def stop_trace(): 122 """Stops the currently running trace, if any.""" 110 123 sys.settrace(None) 111 124 112 125 def 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 """ 113 129 global func_count_max, trace_filter 114 130 … … 167 183 168 184 def get_dot(stop=True): 185 """Returns a string containing a DOT file. Setting stop to True will cause 186 the trace to stop. 187 """ 169 188 if stop: 170 189 stop_trace() … … 193 212 194 213 def save_dot(filename): 214 """Generates a DOT file and writes it into filename.""" 195 215 open(filename, 'w').write(get_dot()) 196 216 197 def make_graph(filename, format='png', tool='dot', stop=True): 217 def 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 222 def 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 """ 198 227 if stop: 199 228 stop_trace() … … 210 239 211 240 if __name__ == '__main__': 212 213 241 f = 'test.png' 214 242 print 'Starting trace'