contrib/perf.py
changeset 30146 148ccd1d9f2f
parent 30145 113aa6145020
child 30147 423bf74d2e5b
equal deleted inserted replaced
30145:113aa6145020 30146:148ccd1d9f2f
   230     # branchmap and repoview modules exist, but subsettable attribute
   230     # branchmap and repoview modules exist, but subsettable attribute
   231     # doesn't)
   231     # doesn't)
   232     raise error.Abort(("perfbranchmap not available with this Mercurial"),
   232     raise error.Abort(("perfbranchmap not available with this Mercurial"),
   233                       hint="use 2.5 or later")
   233                       hint="use 2.5 or later")
   234 
   234 
       
   235 def getsvfs(repo):
       
   236     """Return appropriate object to access files under .hg/store
       
   237     """
       
   238     # for "historical portability":
       
   239     # repo.svfs has been available since 2.3 (or 7034365089bf)
       
   240     svfs = getattr(repo, 'svfs', None)
       
   241     if svfs:
       
   242         return svfs
       
   243     else:
       
   244         return getattr(repo, 'sopener')
       
   245 
       
   246 def getvfs(repo):
       
   247     """Return appropriate object to access files under .hg
       
   248     """
       
   249     # for "historical portability":
       
   250     # repo.vfs has been available since 2.3 (or 7034365089bf)
       
   251     vfs = getattr(repo, 'vfs', None)
       
   252     if vfs:
       
   253         return vfs
       
   254     else:
       
   255         return getattr(repo, 'opener')
       
   256 
   235 # perf commands
   257 # perf commands
   236 
   258 
   237 @command('perfwalk', formatteropts)
   259 @command('perfwalk', formatteropts)
   238 def perfwalk(ui, repo, *pats, **opts):
   260 def perfwalk(ui, repo, *pats, **opts):
   239     timer, fm = gettimer(ui, opts)
   261     timer, fm = gettimer(ui, opts)
   300 @command('perftags', formatteropts)
   322 @command('perftags', formatteropts)
   301 def perftags(ui, repo, **opts):
   323 def perftags(ui, repo, **opts):
   302     import mercurial.changelog
   324     import mercurial.changelog
   303     import mercurial.manifest
   325     import mercurial.manifest
   304     timer, fm = gettimer(ui, opts)
   326     timer, fm = gettimer(ui, opts)
       
   327     svfs = getsvfs(repo)
   305     def t():
   328     def t():
   306         repo.changelog = mercurial.changelog.changelog(repo.svfs)
   329         repo.changelog = mercurial.changelog.changelog(svfs)
   307         repo.manifest = mercurial.manifest.manifest(repo.svfs)
   330         repo.manifest = mercurial.manifest.manifest(svfs)
   308         repo._tags = None
   331         repo._tags = None
   309         return len(repo.tags())
   332         return len(repo.tags())
   310     timer(t)
   333     timer(t)
   311     fm.end()
   334     fm.end()
   312 
   335 
   481 def perfindex(ui, repo, **opts):
   504 def perfindex(ui, repo, **opts):
   482     import mercurial.revlog
   505     import mercurial.revlog
   483     timer, fm = gettimer(ui, opts)
   506     timer, fm = gettimer(ui, opts)
   484     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
   507     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
   485     n = repo["tip"].node()
   508     n = repo["tip"].node()
   486     def d():
   509     svfs = getsvfs(repo)
   487         cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
   510     def d():
       
   511         cl = mercurial.revlog.revlog(svfs, "00changelog.i")
   488         cl.rev(n)
   512         cl.rev(n)
   489     timer(d)
   513     timer(d)
   490     fm.end()
   514     fm.end()
   491 
   515 
   492 @command('perfstartup', formatteropts)
   516 @command('perfstartup', formatteropts)
   554 def perfnodelookup(ui, repo, rev, **opts):
   578 def perfnodelookup(ui, repo, rev, **opts):
   555     timer, fm = gettimer(ui, opts)
   579     timer, fm = gettimer(ui, opts)
   556     import mercurial.revlog
   580     import mercurial.revlog
   557     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
   581     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
   558     n = repo[rev].node()
   582     n = repo[rev].node()
   559     cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
   583     cl = mercurial.revlog.revlog(getsvfs(repo), "00changelog.i")
   560     def d():
   584     def d():
   561         cl.rev(n)
   585         cl.rev(n)
   562         clearcaches(cl)
   586         clearcaches(cl)
   563     timer(d)
   587     timer(d)
   564     fm.end()
   588     fm.end()
   901 def perfloadmarkers(ui, repo):
   925 def perfloadmarkers(ui, repo):
   902     """benchmark the time to parse the on-disk markers for a repo
   926     """benchmark the time to parse the on-disk markers for a repo
   903 
   927 
   904     Result is the number of markers in the repo."""
   928     Result is the number of markers in the repo."""
   905     timer, fm = gettimer(ui)
   929     timer, fm = gettimer(ui)
   906     timer(lambda: len(obsolete.obsstore(repo.svfs)))
   930     svfs = getsvfs(repo)
       
   931     timer(lambda: len(obsolete.obsstore(svfs)))
   907     fm.end()
   932     fm.end()
   908 
   933 
   909 @command('perflrucachedict', formatteropts +
   934 @command('perflrucachedict', formatteropts +
   910     [('', 'size', 4, 'size of cache'),
   935     [('', 'size', 4, 'size of cache'),
   911      ('', 'gets', 10000, 'number of key lookups'),
   936      ('', 'gets', 10000, 'number of key lookups'),