/
usr
/
lib
/
python2.6
/
site-packages
/
nose
/
plugins
/
/usr/lib/python2.6/site-packages/nose/plugins
mkdir
upload
Name
Size
Mode
Actions
attrib.py
7810
0644
edit
dl
rm
attrib.pyc
7428
0644
edit
dl
rm
attrib.pyo
7428
0644
edit
dl
rm
base.py
31384
0644
edit
dl
rm
base.pyc
36810
0644
edit
dl
rm
base.pyo
36810
0644
edit
dl
rm
builtin.py
792
0644
edit
dl
rm
builtin.pyc
1369
0644
edit
dl
rm
builtin.pyo
1369
0644
edit
dl
rm
capture.py
2780
0644
edit
dl
rm
capture.pyc
4565
0644
edit
dl
rm
capture.pyo
4565
0644
edit
dl
rm
cover.py
6416
0644
edit
dl
rm
cover.pyc
6213
0644
edit
dl
rm
cover.pyo
6213
0644
edit
dl
rm
debug.py
1679
0644
edit
dl
rm
debug.pyc
2481
0644
edit
dl
rm
debug.pyo
2481
0644
edit
dl
rm
deprecated.py
1639
0644
edit
dl
rm
deprecated.pyc
2385
0644
edit
dl
rm
deprecated.pyo
2385
0644
edit
dl
rm
doctests.py
9147
0644
edit
dl
rm
doctests.pyc
9891
0644
edit
dl
rm
doctests.pyo
9891
0644
edit
dl
rm
errorclass.py
6438
0644
edit
dl
rm
errorclass.pyc
8037
0644
edit
dl
rm
errorclass.pyo
8037
0644
edit
dl
rm
failuredetail.py
1564
0644
edit
dl
rm
failuredetail.pyc
2334
0644
edit
dl
rm
failuredetail.pyo
2334
0644
edit
dl
rm
isolate.py
3674
0644
edit
dl
rm
isolate.pyc
4729
0644
edit
dl
rm
isolate.pyo
4729
0644
edit
dl
rm
manager.py
14330
0644
edit
dl
rm
manager.pyc
18370
0644
edit
dl
rm
manager.pyo
18370
0644
edit
dl
rm
plugintest.py
7994
0644
edit
dl
rm
plugintest.pyc
9644
0644
edit
dl
rm
plugintest.pyo
9644
0644
edit
dl
rm
prof.py
4744
0644
edit
dl
rm
prof.pyc
4933
0644
edit
dl
rm
prof.pyo
4933
0644
edit
dl
rm
skip.py
1572
0644
edit
dl
rm
skip.pyc
2289
0644
edit
dl
rm
skip.pyo
2289
0644
edit
dl
rm
testid.py
4871
0644
edit
dl
rm
testid.pyc
5479
0644
edit
dl
rm
testid.pyo
5479
0644
edit
dl
rm
__init__.py
8169
0644
edit
dl
rm
__init__.pyc
8412
0644
edit
dl
rm
__init__.pyo
8412
0644
edit
dl
rm
Edit:
/usr/lib/python2.6/site-packages/nose/plugins/prof.py
(4744B)
"""Use the profile plugin with --with-profile or NOSE_WITH_PROFILE to enable profiling using the hotshot profiler. Profiler output can be controlled with the --profile-sort and --profile-restrict, and the profiler output file may be changed with --profile-stats-file. See the hotshot documentation in the standard library documentation for more details on the various output options. """ try: import hotshot from hotshot import stats except ImportError: hotshot, stats = None, None import logging import os import sys import tempfile from nose.plugins.base import Plugin from nose.util import tolist log = logging.getLogger('nose.plugins') class Profile(Plugin): """ Use this plugin to run tests using the hotshot profiler. """ pfile = None clean_stats_file = False def options(self, parser, env=os.environ): if not self.available(): return Plugin.options(self, parser, env) parser.add_option('--profile-sort', action='store', dest='profile_sort', default=env.get('NOSE_PROFILE_SORT', 'cumulative'), help="Set sort order for profiler output") parser.add_option('--profile-stats-file', action='store', dest='profile_stats_file', default=env.get('NOSE_PROFILE_STATS_FILE'), help='Profiler stats file; default is a new ' 'temp file on each run') parser.add_option('--profile-restrict', action='append', dest='profile_restrict', default=env.get('NOSE_PROFILE_RESTRICT'), help="Restrict profiler output. See help for " "pstats.Stats for details") def available(cls): return hotshot is not None available = classmethod(available) def begin(self): if not self.available(): return self._create_pfile() self.prof = hotshot.Profile(self.pfile) def configure(self, options, conf): if not self.available(): self.enabled = False return Plugin.configure(self, options, conf) self.conf = conf if options.profile_stats_file: self.pfile = options.profile_stats_file self.clean_stats_file = False else: self.pfile = None self.clean_stats_file = True self.fileno = None self.sort = options.profile_sort self.restrict = tolist(options.profile_restrict) def prepareTest(self, test): if not self.available(): return log.debug('preparing test %s' % test) def run_and_profile(result, prof=self.prof, test=test): self._create_pfile() prof.runcall(test, result) return run_and_profile def report(self, stream): log.debug('printing profiler report') self.prof.close() prof_stats = stats.load(self.pfile) prof_stats.sort_stats(self.sort) # 2.5 has completely different stream handling from 2.4 and earlier. # Before 2.5, stats objects have no stream attribute; in 2.5 and later # a reference sys.stdout is stored before we can tweak it. compat_25 = hasattr(stats, 'stream') if compat_25: tmp = prof_stats.stream stats.stream = stream else: tmp = sys.stdout sys.stdout = stream try: if self.restrict: log.debug('setting profiler restriction to %s', self.restrict) prof_stats.print_stats(*self.restrict) else: prof_stats.print_stats() finally: if compat_25: stats.stream = tmp else: sys.stdout = tmp def finalize(self, result): if not self.available(): return try: self.prof.close() except AttributeError: # TODO: is this trying to catch just the case where not # hasattr(self.prof, "close")? If so, the function call should be # moved out of the try: suite. pass if self.clean_stats_file: if self.fileno: try: os.close(self.fileno) except OSError: pass try: os.unlink(self.pfile) except OSError: pass return None def _create_pfile(self): if not self.pfile: self.fileno, self.pfile = tempfile.mkstemp() self.clean_stats_file = True
Save
cmd:
run