[PATCH 10 of 10 V2] profiling: make statprof the default profiler (BC)

Gregory Szorc gregory.szorc at gmail.com
Wed Aug 17 12:03:48 EDT 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1471449279 25200
#      Wed Aug 17 08:54:39 2016 -0700
# Node ID d20e3064df489d1a29c5186d3cb77eec3fdf03b4
# Parent  e262b893e1fb54af71123a1e77956f24a9cfea52
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.

diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1396,17 +1396,17 @@ profiling is done using lsprof.
 ``enabled``
     Enable the profiler.
     (default: false)
 
     This is equivalent to passing ``--profile`` on the command line.
 
 ``type``
     The type of profiler to use.
-    (default: ls)
+    (default: stat)
 
     ``ls``
       Use Python's built-in instrumenting profiler. This profiler
       works on all platforms, but each line number it reports is the
       first line of a function. This restriction makes it difficult to
       identify the expensive parts of a non-trivial function.
     ``stat``
       Use a statistical profiler, statprof. This profiler is most
diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -113,20 +113,20 @@ def statprofile(ui, fp):
 def profile(ui):
     """Start profiling.
 
     Profiling is active when the context manager is active. When the context
     manager exits, profiling results will be written to the configured output.
     """
     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')
 
     if output == 'blackbox':
         fp = util.stringio()
     elif output:
         path = ui.expandpath(output)
         fp = open(path, 'wb')
diff --git a/tests/test-profile.t b/tests/test-profile.t
--- a/tests/test-profile.t
+++ b/tests/test-profile.t
@@ -42,9 +42,15 @@ Profiling of HTTP requests works
   $ hg -q clone -U http://localhost:$HGPORT ../clone
 
 A single profile is logged because file logging doesn't append
   $ grep CallCount ../profile.log | wc -l
   \s*1 (re)
 
 #endif
 
+statistical profiler works
+
+  $ hg --profile st 2>../out
+  $ grep Sample ../out
+  Sample count: \d+ (re)
+
   $ cd ..


More information about the Mercurial-devel mailing list