Mercurial > hg
comparison contrib/perf.py @ 32731:6f791ca70640
perf: have a generic "clearstorecache" function
There are multiple places where we will want to purge some store cache. So we
promote the existing _clearobsstore function to a something reusable.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 07 Jun 2017 17:31:30 +0100 |
parents | 326c0e2c1a1d |
children | e36569bd9e28 |
comparison
equal
deleted
inserted
replaced
32730:b8ff7d0ff361 | 32731:6f791ca70640 |
---|---|
355 # - repo.tags of such Mercurial isn't "callable", and repo.tags() | 355 # - repo.tags of such Mercurial isn't "callable", and repo.tags() |
356 # in perftags() causes failure soon | 356 # in perftags() causes failure soon |
357 # - perf.py itself has been available since 1.1 (or eb240755386d) | 357 # - perf.py itself has been available since 1.1 (or eb240755386d) |
358 raise error.Abort(("tags API of this hg command is unknown")) | 358 raise error.Abort(("tags API of this hg command is unknown")) |
359 | 359 |
360 # utilities to clear cache | |
361 | |
362 def clearfilecache(repo, attrname): | |
363 unfi = repo.unfiltered() | |
364 if attrname in vars(unfi): | |
365 delattr(unfi, attrname) | |
366 unfi._filecache.pop(attrname, None) | |
367 | |
360 # perf commands | 368 # perf commands |
361 | 369 |
362 @command('perfwalk', formatteropts) | 370 @command('perfwalk', formatteropts) |
363 def perfwalk(ui, repo, *pats, **opts): | 371 def perfwalk(ui, repo, *pats, **opts): |
364 timer, fm = gettimer(ui, opts) | 372 timer, fm = gettimer(ui, opts) |
1257 else: | 1265 else: |
1258 for r in repo.revs(expr): pass | 1266 for r in repo.revs(expr): pass |
1259 timer(d) | 1267 timer(d) |
1260 fm.end() | 1268 fm.end() |
1261 | 1269 |
1262 def _clearobsstore(repo): | |
1263 unfi = repo.unfiltered() | |
1264 if 'obsstore' in vars(unfi): | |
1265 del unfi.obsstore | |
1266 del unfi._filecache['obsstore'] | |
1267 | |
1268 @command('perfvolatilesets', | 1270 @command('perfvolatilesets', |
1269 [('', 'clear-obsstore', False, 'drop obsstore between each call.'), | 1271 [('', 'clear-obsstore', False, 'drop obsstore between each call.'), |
1270 ] + formatteropts) | 1272 ] + formatteropts) |
1271 def perfvolatilesets(ui, repo, *names, **opts): | 1273 def perfvolatilesets(ui, repo, *names, **opts): |
1272 """benchmark the computation of various volatile set | 1274 """benchmark the computation of various volatile set |
1277 | 1279 |
1278 def getobs(name): | 1280 def getobs(name): |
1279 def d(): | 1281 def d(): |
1280 repo.invalidatevolatilesets() | 1282 repo.invalidatevolatilesets() |
1281 if opts['clear_obsstore']: | 1283 if opts['clear_obsstore']: |
1282 _clearobsstore(repo) | 1284 clearfilecache(repo, 'obsstore') |
1283 obsolete.getrevs(repo, name) | 1285 obsolete.getrevs(repo, name) |
1284 return d | 1286 return d |
1285 | 1287 |
1286 allobs = sorted(obsolete.cachefuncs) | 1288 allobs = sorted(obsolete.cachefuncs) |
1287 if names: | 1289 if names: |
1292 | 1294 |
1293 def getfiltered(name): | 1295 def getfiltered(name): |
1294 def d(): | 1296 def d(): |
1295 repo.invalidatevolatilesets() | 1297 repo.invalidatevolatilesets() |
1296 if opts['clear_obsstore']: | 1298 if opts['clear_obsstore']: |
1297 _clearobsstore(repo) | 1299 clearfilecache(repo, 'obsstore') |
1298 repoview.filterrevs(repo, name) | 1300 repoview.filterrevs(repo, name) |
1299 return d | 1301 return d |
1300 | 1302 |
1301 allfilter = sorted(repoview.filtertable) | 1303 allfilter = sorted(repoview.filtertable) |
1302 if names: | 1304 if names: |