Patchwork perf: make sure to explicitly disable any profiler after the first iteration

login
register
mail settings
Submitter Pierre-Yves David
Date May 23, 2019, 5:13 p.m.
Message ID <b6d5cc6ccb0a14d09459.1558631628@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/40217/
State Accepted
Headers show

Comments

Pierre-Yves David - May 23, 2019, 5:13 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1558631139 -7200
#      Thu May 23 19:05:39 2019 +0200
# Node ID b6d5cc6ccb0a14d094590a42bdaaab41f74ed945
# Parent  b02f3aa2fab572dac4deb5271d349d1cdceedf96
# EXP-Topic perf-followup
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r b6d5cc6ccb0a
perf: make sure to explicitly disable any profiler after the first iteration

The current code work, because of some edge behavior of the `profile` class. We
make it explicit that the profiler is not in effect more than once.
Yuya Nishihara - May 23, 2019, 11:23 p.m.
On Thu, 23 May 2019 19:13:48 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1558631139 -7200
> #      Thu May 23 19:05:39 2019 +0200
> # Node ID b6d5cc6ccb0a14d094590a42bdaaab41f74ed945
> # Parent  b02f3aa2fab572dac4deb5271d349d1cdceedf96
> # EXP-Topic perf-followup
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r b6d5cc6ccb0a
> perf: make sure to explicitly disable any profiler after the first iteration

Queued, thanks.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -275,6 +275,8 @@  class noop(object):
     def __exit__(self, *args):
         pass
 
+NOOPCTX = noop()
+
 def gettimer(ui, opts=None):
     """return a timer function and formatter: (timer, formatter)
 
@@ -405,7 +407,7 @@  def _timer(fm, func, setup=None, title=N
     begin = util.timer()
     count = 0
     if profiler is None:
-        profiler = noop()
+        profiler = NOOPCTX
     for i in xrange(prerun):
         if setup is not None:
             setup()
@@ -417,6 +419,7 @@  def _timer(fm, func, setup=None, title=N
         with profiler:
             with timeone() as item:
                 r = func()
+        profiler = NOOPCTX
         count += 1
         results.append(item[0])
         cstop = util.timer()