Patchwork [5,of,5,v2] profiling: add statprof support for Chrome trace viewer rendering

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 13, 2017, 6:39 a.m.
Message ID <292f937ad6e36d6c8bfa.1486967997@bryano-mbp.local>
Download mbox | patch
Permalink /patch/18435/
State Accepted
Headers show

Comments

Bryan O'Sullivan - Feb. 13, 2017, 6:39 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1486967289 28800
#      Sun Feb 12 22:28:09 2017 -0800
# Node ID 292f937ad6e36d6c8bfadec43ba07103ae75d04f
# Parent  9c4ac8a20bd95c4069a20cf03a84b2c5c7b58def
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
Bryan O'Sullivan - Feb. 13, 2017, 6:44 a.m.
On Sun, Feb 12, 2017 at 10:39 PM, Bryan O'Sullivan <bos@serpentine.com>
wrote:

> profiling: add statprof support for Chrome trace viewer rendering
>

Here's an example screenshot of the Chrome trace viewer:

http://imgur.com/gallery/I3Qmu

And the trace data from which that was generated:

http://pastebin.com/fy6WeyHq

Command line that I ran:

~/hg/hg/hg --config profiling.output=clone.json \
  --config profiling.statformat=chrome --profile \
  clone -r10000 https://www.mercurial-scm.org/repo/hg killme
Sean Farley - Feb. 13, 2017, 11:23 p.m.
Bryan O'Sullivan <bos@serpentine.com> writes:

> On Sun, Feb 12, 2017 at 10:39 PM, Bryan O'Sullivan <bos@serpentine.com>
> wrote:
>
>> profiling: add statprof support for Chrome trace viewer rendering
>>
>
> Here's an example screenshot of the Chrome trace viewer:
>
> http://imgur.com/gallery/I3Qmu
>
> And the trace data from which that was generated:
>
> http://pastebin.com/fy6WeyHq
>
> Command line that I ran:
>
> ~/hg/hg/hg --config profiling.output=clone.json \
>   --config profiling.statformat=chrome --profile \
>   clone -r10000 https://www.mercurial-scm.org/repo/hg killme

This all looks pretty sweet to me. But I have no real horse in this
race. Any one else want to give it a look over?

Patch

diff --git a/mercurial/profiling.py b/mercurial/profiling.py
--- a/mercurial/profiling.py
+++ b/mercurial/profiling.py
@@ -103,6 +103,7 @@  def statprofile(ui, fp):
             'bymethod': statprof.DisplayFormats.ByMethod,
             'hotpath': statprof.DisplayFormats.Hotpath,
             'json': statprof.DisplayFormats.Json,
+            'chrome': statprof.DisplayFormats.Chrome,
         }
 
         if profformat in formats:
@@ -111,7 +112,23 @@  def statprofile(ui, fp):
             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):