# HG changeset patch
# User Arun Kulshreshtha <kulsh...@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:
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to