blob: b0e58f6ef1d776e9243aaebddfb33d224f1b5103 [file] [log] [blame]
Fred Drakef0193242001-10-12 20:56:29 +00001"""High-perfomance logging profiler, mostly written in C."""
2
3import _hotshot
4
5from _hotshot import ProfilerError
6
7
8class Profile:
9 def __init__(self, logfn, lineevents=0, linetimings=1):
10 self.lineevents = lineevents and 1 or 0
11 self.linetimings = (linetimings and lineevents) and 1 or 0
12 self._prof = p = _hotshot.profiler(
13 logfn, self.lineevents, self.linetimings)
14
15 def close(self):
16 self._prof.close()
17
18 def start(self):
19 self._prof.start()
20
21 def stop(self):
22 self._prof.stop()
23
24 # These methods offer the same interface as the profile.Profile class,
25 # but delegate most of the work to the C implementation underneath.
26
27 def run(self, cmd):
28 import __main__
29 dict = __main__.__dict__
30 return self.runctx(cmd, dict, dict)
31
32 def runctx(self, cmd, globals, locals):
33 code = compile(cmd, "<string>", "exec")
34 self._prof.runcode(code, globals, locals)
35 return self
36
37 def runcall(self, func, *args, **kw):
38 self._prof.runcall(func, args, kw)