174 ) |
174 ) |
175 configitem('perf', 'stub', |
175 configitem('perf', 'stub', |
176 default=mercurial.configitems.dynamicdefault, |
176 default=mercurial.configitems.dynamicdefault, |
177 ) |
177 ) |
178 configitem('perf', 'parentscount', |
178 configitem('perf', 'parentscount', |
|
179 default=mercurial.configitems.dynamicdefault, |
|
180 ) |
|
181 configitem('perf', 'all-timing', |
179 default=mercurial.configitems.dynamicdefault, |
182 default=mercurial.configitems.dynamicdefault, |
180 ) |
183 ) |
181 except (ImportError, AttributeError): |
184 except (ImportError, AttributeError): |
182 pass |
185 pass |
183 |
186 |
245 |
248 |
246 # stub function, runs code only once instead of in a loop |
249 # stub function, runs code only once instead of in a loop |
247 # experimental config: perf.stub |
250 # experimental config: perf.stub |
248 if ui.configbool("perf", "stub", False): |
251 if ui.configbool("perf", "stub", False): |
249 return functools.partial(stub_timer, fm), fm |
252 return functools.partial(stub_timer, fm), fm |
250 return functools.partial(_timer, fm), fm |
253 |
|
254 # experimental config: perf.all-timing |
|
255 displayall = ui.configbool("perf", "all-timing", False) |
|
256 return functools.partial(_timer, fm, displayall=displayall), fm |
251 |
257 |
252 def stub_timer(fm, func, title=None): |
258 def stub_timer(fm, func, title=None): |
253 func() |
259 func() |
254 |
260 |
255 def _timer(fm, func, title=None): |
261 def _timer(fm, func, title=None, displayall=False): |
256 gc.collect() |
262 gc.collect() |
257 results = [] |
263 results = [] |
258 begin = util.timer() |
264 begin = util.timer() |
259 count = 0 |
265 count = 0 |
260 while True: |
266 while True: |
275 |
281 |
276 if title: |
282 if title: |
277 fm.write('title', '! %s\n', title) |
283 fm.write('title', '! %s\n', title) |
278 if r: |
284 if r: |
279 fm.write('result', '! result: %s\n', r) |
285 fm.write('result', '! result: %s\n', r) |
280 m = min(results) |
286 def display(role, entry): |
281 fm.plain('!') |
287 prefix = '' |
282 fm.write('wall', ' wall %f', m[0]) |
288 if role != 'best': |
283 fm.write('comb', ' comb %f', m[1] + m[2]) |
289 prefix = '%s.' % role |
284 fm.write('user', ' user %f', m[1]) |
290 fm.plain('!') |
285 fm.write('sys', ' sys %f', m[2]) |
291 fm.write(prefix + 'wall', ' wall %f', entry[0]) |
286 fm.write('count', ' (best of %d)', count) |
292 fm.write(prefix + 'comb', ' comb %f', entry[1] + entry[2]) |
287 fm.plain('\n') |
293 fm.write(prefix + 'user', ' user %f', entry[1]) |
|
294 fm.write(prefix + 'sys', ' sys %f', entry[2]) |
|
295 fm.write(prefix + 'count', ' (%s of %d)', role, count) |
|
296 fm.plain('\n') |
|
297 results.sort() |
|
298 min_val = results[0] |
|
299 display('best', min_val) |
|
300 if displayall: |
|
301 max_val = results[-1] |
|
302 display('max', max_val) |
|
303 avg = tuple([sum(x) / count for x in zip(*results)]) |
|
304 display('avg', avg) |
|
305 median = results[len(results) // 2] |
|
306 display('median', median) |
288 |
307 |
289 # utilities for historical portability |
308 # utilities for historical portability |
290 |
309 |
291 def getint(ui, section, name, default): |
310 def getint(ui, section, name, default): |
292 # for "historical portability": |
311 # for "historical portability": |