[PATCH 5 of 5 v2] profiling: add statprof support for Chrome trace viewer rendering
Bryan O'Sullivan
bos at serpentine.com
Mon Feb 13 01:39:57 EST 2017
# HG changeset patch
# User Bryan O'Sullivan <bryano at 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
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):
More information about the Mercurial-devel
mailing list