Patchwork [1,of,2] dispatch: move detection of profiling earlier during startup

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 14, 2017, 4:50 a.m.
Message ID <82467bdb090b2500a97a.1487047810@bryano-mbp.local>
Download mbox | patch
Permalink /patch/18467/
State Accepted
Headers show

Comments

Bryan O'Sullivan - Feb. 14, 2017, 4:50 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1487047460 28800
#      Mon Feb 13 20:44:20 2017 -0800
# Node ID 82467bdb090b2500a97ae92e239bcdf72974f3f7
# Parent  a0e3d808690d57d1c9dff840e0b8ee099526397b
dispatch: move detection of profiling earlier during startup
Jun Wu - Feb. 18, 2017, 12:16 a.m.
This breaks extensions that wraps maybeprofile, namely
fb-hgext/profiling.py which tries to log interactive time.

That said, I think we could just remove profiling.py as Simon's change is a
superior solution.

Excerpts from Bryan O'Sullivan's message of 2017-02-13 20:50:10 -0800:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano@fb.com>
> # Date 1487047460 28800
> #      Mon Feb 13 20:44:20 2017 -0800
> # Node ID 82467bdb090b2500a97ae92e239bcdf72974f3f7
> # Parent  a0e3d808690d57d1c9dff840e0b8ee099526397b
> dispatch: move detection of profiling earlier during startup
> 
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -655,6 +655,15 @@ def _dispatch(req):
>      rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
>      path, lui = _getlocal(ui, rpath)
>  
> +    uis = set([ui, lui])
> +
> +    if req.repo:
> +        uis.add(req.repo.ui)
> +
> +    if '--profile' in args:
> +        for ui_ in uis:
> +            ui_.setconfig('profiling', 'enabled', 'true', '--profile')
> +
>      # Configure extensions in phases: uisetup, extsetup, cmdtable, and
>      # reposetup. Programs like TortoiseHg will call _dispatch several
>      # times so we keep track of configured extensions in _loaded.
> @@ -721,21 +730,12 @@ def _dispatch(req):
>                  (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
>          atexit.register(print_time)
>  
> -    uis = set([ui, lui])
> -
> -    if req.repo:
> -        uis.add(req.repo.ui)
> -
>      if options['verbose'] or options['debug'] or options['quiet']:
>          for opt in ('verbose', 'debug', 'quiet'):
>              val = str(bool(options[opt]))
>              for ui_ in uis:
>                  ui_.setconfig('ui', opt, val, '--' + opt)
>  
> -    if options['profile']:
> -        for ui_ in uis:
> -            ui_.setconfig('profiling', 'enabled', 'true', '--profile')
> -
>      if options['traceback']:
>          for ui_ in uis:
>              ui_.setconfig('ui', 'traceback', 'on', '--traceback')
Bryan O'Sullivan - Feb. 20, 2017, 9:53 p.m.
On Fri, Feb 17, 2017 at 4:16 PM, Jun Wu <quark@fb.com> wrote:

> This breaks extensions that wraps maybeprofile, namely
> fb-hgext/profiling.py which tries to log interactive time.
>
> That said, I think we could just remove profiling.py as Simon's change is
> a
> superior solution.
>

Breaking out-of-tree extensions is somewhat unfortunate, but difficult to
avoid, and generally not something I think we'd want to block on.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -655,6 +655,15 @@  def _dispatch(req):
     rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
     path, lui = _getlocal(ui, rpath)
 
+    uis = set([ui, lui])
+
+    if req.repo:
+        uis.add(req.repo.ui)
+
+    if '--profile' in args:
+        for ui_ in uis:
+            ui_.setconfig('profiling', 'enabled', 'true', '--profile')
+
     # Configure extensions in phases: uisetup, extsetup, cmdtable, and
     # reposetup. Programs like TortoiseHg will call _dispatch several
     # times so we keep track of configured extensions in _loaded.
@@ -721,21 +730,12 @@  def _dispatch(req):
                 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
         atexit.register(print_time)
 
-    uis = set([ui, lui])
-
-    if req.repo:
-        uis.add(req.repo.ui)
-
     if options['verbose'] or options['debug'] or options['quiet']:
         for opt in ('verbose', 'debug', 'quiet'):
             val = str(bool(options[opt]))
             for ui_ in uis:
                 ui_.setconfig('ui', opt, val, '--' + opt)
 
-    if options['profile']:
-        for ui_ in uis:
-            ui_.setconfig('profiling', 'enabled', 'true', '--profile')
-
     if options['traceback']:
         for ui_ in uis:
             ui_.setconfig('ui', 'traceback', 'on', '--traceback')