contrib/perf.py
changeset 30451 94ca0e13d1fc
parent 30426 605e3b126d46
child 30584 be5b2098a817
equal deleted inserted replaced
30450:0acf3fd718f1 30451:94ca0e13d1fc
   857             r.revision(r.node(x))
   857             r.revision(r.node(x))
   858 
   858 
   859     timer(d)
   859     timer(d)
   860     fm.end()
   860     fm.end()
   861 
   861 
       
   862 @command('perfrevlogchunks', revlogopts + formatteropts +
       
   863          [('s', 'startrev', 0, 'revision to start at')],
       
   864          '-c|-m|FILE')
       
   865 def perfrevlogchunks(ui, repo, file_=None, startrev=0, **opts):
       
   866     """Benchmark operations on revlog chunks.
       
   867 
       
   868     Logically, each revlog is a collection of fulltext revisions. However,
       
   869     stored within each revlog are "chunks" of possibly compressed data. This
       
   870     data needs to be read and decompressed or compressed and written.
       
   871 
       
   872     This command measures the time it takes to read+decompress and recompress
       
   873     chunks in a revlog. It effectively isolates I/O and compression performance.
       
   874     For measurements of higher-level operations like resolving revisions,
       
   875     see ``perfrevlog`` and ``perfrevlogrevision``.
       
   876     """
       
   877     rl = cmdutil.openrevlog(repo, 'perfrevlogchunks', file_, opts)
       
   878     revs = list(rl.revs(startrev, len(rl) - 1))
       
   879 
       
   880     def rlfh(rl):
       
   881         if rl._inline:
       
   882             return getsvfs(repo)(rl.indexfile)
       
   883         else:
       
   884             return getsvfs(repo)(rl.datafile)
       
   885 
       
   886     def doread():
       
   887         rl.clearcaches()
       
   888         for rev in revs:
       
   889             rl._chunkraw(rev, rev)
       
   890 
       
   891     def doreadcachedfh():
       
   892         rl.clearcaches()
       
   893         fh = rlfh(rl)
       
   894         for rev in revs:
       
   895             rl._chunkraw(rev, rev, df=fh)
       
   896 
       
   897     def doreadbatch():
       
   898         rl.clearcaches()
       
   899         rl._chunkraw(revs[0], revs[-1])
       
   900 
       
   901     def doreadbatchcachedfh():
       
   902         rl.clearcaches()
       
   903         fh = rlfh(rl)
       
   904         rl._chunkraw(revs[0], revs[-1], df=fh)
       
   905 
       
   906     def dochunk():
       
   907         rl.clearcaches()
       
   908         fh = rlfh(rl)
       
   909         for rev in revs:
       
   910             rl._chunk(rev, df=fh)
       
   911 
       
   912     chunks = [None]
       
   913 
       
   914     def dochunkbatch():
       
   915         rl.clearcaches()
       
   916         fh = rlfh(rl)
       
   917         # Save chunks as a side-effect.
       
   918         chunks[0] = rl._chunks(revs, df=fh)
       
   919 
       
   920     def docompress():
       
   921         rl.clearcaches()
       
   922         for chunk in chunks[0]:
       
   923             rl.compress(chunk)
       
   924 
       
   925     benches = [
       
   926         (lambda: doread(), 'read'),
       
   927         (lambda: doreadcachedfh(), 'read w/ reused fd'),
       
   928         (lambda: doreadbatch(), 'read batch'),
       
   929         (lambda: doreadbatchcachedfh(), 'read batch w/ reused fd'),
       
   930         (lambda: dochunk(), 'chunk'),
       
   931         (lambda: dochunkbatch(), 'chunk batch'),
       
   932         (lambda: docompress(), 'compress'),
       
   933     ]
       
   934 
       
   935     for fn, title in benches:
       
   936         timer, fm = gettimer(ui, opts)
       
   937         timer(fn, title=title)
       
   938         fm.end()
       
   939 
   862 @command('perfrevlogrevision', revlogopts + formatteropts +
   940 @command('perfrevlogrevision', revlogopts + formatteropts +
   863          [('', 'cache', False, 'use caches instead of clearing')],
   941          [('', 'cache', False, 'use caches instead of clearing')],
   864          '-c|-m|FILE REV')
   942          '-c|-m|FILE REV')
   865 def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
   943 def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
   866     """Benchmark obtaining a revlog revision.
   944     """Benchmark obtaining a revlog revision.