+++ /dev/null
-"""High-perfomance logging profiler, mostly written in C."""\r
-\r
-import _hotshot\r
-from _hotshot import ProfilerError\r
-\r
-from warnings import warnpy3k as _warnpy3k\r
-_warnpy3k("The 'hotshot' module is not supported in 3.x, "\r
- "use the 'profile' module instead.", stacklevel=2)\r
-\r
-class Profile:\r
- def __init__(self, logfn, lineevents=0, linetimings=1):\r
- self.lineevents = lineevents and 1 or 0\r
- self.linetimings = (linetimings and lineevents) and 1 or 0\r
- self._prof = p = _hotshot.profiler(\r
- logfn, self.lineevents, self.linetimings)\r
-\r
- # Attempt to avoid confusing results caused by the presence of\r
- # Python wrappers around these functions, but only if we can\r
- # be sure the methods have not been overridden or extended.\r
- if self.__class__ is Profile:\r
- self.close = p.close\r
- self.start = p.start\r
- self.stop = p.stop\r
- self.addinfo = p.addinfo\r
-\r
- def close(self):\r
- """Close the logfile and terminate the profiler."""\r
- self._prof.close()\r
-\r
- def fileno(self):\r
- """Return the file descriptor of the profiler's log file."""\r
- return self._prof.fileno()\r
-\r
- def start(self):\r
- """Start the profiler."""\r
- self._prof.start()\r
-\r
- def stop(self):\r
- """Stop the profiler."""\r
- self._prof.stop()\r
-\r
- def addinfo(self, key, value):\r
- """Add an arbitrary labelled value to the profile log."""\r
- self._prof.addinfo(key, value)\r
-\r
- # These methods offer the same interface as the profile.Profile class,\r
- # but delegate most of the work to the C implementation underneath.\r
-\r
- def run(self, cmd):\r
- """Profile an exec-compatible string in the script\r
- environment.\r
-\r
- The globals from the __main__ module are used as both the\r
- globals and locals for the script.\r
- """\r
- import __main__\r
- dict = __main__.__dict__\r
- return self.runctx(cmd, dict, dict)\r
-\r
- def runctx(self, cmd, globals, locals):\r
- """Evaluate an exec-compatible string in a specific\r
- environment.\r
-\r
- The string is compiled before profiling begins.\r
- """\r
- code = compile(cmd, "<string>", "exec")\r
- self._prof.runcode(code, globals, locals)\r
- return self\r
-\r
- def runcall(self, func, *args, **kw):\r
- """Profile a single call of a callable.\r
-\r
- Additional positional and keyword arguments may be passed\r
- along; the result of the call is returned, and exceptions are\r
- allowed to propogate cleanly, while ensuring that profiling is\r
- disabled on the way out.\r
- """\r
- return self._prof.runcall(func, args, kw)\r