Patchwork [3,of,4] profiling: make statprof the default profiler (BC)

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 5, 2016, 4:53 a.m.
Message ID <dfd8e1f11e33fc1ba6cb.1478321622@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17347/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 5, 2016, 4:53 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1478321065 25200
#      Fri Nov 04 21:44:25 2016 -0700
# Node ID dfd8e1f11e33fc1ba6cba429818ad0ea6e84dadc
# Parent  503459ea99f4b5fa4bd2827e36de2e1e8a7696f8
profiling: make statprof the default profiler (BC)

The statprof sampling profiler runs with significantly less overhead.
Its data is therefore more useful. Furthermore, its default output
shows the hotpath by default, which I've found to be way more useful
than the default profiler's function time table.

There is one behavioral regression with this change worth noting:
the statprof profiler currently doesn't profile individual hgweb
requests like lsprof does. This is because the current implementation
of statprof only profiles the thread that started profiling.

The ability for lsprof to profile individual hgweb requests is
relatively new and likely not widely used. Furthermore, I have plans
to modify statprof to support profiling multiple threads. I expect
that change to go through several iterations. I'm submitting this
patch first so there is more time to test statprof. Perfect is the
enemy of good.
Yuya Nishihara - Nov. 8, 2016, 2:12 p.m.
On Fri, 04 Nov 2016 21:53:42 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1478321065 25200
> #      Fri Nov 04 21:44:25 2016 -0700
> # Node ID dfd8e1f11e33fc1ba6cba429818ad0ea6e84dadc
> # Parent  503459ea99f4b5fa4bd2827e36de2e1e8a7696f8
> profiling: make statprof the default profiler (BC)

The patch 2 and 3 look good to me. Pushed up to this, thanks.
(I'll revisit the last patch later.)

Patch

diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1401,7 +1401,7 @@  profiling is done using lsprof.
 
 ``type``
     The type of profiler to use.
-    (default: ls)
+    (default: stat)
 
     ``ls``
       Use Python's built-in instrumenting profiler. This profiler
diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -123,10 +123,10 @@  def profile(ui):
     """
     profiler = os.getenv('HGPROF')
     if profiler is None:
-        profiler = ui.config('profiling', 'type', default='ls')
+        profiler = ui.config('profiling', 'type', default='stat')
     if profiler not in ('ls', 'stat', 'flame'):
         ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler)
-        profiler = 'ls'
+        profiler = 'stat'
 
     output = ui.config('profiling', 'output')
 
diff --git a/tests/test-profile.t b/tests/test-profile.t
--- a/tests/test-profile.t
+++ b/tests/test-profile.t
@@ -66,29 +66,29 @@  Install an extension that can sleep and 
 
 statistical profiler works
 
-  $ HGPROF=stat hg --profile sleep 2>../out
+  $ hg --profile sleep 2>../out
   $ grep Sample ../out
   Sample count: \d+ (re)
 
 Various statprof formatters work
 
-  $ HGPROF=stat hg --profile --config profiling.statformat=byline sleep 2>../out
+  $ hg --profile --config profiling.statformat=byline sleep 2>../out
   $ head -n 1 ../out
     %   cumulative      self          
   $ grep Sample ../out
   Sample count: \d+ (re)
 
-  $ HGPROF=stat hg --profile --config profiling.statformat=bymethod sleep 2>../out
+  $ hg --profile --config profiling.statformat=bymethod sleep 2>../out
   $ head -n 1 ../out
     %   cumulative      self          
   $ grep Sample ../out
   Sample count: \d+ (re)
 
-  $ HGPROF=stat hg --profile --config profiling.statformat=hotpath sleep 2>../out
+  $ hg --profile --config profiling.statformat=hotpath sleep 2>../out
   $ grep Sample ../out
   Sample count: \d+ (re)
 
-  $ HGPROF=stat hg --profile --config profiling.statformat=json sleep 2>../out
+  $ hg --profile --config profiling.statformat=json sleep 2>../out
   $ cat ../out
   \[\[\d+.* (re)