[PATCH 1 of 3] profiling: allow nested usage of maybeprofile
Arun Kulshreshtha
kulshrax at fb.com
Mon Sep 19 20:52:58 UTC 2016
# HG changeset patch
# User Arun Kulshreshtha <kulshrax at fb.com>
# Date 1474317803 25200
# Mon Sep 19 13:43:23 2016 -0700
# Node ID bed6aa7752d07f7fbd4bac2c0f5092da76271304
# Parent 285a8c3e53f2183438f0cdbc238e4ab851d0d110
profiling: allow nested usage of maybeprofile
Add a check to the maybeprofile context manager to ensure that profiling
is only enabled once in nested invocations of this context manager.
diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -157,7 +157,13 @@
just use a single code path for calling into code you may want to profile
and this function determines whether to start profiling.
"""
- if ui.configbool('profiling', 'enabled'):
+
+ # Guard against nested invocations of this context manager.
+ # Profiling should only be started in the outermost invocation.
+ alreadyenabled = getattr(maybeprofile, 'enabled', False)
+
+ if ui.configbool('profiling', 'enabled') and not alreadyenabled:
+ maybeprofile.enabled = True
with profile(ui):
yield
else:
More information about the Mercurial-devel
mailing list