Mercurial > hg
comparison contrib/perf.py @ 18304:9b6ae29d4801
perf: add perfbranchmap command
The command times the update of a branchmap from its nearest subset
or from scratch.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Fri, 11 Jan 2013 18:39:43 +0100 |
parents | f5ed27c51995 |
children | 3e92772d5383 |
comparison
equal
deleted
inserted
replaced
18303:4d1671b39168 | 18304:9b6ae29d4801 |
---|---|
1 # perf.py - performance test routines | 1 # perf.py - performance test routines |
2 '''helper extension to measure performance''' | 2 '''helper extension to measure performance''' |
3 | 3 |
4 from mercurial import cmdutil, scmutil, util, match, commands, obsolete | 4 from mercurial import cmdutil, scmutil, util, match, commands, obsolete |
5 from mercurial import repoview | 5 from mercurial import repoview, branchmap |
6 import time, os, sys | 6 import time, os, sys |
7 | 7 |
8 cmdtable = {} | 8 cmdtable = {} |
9 command = cmdutil.command(cmdtable) | 9 command = cmdutil.command(cmdtable) |
10 | 10 |
307 if names: | 307 if names: |
308 allfilter = [n for n in allfilter if n in names] | 308 allfilter = [n for n in allfilter if n in names] |
309 | 309 |
310 for name in allfilter: | 310 for name in allfilter: |
311 timer(getfiltered(name), title=name) | 311 timer(getfiltered(name), title=name) |
312 | |
313 @command('perfbranchmap', | |
314 [('f', 'full', False, | |
315 'Includes build time of subset'), | |
316 ]) | |
317 def perfbranchmap(ui, repo, full=False): | |
318 """benchmark the update of a branchmap | |
319 | |
320 This benchmarks the full repo.branchmap() call with read and write disabled | |
321 """ | |
322 def getbranchmap(filtername): | |
323 """generate a benchmark function for the filtername""" | |
324 if filtername is None: | |
325 view = repo | |
326 else: | |
327 view = repo.filtered(filtername) | |
328 def d(): | |
329 if full: | |
330 view._branchcaches.clear() | |
331 else: | |
332 view._branchcaches.pop(filtername, None) | |
333 view.branchmap() | |
334 return d | |
335 # add filter in smaller subset to bigger subset | |
336 possiblefilters = set(repoview.filtertable) | |
337 allfilters = [] | |
338 while possiblefilters: | |
339 for name in possiblefilters: | |
340 subset = repoview.subsettable.get(name) | |
341 if subset not in possiblefilters: | |
342 break | |
343 else: | |
344 assert False, 'subset cycle %s!' % possiblefilters | |
345 allfilters.append(name) | |
346 possiblefilters.remove(name) | |
347 | |
348 # warm the cache | |
349 if not full: | |
350 for name in allfilters: | |
351 repo.filtered(name).branchmap() | |
352 # add unfiltered | |
353 allfilters.append(None) | |
354 oldread = branchmap.read | |
355 oldwrite = branchmap.branchcache.write | |
356 try: | |
357 branchmap.read = lambda repo: None | |
358 branchmap.write = lambda repo: None | |
359 for name in allfilters: | |
360 timer(getbranchmap(name), title=str(name)) | |
361 finally: | |
362 branchmap.read = oldread | |
363 branchmap.branchcache.write = oldwrite | |
364 | |
365 | |
366 |