profiling: add statprof support for Chrome trace viewer rendering
authorBryan O'Sullivan <bryano@fb.com>
Sun, 12 Feb 2017 22:28:09 -0800
changeset 30930 517bc1cd7033
parent 30929 cb440e7af05d
child 30931 f2ad0d804700
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
mercurial/profiling.py
--- 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):