summaryrefslogtreecommitdiffstats
path: root/Lib/hotshot/__init__.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-10-12 20:56:29 (GMT)
committerFred Drake <fdrake@acm.org>2001-10-12 20:56:29 (GMT)
commitf019324b5c7a77f4983c06e5abb03b7751ea7305 (patch)
tree4f8febf4704eb20f4fb38a65f245b80459ceea24 /Lib/hotshot/__init__.py
parentde3cdcadce9ea43fb0c1e3619f07e6fb63d41981 (diff)
downloadcpython-f019324b5c7a77f4983c06e5abb03b7751ea7305.zip
cpython-f019324b5c7a77f4983c06e5abb03b7751ea7305.tar.gz
cpython-f019324b5c7a77f4983c06e5abb03b7751ea7305.tar.bz2
Preliminary user-level interface to HotShot. We still need the analysis
tool; look for that on Monday.
Diffstat (limited to 'Lib/hotshot/__init__.py')
-rw-r--r--Lib/hotshot/__init__.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/hotshot/__init__.py b/Lib/hotshot/__init__.py
new file mode 100644
index 0000000..b0e58f6
--- /dev/null
+++ b/Lib/hotshot/__init__.py
@@ -0,0 +1,38 @@
+"""High-perfomance logging profiler, mostly written in C."""
+
+import _hotshot
+
+from _hotshot import ProfilerError
+
+
+class Profile:
+ def __init__(self, logfn, lineevents=0, linetimings=1):
+ self.lineevents = lineevents and 1 or 0
+ self.linetimings = (linetimings and lineevents) and 1 or 0
+ self._prof = p = _hotshot.profiler(
+ logfn, self.lineevents, self.linetimings)
+
+ def close(self):
+ self._prof.close()
+
+ def start(self):
+ self._prof.start()
+
+ def stop(self):
+ self._prof.stop()
+
+ # These methods offer the same interface as the profile.Profile class,
+ # but delegate most of the work to the C implementation underneath.
+
+ def run(self, cmd):
+ import __main__
+ dict = __main__.__dict__
+ return self.runctx(cmd, dict, dict)
+
+ def runctx(self, cmd, globals, locals):
+ code = compile(cmd, "<string>", "exec")
+ self._prof.runcode(code, globals, locals)
+ return self
+
+ def runcall(self, func, *args, **kw):
+ self._prof.runcall(func, args, kw)