Module runner
source code
Helper module to enable profiling of the testcase
If environment variable PROFILELEVEL is set it uses hotshot profiler
for unittest.main() call. Value of PROFILELEVEL defines number of top
busy functions to report.
Environment variable PROFILELINES=1 makes hotshot store information
per each line, so it could be easily inspected later on.
- Output:
- Profiler stores its Stats into a file named after original script
(sys.argv[0]) with suffix".prof" appended
- Usage:
- Replace unittest.main() with import runner
- Visualization:
kcachegrind provides nice interactive GUI to inspect profiler
results. If PROFILELINES was set to 1, it provides information per
each line.
To convert .prof file into a file suitable for kcachegrind, use
utility hotshot2calltree which comes in package
kcachegrind-converters.
Example:
# profile and output 3 most expensive function calls
PROFILELEVEL=3 PROFILELINES=1 PYTHONPATH=../ python test_searchlight.py
# convert to kcachegrind format
hotshot2calltree -o test_searchlight.py.kcache test_searchlight.py.prof
# inspect
kcachegrind test_searchlight.py.kcache
|
profilelevel = int(environ ['PROFILELEVEL'])
|
|
profilelines = environ.has_key('PROFILELINES')
|
|
pname = "%s.prof" % sys.argv [0]
|
|
prof = hotshot.Profile(pname, lineevents= profilelines)
|
|
stats = hotshot.stats.load(pname)
|