changeset 30930:517bc1cd7033

profiling: add statprof support for Chrome trace viewer rendering We synthesize function call begin/end events from snapshots, and try (configurably) to eliminate "noisy" stack frames. Example invocation: hg --config profiling.output=$HOME/Desktop/clone.json \ --config profiling.statformat=chrome \ --profile clone https://www.mercurial-scm.org/repo/hg
author Bryan O'Sullivan <bryano@fb.com>
date Sun, 12 Feb 2017 22:28:09 -0800
parents cb440e7af05d
children f2ad0d804700
files mercurial/profiling.py
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/profiling.py	Sun Feb 12 22:20:20 2017 -0800
+++ b/mercurial/profiling.py	Sun Feb 12 22:28:09 2017 -0800
@@ -103,6 +103,7 @@
             'bymethod': statprof.DisplayFormats.ByMethod,
             'hotpath': statprof.DisplayFormats.Hotpath,
             'json': statprof.DisplayFormats.Json,
+            'chrome': statprof.DisplayFormats.Chrome,
         }
 
         if profformat in formats:
@@ -111,7 +112,23 @@
             ui.warn(_('unknown profiler output format: %s\n') % profformat)
             displayformat = statprof.DisplayFormats.Hotpath
 
-        statprof.display(fp, data=data, format=displayformat)
+        kwargs = {}
+
+        def fraction(s):
+            if s.endswith('%'):
+                v = float(s[:-1]) / 100
+            else:
+                v = float(s)
+            if 0 <= v <= 1:
+                return v
+            raise ValueError(s)
+
+        if profformat == 'chrome':
+            showmin = ui.configwith(fraction, 'profiling', 'showmin', 0.005)
+            showmax = ui.configwith(fraction, 'profiling', 'showmax', 0.999)
+            kwargs.update(minthreshold=showmin, maxthreshold=showmax)
+
+        statprof.display(fp, data=data, format=displayformat, **kwargs)
 
 @contextlib.contextmanager
 def profile(ui):