Changeset 45
- Timestamp:
- 24/06/07 05:55:07 (17 months ago)
- Location:
- trunk/examples
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/basic.py
r42 r45 39 39 pass 40 40 41 banana = Banana() 42 banana.eat() 41 def main(): 42 banana = Banana() 43 banana.eat() 44 pycallgraph.make_dot_graph('basic.png') 43 45 44 pycallgraph.make_dot_graph('basic.png') 46 if __name__ == '__main__': 47 main() 45 48 46 49 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: -
trunk/examples/colours.py
r42 r45 1 #!/usr/bin/env python1 #!/usr/bin/env python 2 2 """ 3 3 pycallgraph … … 25 25 This example demonstrates several different methods on colouring your graph. 26 26 27 See U{http://www.graphviz.org/doc/info/attrs.html #k:color} for details on how27 See U{http://www.graphviz.org/doc/info/attrs.html #k:color} for details on how 28 28 to return colour formats to Graphviz. 29 29 """ … … 33 33 import pycallgraph 34 34 35 # Do the trace, remember the values for later 36 pycallgraph.start_trace() 37 import HTMLParser 38 pycallgraph.stop_trace() 35 def main(): 36 # Do the trace, remember the values for later 37 pycallgraph.start_trace() 38 import HTMLParser 39 pycallgraph.stop_trace() 39 40 40 # Set the edge colour to black for all examples41 pycallgraph.settings['edge_colour'] = lambda a, b: 'black'41 # Set the edge colour to black for all examples 42 pycallgraph.settings['edge_colour'] = lambda a, b: 'black' 42 43 43 # Default node colouring44 pycallgraph.make_dot_graph('colours-default.png')44 # Default node colouring 45 pycallgraph.make_dot_graph('colours-default.png') 45 46 46 # Rainbow47 def rainbow(calls, total_time):48 """Colour using only changes in hue.47 # Rainbow 48 def rainbow(calls, total_time): 49 """Colour using only changes in hue. 49 50 50 It will go from 0 to 0.8 which is red, orange, yellow, green, cyani, blue51 then purple.51 It will go from 0 to 0.8 which is red, orange, yellow, green, cyani, blue 52 then purple. 52 53 53 See U{http://en.wikipedia.org/wiki/Hue} for more information on hue.54 """55 return '%f 0.8 0.8' % (calls * 0.8)54 See U{http://en.wikipedia.org/wiki/Hue} for more information on hue. 55 """ 56 return '%f 0.8 0.8' % (calls * 0.8) 56 57 57 pycallgraph.settings['node_colour'] = rainbow58 pycallgraph.make_dot_graph('colours-rainbow.png')58 pycallgraph.settings['node_colour'] = rainbow 59 pycallgraph.make_dot_graph('colours-rainbow.png') 59 60 60 # Greyscale61 def greyscale(calls, total_time):62 """Goes from dark grey to a light grey."""63 return '0 0 %f' % (calls / 2 + 0.4)61 # Greyscale 62 def greyscale(calls, total_time): 63 """Goes from dark grey to a light grey.""" 64 return '0 0 %f' % (calls / 2 + 0.4) 64 65 65 pycallgraph.settings['node_colour'] = greyscale66 pycallgraph.make_dot_graph('colours-greyscale.png')66 pycallgraph.settings['node_colour'] = greyscale 67 pycallgraph.make_dot_graph('colours-greyscale.png') 67 68 68 # Differences between calls and total time69 def orange_green(calls, total_time):70 """Make a higher total time have an orange colour and a higher number of71 calls have a green colour using RGB.72 """73 return '#%02X%02X%02X' % (74 0x30 + total_time * 0xc0,75 0x30 + calls * 0xc0 + total_time * 0x70,76 0x30,77 )69 # Differences between calls and total time 70 def orange_green(calls, total_time): 71 """Make a higher total time have an orange colour and a higher number of 72 calls have a green colour using RGB. 73 """ 74 return ' #%02X%02X%02X' % ( 75 0x30 + total_time * 0xc0, 76 0x30 + calls * 0xc0 + total_time * 0x70, 77 0x30, 78 ) 78 79 79 pycallgraph.settings['node_colour'] = orange_green80 pycallgraph.make_dot_graph('colours-orange-green.png')80 pycallgraph.settings['node_colour'] = orange_green 81 pycallgraph.make_dot_graph('colours-orange-green.png') 81 82 82 # Random!83 def rand(calls, total_time):84 """Random with a touch of usefulness"""85 return '%f %f %f' % (random.random(), calls * 0.5 + 0.5, calls * 0.5 + 0.5)83 # Random! 84 def rand(calls, total_time): 85 """Random with a touch of usefulness""" 86 return '%f %f %f' % (random.random(), calls * 0.5 + 0.5, calls * 0.5 + 0.5) 86 87 87 pycallgraph.settings['node_colour'] = rand88 pycallgraph.make_dot_graph('colours-random.png')88 pycallgraph.settings['node_colour'] = rand 89 pycallgraph.make_dot_graph('colours-random.png') 89 90 91 if __name__ == '__main__': 92 main() 90 93 94 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: -
trunk/examples/filter.py
r42 r45 65 65 pycallgraph.make_dot_graph('filter-max-depth.png') 66 66 67 filter_exclude() 68 filter_include() 69 filter_max_depth() 67 def main(): 68 filter_exclude() 69 filter_include() 70 filter_max_depth() 71 72 if __name__ == '__main__': 73 main() 70 74 71 75 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: -
trunk/examples/import.py
r42 r45 28 28 import pycallgraph 29 29 30 pycallgraph.settings['dont_exclude_anything'] = True 30 def main(): 31 pycallgraph.settings['dont_exclude_anything'] = True 32 import_list = ['pickle', 'htmllib'] 31 33 32 import_list = ['pickle', 'htmllib'] 34 for imp in import_list: 35 pycallgraph.start_trace() 36 __import__(imp) 37 pycallgraph.make_dot_graph('import-%s.png' % imp) 33 38 34 for imp in import_list: 35 pycallgraph.start_trace() 36 __import__(imp) 37 pycallgraph.make_dot_graph('import-%s.png' % imp) 39 if __name__ == '__main__': 40 main() 38 41 39 42 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: -
trunk/examples/large.py
r42 r45 29 29 import pycallgraph 30 30 31 pycallgraph.start_trace() 32 import urllib 33 from xml.dom.minidom import parse, parseString 34 parseString(urllib.urlopen('http://w3.org/').read()) 35 pycallgraph.make_dot_graph('large.png') 31 def main(): 32 pycallgraph.start_trace() 33 import urllib 34 from xml.dom.minidom import parse, parseString 35 parseString(urllib.urlopen('http://w3.org/').read()) 36 pycallgraph.make_dot_graph('large.png') 37 38 if __name__ == '__main__': 39 main() 36 40 37 41 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: -
trunk/examples/recursive.py
r42 r45 36 36 return n * factorial(n-1) 37 37 38 for a in xrange(1, 10):39 print factorial(a)40 38 41 pycallgraph.make_dot_graph('recursive.png') 39 def main(self): 40 for a in xrange(1, 10): 41 print factorial(a) 42 43 pycallgraph.make_dot_graph('recursive.png') 44 45 if __name__ == '__main__': 46 main() 42 47 43 48 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: -
trunk/examples/regexp.py
r42 r45 28 28 import re 29 29 30 pycallgraph.start_trace() 30 def main(): 31 pycallgraph.start_trace() 32 re.search('(hel[j-s]o).*(th[^e]*ere)', 'hello there') 33 pycallgraph.make_dot_graph('regexp.png') 31 34 32 re.search('(hel[j-s]o).*(th[^e]*ere)', 'hello there') 33 34 pycallgraph.make_dot_graph('regexp.png') 35 if __name__ == '__main__': 36 main() 35 37 36 38 # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: