Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34f300a

Browse files
committed
Added docstrings to the Profile class.
Avoid adding Python wrappers around the underlying C profiler if possible; the extra layer of calls can lead to confusion in interpreting the logs.
1 parent 0fdc826 commit 34f300a

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lib/hotshot/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,61 @@ def __init__(self, logfn, lineevents=0, linetimings=1):
1212
self._prof = p = _hotshot.profiler(
1313
logfn, self.lineevents, self.linetimings)
1414

15+
# Attempt to avoid confusing results caused by the presence of
16+
# Python wrappers around these functions, but only if we can
17+
# be sure the methods have not been overridden or extended.
18+
if self.__class__ is Profile:
19+
self.close = p.close
20+
self.start = p.start
21+
self.stop = p.stop
22+
self.addinfo = p.addinfo
23+
1524
def close(self):
25+
"""Close the logfile and terminate the profiler."""
1626
self._prof.close()
1727

1828
def start(self):
29+
"""Start the profiler."""
1930
self._prof.start()
2031

2132
def stop(self):
33+
"""Stop the profiler."""
2234
self._prof.stop()
2335

2436
def addinfo(self, key, value):
37+
"""Add an arbitrary labelled value to the profile log."""
2538
self._prof.addinfo(key, value)
2639

2740
# These methods offer the same interface as the profile.Profile class,
2841
# but delegate most of the work to the C implementation underneath.
2942

3043
def run(self, cmd):
44+
"""Profile an exec-compatible string in the script
45+
environment.
46+
47+
The globals from the __main__ module are used as both the
48+
globals and locals for the script.
49+
"""
3150
import __main__
3251
dict = __main__.__dict__
3352
return self.runctx(cmd, dict, dict)
3453

3554
def runctx(self, cmd, globals, locals):
55+
"""Evaluate an exec-compatible string in a specific
56+
environment.
57+
58+
The string is compiled before profiling begins.
59+
"""
3660
code = compile(cmd, "<string>", "exec")
3761
self._prof.runcode(code, globals, locals)
3862
return self
3963

4064
def runcall(self, func, *args, **kw):
65+
"""Profile a single call of a callable.
66+
67+
Additional positional and keyword arguments may be passed
68+
along; the result of the call is returned, and exceptions are
69+
allowed to propogate cleanly, while ensuring that profiling is
70+
disabled on the way out.
71+
"""
4172
return self._prof.runcall(func, args, kw)

0 commit comments

Comments
 (0)