[PATCH 5 of 6] profile: support --profile in alias and abbreviated version (--prof)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Jun 9 08:33:01 EDT 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1497008167 -3600
#      Fri Jun 09 12:36:07 2017 +0100
# Node ID b45fd5132c5f55104e0853da642a9c4d2e9c71b8
# Parent  1642a7b657e057cd0404cd4f33528e3cc272dfee
# EXP-Topic profile
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r b45fd5132c5f
profile: support --profile in alias and abbreviated version (--prof)

We now process the "--profile" a second time after alias has been processed and
the command argument fully parsed. If appropriate we enable profiling at that
time.

In these situation, the --profile will cover less than if the full --profile
flag was passed on the command line. This is better than the previous behavior
(flag ignored) and still fullfil multiple valid usecases.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -764,7 +764,7 @@ def _dispatch(req):
         for ui_ in uis:
             ui_.setconfig('profiling', 'enabled', 'true', '--profile')
 
-    with profiling.maybeprofile(lui):
+    with profiling.maybeprofile(lui) as profiler:
         # 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.
@@ -827,6 +827,8 @@ def _dispatch(req):
                     _("time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
                     (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
             ui.atexit(print_time)
+        if options["profile"]:
+            profiler.start()
 
         if options['verbose'] or options['debug'] or options['quiet']:
             for opt in ('verbose', 'debug', 'quiet'):
diff --git a/tests/test-profile.t b/tests/test-profile.t
--- a/tests/test-profile.t
+++ b/tests/test-profile.t
@@ -4,10 +4,24 @@ test --time
   $ hg init a
   $ cd a
 
-#if lsprof
 
 test --profile
 
+  $ hg st --profile 2>&1 | grep Sample
+  Sample count: \d+ (re)
+
+Abreviated version
+
+  $ hg st --prof 2>&1 | grep Sample
+  Sample count: \d+ (re)
+
+In alias
+
+  $ hg --config "alias.profst=status --profile" profst 2>&1 | grep Sample
+  Sample count: \d+ (re)
+
+#if lsprof
+
   $ prof='hg --config profiling.type=ls --profile'
 
   $ $prof st 2>../out


More information about the Mercurial-devel mailing list