comparison mercurial/profiling.py @ 31709: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 6a70cf94d1b5
children 22fbca1d11ed
comparison
equal deleted inserted replaced
31708:cb440e7af05d 31709:517bc1cd7033
101 formats = { 101 formats = {
102 'byline': statprof.DisplayFormats.ByLine, 102 'byline': statprof.DisplayFormats.ByLine,
103 'bymethod': statprof.DisplayFormats.ByMethod, 103 'bymethod': statprof.DisplayFormats.ByMethod,
104 'hotpath': statprof.DisplayFormats.Hotpath, 104 'hotpath': statprof.DisplayFormats.Hotpath,
105 'json': statprof.DisplayFormats.Json, 105 'json': statprof.DisplayFormats.Json,
106 'chrome': statprof.DisplayFormats.Chrome,
106 } 107 }
107 108
108 if profformat in formats: 109 if profformat in formats:
109 displayformat = formats[profformat] 110 displayformat = formats[profformat]
110 else: 111 else:
111 ui.warn(_('unknown profiler output format: %s\n') % profformat) 112 ui.warn(_('unknown profiler output format: %s\n') % profformat)
112 displayformat = statprof.DisplayFormats.Hotpath 113 displayformat = statprof.DisplayFormats.Hotpath
113 114
114 statprof.display(fp, data=data, format=displayformat) 115 kwargs = {}
116
117 def fraction(s):
118 if s.endswith('%'):
119 v = float(s[:-1]) / 100
120 else:
121 v = float(s)
122 if 0 <= v <= 1:
123 return v
124 raise ValueError(s)
125
126 if profformat == 'chrome':
127 showmin = ui.configwith(fraction, 'profiling', 'showmin', 0.005)
128 showmax = ui.configwith(fraction, 'profiling', 'showmax', 0.999)
129 kwargs.update(minthreshold=showmin, maxthreshold=showmax)
130
131 statprof.display(fp, data=data, format=displayformat, **kwargs)
115 132
116 @contextlib.contextmanager 133 @contextlib.contextmanager
117 def profile(ui): 134 def profile(ui):
118 """Start profiling. 135 """Start profiling.
119 136