blob: f00e78d7fbe72fc44d45abc8dff4fd54ad3a179f [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
Fred Drake165b2cc2001-10-29 20:48:09 +000024 def addinfo(self, key, value):
25 self._prof.addinfo(key, value)
26
Fred Drakef0193242001-10-12 20:56:29 +000027 # These methods offer the same interface as the profile.Profile class,
28 # but delegate most of the work to the C implementation underneath.
29
30 def run(self, cmd):
31 import __main__
32 dict = __main__.__dict__
33 return self.runctx(cmd, dict, dict)
34
35 def runctx(self, cmd, globals, locals):
36 code = compile(cmd, "<string>", "exec")
37 self._prof.runcode(code, globals, locals)
38 return self
39
40 def runcall(self, func, *args, **kw):
Fred Drakee7d8a782001-10-15 22:14:29 +000041 return self._prof.runcall(func, args, kw)