[PATCH 1 of 3 v2] profiling: allow nested usage of maybeprofile

Arun Kulshreshtha kulshrax at fb.com
Mon Sep 19 19:19:20 EDT 2016

This wasn’t caught during review, but I’ve updated this so that the nested invocation check resets itself after the root context manager exits. This ensures that if maybeprofile is called in several (non-nested) places, it won’t be the case that only the first instance enables profiling. This situation does not exist in the code right now, but may in the future.

On 9/19/16, 4:13 PM, "Mercurial-devel on behalf of Arun Kulshreshtha" <mercurial-devel-bounces at mercurial-scm.org on behalf of kulshrax at fb.com> wrote:

    # HG changeset patch
    # User Arun Kulshreshtha <kulshrax at fb.com>
    # Date 1474324901 25200
    #      Mon Sep 19 15:41:41 2016 -0700
    # Node ID 679c90104cc1fc92099ede6bd359f6ab5b10640d
    # 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.
    Updated in v2 of this patch to reset itself once the root invocation
    has exited. While not currently used, this ensures that maybeprofile
    can be used in multiple (non-nested) places in a single run.
    diff --git a/mercurial/profiling.py b/mercurial/profiling.py
    --- a/mercurial/profiling.py
    +++ b/mercurial/profiling.py
    @@ -157,8 +157,15 @@
         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):
    +        maybeprofile.enabled = False
    Mercurial-devel mailing list
    Mercurial-devel at mercurial-scm.org

More information about the Mercurial-devel mailing list