1
2
3
4
5
6
7
8
9
10
11 import os
12 import hotshot
13 import hotshot.stats
14 import tempfile
15
17
19 self.fname = tempfile.mktemp()
20 self.profiler = hotshot.Profile(self.fname, True)
21
23 stats = hotshot.stats.load(self.fname)
24 stats.sort_stats('time', 'calls')
25 stats.print_stats(limit)
26
27 - def runcall(self, *args, **kwargs):
31
34
35
37 """
38 Decorator that will profile a function and print stats.
39 """
40 def inner(*args, **kwargs):
41 p = Profiler()
42 result = p.runcall(f, *args, **kwargs)
43 p.print_stats()
44 return result
45 return inner
46