Patchwork [5,of,7,V2] profiling: don't error with statprof when profiling has already started

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 15, 2016, 1:37 a.m.
Message ID <ef37b1df0058f54c7b23.1471225062@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16299/
State Accepted
Headers show

Comments

Gregory Szorc - Aug. 15, 2016, 1:37 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1471224523 25200
#      Sun Aug 14 18:28:43 2016 -0700
# Node ID ef37b1df0058f54c7b23252b7356bb97b07652d7
# Parent  fd7b55561853e9d5532f3a9265433a7b614f2687
profiling: don't error with statprof when profiling has already started

statprof.reset() asserts if profiling has already started. So don't
call if it profiling is already running.

Patch

diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -83,17 +83,19 @@  def statprofile(ui, fp):
     try:
         import statprof
     except ImportError:
         raise error.Abort(_(
             'statprof not available - install using "easy_install statprof"'))
 
     freq = ui.configint('profiling', 'freq', default=1000)
     if freq > 0:
-        statprof.reset(freq)
+        # 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()
     try:
         yield
     finally:
         statprof.stop()