Patchwork [1,of,3] profiling: allow nested usage of maybeprofile

login
register
mail settings
Submitter Arun Kulshreshtha
Date Sept. 19, 2016, 8:52 p.m.
Message ID <bed6aa7752d07f7fbd4b.1474318378@dev10559.prn2.facebook.com>
Download mbox | patch
Permalink /patch/16673/
State Superseded
Headers show

Comments

Arun Kulshreshtha - Sept. 19, 2016, 8:52 p.m.
# HG changeset patch
# User Arun Kulshreshtha <kulshrax@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.

Patch

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: