[PATCH] perf: support -T for every perf commands

Augie Fackler raf at durin42.com
Wed Jun 10 09:27:15 CDT 2015


On Tue, Jun 09, 2015 at 03:35:53PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1433888327 25200
> #      Tue Jun 09 15:18:47 2015 -0700
> # Node ID 76eb548e55a55d74cf7ff83b18d11f9443bbb4f4
> # Parent  ad14fb602e5e54e5432fbc776dd5d1bad63f1f68
> perf: support -T for every perf commands

queued, thanks

>
> We are already building a formatter, we can not pass him option the official
> way.
>
> diff --git a/contrib/perf.py b/contrib/perf.py
> --- a/contrib/perf.py
> +++ b/contrib/perf.py
> @@ -4,10 +4,12 @@
>  from mercurial import cmdutil, scmutil, util, commands, obsolete
>  from mercurial import repoview, branchmap, merge, copies
>  import time, os, sys
>  import functools
>
> +formatteropts = commands.formatteropts
> +
>  cmdtable = {}
>  command = cmdutil.command(cmdtable)
>
>  def gettimer(ui, opts=None):
>      """return a timer function and formatter: (timer, formatter)
> @@ -58,13 +60,13 @@ def _timer(fm, func, title=None):
>      fm.write('user', ' user %f', m[1])
>      fm.write('sys',  ' sys %f', m[2])
>      fm.write('count',  ' (best of %d)', count)
>      fm.plain('\n')
>
> - at command('perfwalk')
> -def perfwalk(ui, repo, *pats):
> -    timer, fm = gettimer(ui)
> + at command('perfwalk', formatteropts)
> +def perfwalk(ui, repo, *pats, **opts):
> +    timer, fm = gettimer(ui, opts)
>      try:
>          m = scmutil.match(repo[None], pats, {})
>          timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
>      except Exception:
>          try:
> @@ -72,31 +74,31 @@ def perfwalk(ui, repo, *pats):
>              timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
>          except Exception:
>              timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
>      fm.end()
>
> - at command('perfannotate')
> -def perfannotate(ui, repo, f):
> -    timer, fm = gettimer(ui)
> + at command('perfannotate', formatteropts)
> +def perfannotate(ui, repo, f, **opts):
> +    timer, fm = gettimer(ui, opts)
>      fc = repo['.'][f]
>      timer(lambda: len(fc.annotate(True)))
>      fm.end()
>
>  @command('perfstatus',
>           [('u', 'unknown', False,
> -           'ask status to look for unknown files')])
> +           'ask status to look for unknown files')] + formatteropts)
>  def perfstatus(ui, repo, **opts):
>      #m = match.always(repo.root, repo.getcwd())
>      #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
>      #                                                False))))
> -    timer, fm = gettimer(ui)
> -    timer(lambda: sum(map(len, repo.status(**opts))))
> +    timer, fm = gettimer(ui, **opts)
> +    timer(lambda: sum(map(len, repo.status(unknown=opts['unknown']))))
>      fm.end()
>
> - at command('perfaddremove')
> -def perfaddremove(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfaddremove', formatteropts)
> +def perfaddremove(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      try:
>          oldquiet = repo.ui.quiet
>          repo.ui.quiet = True
>          matcher = scmutil.match(repo[None])
>          timer(lambda: scmutil.addremove(repo, matcher, "", dry_run=True))
> @@ -111,124 +113,124 @@ def clearcaches(cl):
>      elif util.safehasattr(cl, '_nodecache'):
>          from mercurial.node import nullid, nullrev
>          cl._nodecache = {nullid: nullrev}
>          cl._nodepos = None
>
> - at command('perfheads')
> -def perfheads(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfheads', formatteropts)
> +def perfheads(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      cl = repo.changelog
>      def d():
>          len(cl.headrevs())
>          clearcaches(cl)
>      timer(d)
>      fm.end()
>
> - at command('perftags')
> -def perftags(ui, repo):
> + at command('perftags', formatteropts)
> +def perftags(ui, repo, **opts):
>      import mercurial.changelog
>      import mercurial.manifest
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      def t():
>          repo.changelog = mercurial.changelog.changelog(repo.svfs)
>          repo.manifest = mercurial.manifest.manifest(repo.svfs)
>          repo._tags = None
>          return len(repo.tags())
>      timer(t)
>      fm.end()
>
> - at command('perfancestors')
> -def perfancestors(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfancestors', formatteropts)
> +def perfancestors(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      heads = repo.changelog.headrevs()
>      def d():
>          for a in repo.changelog.ancestors(heads):
>              pass
>      timer(d)
>      fm.end()
>
> - at command('perfancestorset')
> -def perfancestorset(ui, repo, revset):
> -    timer, fm = gettimer(ui)
> + at command('perfancestorset', formatteropts)
> +def perfancestorset(ui, repo, revset, **opts):
> +    timer, fm = gettimer(ui, opts)
>      revs = repo.revs(revset)
>      heads = repo.changelog.headrevs()
>      def d():
>          s = repo.changelog.ancestors(heads)
>          for rev in revs:
>              rev in s
>      timer(d)
>      fm.end()
>
> - at command('perfdirs')
> -def perfdirs(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfdirs', formatteropts)
> +def perfdirs(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      dirstate = repo.dirstate
>      'a' in dirstate
>      def d():
>          dirstate.dirs()
>          del dirstate._dirs
>      timer(d)
>      fm.end()
>
> - at command('perfdirstate')
> -def perfdirstate(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfdirstate', formatteropts)
> +def perfdirstate(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      "a" in repo.dirstate
>      def d():
>          repo.dirstate.invalidate()
>          "a" in repo.dirstate
>      timer(d)
>      fm.end()
>
> - at command('perfdirstatedirs')
> -def perfdirstatedirs(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfdirstatedirs', formatteropts)
> +def perfdirstatedirs(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      "a" in repo.dirstate
>      def d():
>          "a" in repo.dirstate._dirs
>          del repo.dirstate._dirs
>      timer(d)
>      fm.end()
>
> - at command('perffilefoldmap')
> -def perffilefoldmap(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfdirstatefoldmap', formatteropts)
> +def perffilefoldmap(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      dirstate = repo.dirstate
>      'a' in dirstate
>      def d():
>          dirstate._filefoldmap.get('a')
>          del dirstate._filefoldmap
>      timer(d)
>      fm.end()
>
> - at command('perfdirfoldmap')
> -def perfdirfoldmap(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfdirfoldmap', formatteropts)
> +def perfdirfoldmap(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      dirstate = repo.dirstate
>      'a' in dirstate
>      def d():
>          dirstate._dirfoldmap.get('a')
>          del dirstate._dirfoldmap
>          del dirstate._dirs
>      timer(d)
>      fm.end()
>
> - at command('perfdirstatewrite')
> -def perfdirstatewrite(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfdirstatewrite', formatteropts)
> +def perfdirstatewrite(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      ds = repo.dirstate
>      "a" in ds
>      def d():
>          ds._dirty = True
>          ds.write()
>      timer(d)
>      fm.end()
>
>  @command('perfmergecalculate',
> -         [('r', 'rev', '.', 'rev to merge against')])
> -def perfmergecalculate(ui, repo, rev):
> -    timer, fm = gettimer(ui)
> +         [('r', 'rev', '.', 'rev to merge against')] + formatteropts)
> +def perfmergecalculate(ui, repo, rev, **opts):
> +    timer, fm = gettimer(ui, opts)
>      wctx = repo[None]
>      rctx = scmutil.revsingle(repo, rev, rev)
>      ancestor = wctx.ancestor(rctx)
>      # we don't want working dir files to be stat'd in the benchmark, so prime
>      # that cache
> @@ -240,107 +242,111 @@ def perfmergecalculate(ui, repo, rev):
>                                 acceptremote=True)
>      timer(d)
>      fm.end()
>
>  @command('perfpathcopies', [], "REV REV")
> -def perfpathcopies(ui, repo, rev1, rev2):
> -    timer, fm = gettimer(ui)
> +def perfpathcopies(ui, repo, rev1, rev2, **opts):
> +    timer, fm = gettimer(ui, opts)
>      ctx1 = scmutil.revsingle(repo, rev1, rev1)
>      ctx2 = scmutil.revsingle(repo, rev2, rev2)
>      def d():
>          copies.pathcopies(ctx1, ctx2)
>      timer(d)
>      fm.end()
>
>  @command('perfmanifest', [], 'REV')
> -def perfmanifest(ui, repo, rev):
> -    timer, fm = gettimer(ui)
> +def perfmanifest(ui, repo, rev, **opts):
> +    timer, fm = gettimer(ui, opts)
>      ctx = scmutil.revsingle(repo, rev, rev)
>      t = ctx.manifestnode()
>      def d():
>          repo.manifest._mancache.clear()
>          repo.manifest._cache = None
>          repo.manifest.read(t)
>      timer(d)
>      fm.end()
>
> - at command('perfchangeset')
> -def perfchangeset(ui, repo, rev):
> -    timer, fm = gettimer(ui)
> + at command('perfchangeset', formatteropts)
> +def perfchangeset(ui, repo, rev, **opts):
> +    timer, fm = gettimer(ui, opts)
>      n = repo[rev].node()
>      def d():
>          repo.changelog.read(n)
>          #repo.changelog._cache = None
>      timer(d)
>      fm.end()
>
> - at command('perfindex')
> -def perfindex(ui, repo):
> + at command('perfindex', formatteropts)
> +def perfindex(ui, repo, **opts):
>      import mercurial.revlog
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
>      n = repo["tip"].node()
>      def d():
>          cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
>          cl.rev(n)
>      timer(d)
>      fm.end()
>
> - at command('perfstartup')
> -def perfstartup(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfstartup', formatteropts)
> +def perfstartup(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      cmd = sys.argv[0]
>      def d():
>          os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
>      timer(d)
>      fm.end()
>
> - at command('perfparents')
> -def perfparents(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfparents', formatteropts)
> +def perfparents(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      nl = [repo.changelog.node(i) for i in xrange(1000)]
>      def d():
>          for n in nl:
>              repo.changelog.parents(n)
>      timer(d)
>      fm.end()
>
> - at command('perfctxfiles')
> -def perfparents(ui, repo, x):
> + at command('perfctxfiles', formatteropts)
> +def perfparents(ui, repo, x, **opts):
>      x = int(x)
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      def d():
>          len(repo[x].files())
>      timer(d)
>      fm.end()
>
> - at command('perfrawfiles')
> -def perfparents(ui, repo, x):
> + at command('perfrawfiles', formatteropts)
> +def perfparents(ui, repo, x, **opts):
>      x = int(x)
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      cl = repo.changelog
>      def d():
>          len(cl.read(x)[3])
>      timer(d)
>      fm.end()
>
> - at command('perflookup')
> -def perflookup(ui, repo, rev):
> -    timer, fm = gettimer(ui)
> + at command('perflookup', formatteropts)
> +def perflookup(ui, repo, rev, **opts):
> +    timer, fm = gettimer(ui, opts)
> +
> + at command('perflookup', formatteropts)
> +def perflookup(ui, repo, rev, **opts):
> +    timer, fm = gettimer(ui, opts)
>      timer(lambda: len(repo.lookup(rev)))
>      fm.end()
>
> - at command('perfrevrange')
> -def perfrevrange(ui, repo, *specs):
> -    timer, fm = gettimer(ui)
> + at command('perfrevrange', formatteropts)
> +def perfrevrange(ui, repo, *specs, **opts):
> +    timer, fm = gettimer(ui, opts)
>      revrange = scmutil.revrange
>      timer(lambda: len(revrange(repo, specs)))
>      fm.end()
>
> - at command('perfnodelookup')
> -def perfnodelookup(ui, repo, rev):
> -    timer, fm = gettimer(ui)
> + at command('perfnodelookup', formatteropts)
> +def perfnodelookup(ui, repo, rev, **opts):
> +    timer, fm = gettimer(ui, opts)
>      import mercurial.revlog
>      mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
>      n = repo[rev].node()
>      cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
>      def d():
> @@ -348,84 +354,84 @@ def perfnodelookup(ui, repo, rev):
>          clearcaches(cl)
>      timer(d)
>      fm.end()
>
>  @command('perflog',
> -         [('', 'rename', False, 'ask log to follow renames')])
> +         [('', 'rename', False, 'ask log to follow renames')] + formatteropts)
>  def perflog(ui, repo, **opts):
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      ui.pushbuffer()
>      timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
>                                 copies=opts.get('rename')))
>      ui.popbuffer()
>      fm.end()
>
> - at command('perfmoonwalk')
> -def perfmoonwalk(ui, repo):
> + at command('perfmoonwalk', formatteropts)
> +def perfmoonwalk(ui, repo, **opts):
>      """benchmark walking the changelog backwards
>
>      This also loads the changelog data for each revision in the changelog.
>      """
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      def moonwalk():
>          for i in xrange(len(repo), -1, -1):
>              ctx = repo[i]
>              ctx.branch() # read changelog data (in addition to the index)
>      timer(moonwalk)
>      fm.end()
>
> - at command('perftemplating')
> -def perftemplating(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perftemplating', formatteropts)
> +def perftemplating(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      ui.pushbuffer()
>      timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
>                                 template='{date|shortdate} [{rev}:{node|short}]'
>                                 ' {author|person}: {desc|firstline}\n'))
>      ui.popbuffer()
>      fm.end()
>
> - at command('perfcca')
> -def perfcca(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perfcca', formatteropts)
> +def perfcca(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
>      fm.end()
>
> - at command('perffncacheload')
> -def perffncacheload(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perffncacheload', formatteropts)
> +def perffncacheload(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      s = repo.store
>      def d():
>          s.fncache._load()
>      timer(d)
>      fm.end()
>
> - at command('perffncachewrite')
> -def perffncachewrite(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perffncachewrite', formatteropts)
> +def perffncachewrite(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      s = repo.store
>      s.fncache._load()
>      def d():
>          s.fncache._dirty = True
>          s.fncache.write()
>      timer(d)
>      fm.end()
>
> - at command('perffncacheencode')
> -def perffncacheencode(ui, repo):
> -    timer, fm = gettimer(ui)
> + at command('perffncacheencode', formatteropts)
> +def perffncacheencode(ui, repo, **opts):
> +    timer, fm = gettimer(ui, opts)
>      s = repo.store
>      s.fncache._load()
>      def d():
>          for p in s.fncache.entries:
>              s.encode(p)
>      timer(d)
>      fm.end()
>
> - at command('perfdiffwd')
> -def perfdiffwd(ui, repo):
> + at command('perfdiffwd', formatteropts)
> +def perfdiffwd(ui, repo, **opts):
>      """Profile diff of working directory changes"""
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      options = {
>          'w': 'ignore_all_space',
>          'b': 'ignore_space_change',
>          'B': 'ignore_blank_lines',
>          }
> @@ -439,14 +445,14 @@ def perfdiffwd(ui, repo):
>          title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
>          timer(d, title)
>      fm.end()
>
>  @command('perfrevlog',
> -         [('d', 'dist', 100, 'distance between the revisions')],
> +         [('d', 'dist', 100, 'distance between the revisions')] + formatteropts,
>           "[INDEXFILE]")
>  def perfrevlog(ui, repo, file_, **opts):
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      from mercurial import revlog
>      dist = opts['dist']
>      def d():
>          r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
>          for x in xrange(0, len(r), dist):
> @@ -454,32 +460,32 @@ def perfrevlog(ui, repo, file_, **opts):
>
>      timer(d)
>      fm.end()
>
>  @command('perfrevset',
> -         [('C', 'clear', False, 'clear volatile cache between each call.')],
> -         "REVSET")
> -def perfrevset(ui, repo, expr, clear=False):
> +         [('C', 'clear', False, 'clear volatile cache between each call.')]
> +         + formatteropts, "REVSET")
> +def perfrevset(ui, repo, expr, clear=False, **opts):
>      """benchmark the execution time of a revset
>
>      Use the --clean option if need to evaluate the impact of build volatile
>      revisions set cache on the revset execution. Volatile cache hold filtered
>      and obsolete related cache."""
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      def d():
>          if clear:
>              repo.invalidatevolatilesets()
>          for r in repo.revs(expr): pass
>      timer(d)
>      fm.end()
>
> - at command('perfvolatilesets')
> -def perfvolatilesets(ui, repo, *names):
> + at command('perfvolatilesets', formatteropts)
> +def perfvolatilesets(ui, repo, *names, **opts):
>      """benchmark the computation of various volatile set
>
>      Volatile set computes element related to filtering and obsolescence."""
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      repo = repo.unfiltered()
>
>      def getobs(name):
>          def d():
>              repo.invalidatevolatilesets()
> @@ -508,17 +514,17 @@ def perfvolatilesets(ui, repo, *names):
>      fm.end()
>
>  @command('perfbranchmap',
>           [('f', 'full', False,
>             'Includes build time of subset'),
> -         ])
> -def perfbranchmap(ui, repo, full=False):
> +         ] + formatteropts)
> +def perfbranchmap(ui, repo, full=False, **opts):
>      """benchmark the update of a branchmap
>
>      This benchmarks the full repo.branchmap() call with read and write disabled
>      """
> -    timer, fm = gettimer(ui)
> +    timer, fm = gettimer(ui, opts)
>      def getbranchmap(filtername):
>          """generate a benchmark function for the filtername"""
>          if filtername is None:
>              view = repo
>          else:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list