[PATCH 2 of 6] profile: introduce a "start" method to the profile context
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Fri Jun 9 12:32:58 UTC 2017
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1497004793 -3600
# Fri Jun 09 11:39:53 2017 +0100
# Node ID 5b9718803532b81e240e126913608385a32352bd
# Parent a3a4b52464f3dbaf533f62bca7512f42c6a6d449
# EXP-Topic profile
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
# hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 5b9718803532
profile: introduce a "start" method to the profile context
The start method is doing all profiler setup and activation. It is currently
unconditionally called by '__init__' but this will be made more flexible in
later changesets.
diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -152,8 +152,24 @@ class profile(object):
self._output = None
self._fp = None
self._profiler = None
+ self._entered = False
+ self._started = False
def __enter__(self):
+ self._entered = True
+ self.start()
+
+ def start(self):
+ """Start profiling.
+
+ The profiling will stop at the context exit.
+
+ If the profiler was already started, this has no effect."""
+ if not self._entered:
+ raise error.ProgrammingError()
+ if self._started:
+ return
+ self._started = True
profiler = encoding.environ.get('HGPROF')
proffn = None
if profiler is None:
More information about the Mercurial-devel
mailing list