Patchwork [1,of,2] perf: use standard arguments for perfrevlog

login
register
mail settings
Submitter Gregory Szorc
Date Dec. 22, 2015, 6:49 a.m.
Message ID <4e4279304032983bca4c.1450766993@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/12235/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Gregory Szorc - Dec. 22, 2015, 6:49 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1450669555 28800
#      Sun Dec 20 19:45:55 2015 -0800
# Node ID 4e4279304032983bca4c28eba354cbe53df9e1e8
# Parent  3dea4eae4eebac11741f0c1dc5dcd9c88d8f4554
perf: use standard arguments for perfrevlog

We have a convention of using -c|-m|FILE elsewhere for reading from
revlogs. Use it for `hg perfrevlog`.

While I was here, I also added a docstring to document what this
command does, as "perfrevlog" is ambiguous.
Yuya Nishihara - Dec. 23, 2015, 11:06 a.m.
On Mon, 21 Dec 2015 22:49:53 -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1450669555 28800
> #      Sun Dec 20 19:45:55 2015 -0800
> # Node ID 4e4279304032983bca4c28eba354cbe53df9e1e8
> # Parent  3dea4eae4eebac11741f0c1dc5dcd9c88d8f4554
> perf: use standard arguments for perfrevlog

Looks good. Pushed the series to the clowncopter, thanks.

> +def perfrevlog(ui, repo, file_=None, **opts):
> +    """Benchmark reading a series of revisions from a revlog.

Command help generally starts with lowercase letter, but perf.py has somehow
both styles. So I didn't change it in flight.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -469,26 +469,30 @@  def perfdiffwd(ui, repo, **opts):
         def d():
             ui.pushbuffer()
             commands.diff(ui, repo, **opts)
             ui.popbuffer()
         title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
         timer(d, title)
     fm.end()
 
-@command('perfrevlog',
-         [('d', 'dist', 100, 'distance between the revisions')] + formatteropts,
-         "[INDEXFILE]")
-def perfrevlog(ui, repo, file_, **opts):
+@command('perfrevlog', revlogopts + formatteropts +
+         [('d', 'dist', 100, 'distance between the revisions')],
+         '-c|-m|FILE')
+def perfrevlog(ui, repo, file_=None, **opts):
+    """Benchmark reading a series of revisions from a revlog.
+
+    By default, we read every ``-d/--dist`` revision from 0 to tip of
+    the specified revlog.
+    """
     timer, fm = gettimer(ui, opts)
-    from mercurial import revlog
     dist = opts['dist']
     _len = getlen(ui)
     def d():
-        r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
+        r = cmdutil.openrevlog(repo, 'perfrevlog', file_, opts)
         for x in xrange(0, _len(r), dist):
             r.revision(r.node(x))
 
     timer(d)
     fm.end()
 
 @command('perfrevlogrevision', revlogopts + formatteropts +
          [('', 'cache', False, 'use caches instead of clearing')],
diff --git a/tests/test-contrib-perf.t b/tests/test-contrib-perf.t
--- a/tests/test-contrib-perf.t
+++ b/tests/test-contrib-perf.t
@@ -85,17 +85,17 @@  perfstatus
                  (no help text available)
    perfmoonwalk  benchmark walking the changelog backwards
    perfnodelookup
                  (no help text available)
    perfparents   (no help text available)
    perfpathcopies
                  (no help text available)
    perfrawfiles  (no help text available)
-   perfrevlog    (no help text available)
+   perfrevlog    Benchmark reading a series of revisions from a revlog.
    perfrevlogrevision
                  Benchmark obtaining a revlog revision.
    perfrevrange  (no help text available)
    perfrevset    benchmark the execution time of a revset
    perfstartup   (no help text available)
    perfstatus    (no help text available)
    perftags      (no help text available)
    perftemplating