From patchwork Thu May 23 17:13:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: perf: make sure to explicitly disable any profiler after the first iteration From: Pierre-Yves David X-Patchwork-Id: 40217 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Thu, 23 May 2019 19:13:48 +0200 # HG changeset patch # User Pierre-Yves David # 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. 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()