perf: add perfchangegroupchangelog command
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 24 Sep 2016 12:22:30 -0700
changeset 30018 bd6df07ccc24
parent 30017 973cf6c3de30
child 30019 6ca3c54f801b
perf: add perfchangegroupchangelog command This command can be used for testing the performance of producing the changelog portion of a changegroup. We could use additional perf* commands for testing other parts of changegroup. Those can be written another time, when they are needed. (And those may want to refactor the changegroup generation API so code can be reused.) Speaking of code reuse, yes, this command does reinvent a small wheel. I didn't want to scope bloat to change the changegroup API because that will invite bikeshedding.
contrib/perf.py
tests/test-contrib-perf.t
--- a/contrib/perf.py	Sat Sep 24 10:44:37 2016 -0700
+++ b/contrib/perf.py	Sat Sep 24 12:22:30 2016 -0700
@@ -25,6 +25,7 @@
 import sys
 import time
 from mercurial import (
+    changegroup,
     cmdutil,
     commands,
     copies,
@@ -279,6 +280,37 @@
     timer(d)
     fm.end()
 
+@command('perfchangegroupchangelog', formatteropts +
+         [('', 'version', '02', 'changegroup version'),
+          ('r', 'rev', '', 'revisions to add to changegroup')])
+def perfchangegroupchangelog(ui, repo, version='02', rev=None, **opts):
+    """Benchmark producing a changelog group for a changegroup.
+
+    This measures the time spent processing the changelog during a
+    bundle operation. This occurs during `hg bundle` and on a server
+    processing a `getbundle` wire protocol request (handles clones
+    and pull requests).
+
+    By default, all revisions are added to the changegroup.
+    """
+    cl = repo.changelog
+    revs = [cl.lookup(r) for r in repo.revs(rev or 'all()')]
+    bundler = changegroup.getbundler(version, repo)
+
+    def lookup(node):
+        # The real bundler reads the revision in order to access the
+        # manifest node and files list. Do that here.
+        cl.read(node)
+        return node
+
+    def d():
+        for chunk in bundler.group(revs, cl, lookup):
+            pass
+
+    timer, fm = gettimer(ui, opts)
+    timer(d)
+    fm.end()
+
 @command('perfdirs', formatteropts)
 def perfdirs(ui, repo, **opts):
     timer, fm = gettimer(ui, opts)
--- a/tests/test-contrib-perf.t	Sat Sep 24 10:44:37 2016 -0700
+++ b/tests/test-contrib-perf.t	Sat Sep 24 12:22:30 2016 -0700
@@ -53,6 +53,8 @@
    perfbranchmap
                  benchmark the update of a branchmap
    perfcca       (no help text available)
+   perfchangegroupchangelog
+                 Benchmark producing a changelog group for a changegroup.
    perfchangeset
                  (no help text available)
    perfctxfiles  (no help text available)
@@ -112,6 +114,7 @@
   $ hg perfannotate a
   $ hg perfbranchmap
   $ hg perfcca
+  $ hg perfchangegroupchangelog
   $ hg perfchangeset 2
   $ hg perfctxfiles 2
   $ hg perfdiffwd