Comments
Patch
@@ -75,36 +75,45 @@ def flameprofile(ui, fp):
thread.stop()
thread.join()
print('Collected %d stack frames (%d unique) in %2.2f seconds.' % (
time.clock() - start_time, thread.num_frames(),
thread.num_frames(unique=True)))
@contextlib.contextmanager
def statprofile(ui, fp):
- try:
- import statprof
- except ImportError:
- raise error.Abort(_(
- 'statprof not available - install using "easy_install statprof"'))
+ from . import statprof
freq = ui.configint('profiling', 'freq', default=1000)
if freq > 0:
# Cannot reset when profiler is already active. So silently no-op.
if statprof.state.profile_level == 0:
statprof.reset(freq)
else:
ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
- statprof.start()
+ mechanism = ui.config('statprof', 'mechanism', 'thread')
+ statprof.start(mechanism=mechanism)
+
try:
yield
finally:
- statprof.stop()
- statprof.display(fp)
+ data = statprof.stop()
+
+ profformat = ui.config('statprof', 'format', 'hotpath')
+
+ if profformat == 'hotpath':
+ displayformat = statprof.DisplayFormats.Hotpath
+ elif profformat == 'json':
+ displayformat = statprof.DisplayFormats.Json
+ else:
+ ui.warn(_('unknown profiler output format: %s') % profformat)
+ displayformat = statprof.DisplayFormats.Hotpath
+
+ statprof.display(fp, data=data, format=displayformat)
@contextlib.contextmanager
def profile(ui):
"""Start profiling.
Profiling is active when the context manager is active. When the context
manager exits, profiling results will be written to the configured output.
"""