Patchwork [2,of,4] perf: add perfchangegroupchangelog command

login
register
mail settings
Submitter Gregory Szorc
Date Sept. 24, 2016, 7:37 p.m.
Message ID <af899e2937e1a8058e82.1474745837@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16780/
State Accepted
Headers show

Comments

Gregory Szorc - Sept. 24, 2016, 7:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1474744950 25200
#      Sat Sep 24 12:22:30 2016 -0700
# Node ID af899e2937e1a8058e82e3eaf6b2160f6cf98fa9
# Parent  4567ac4e7248ace445195b9de10720bf54d47a7d
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.
Pierre-Yves David - Sept. 27, 2016, 2:37 p.m.
On 09/24/2016 09:37 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1474744950 25200
> #      Sat Sep 24 12:22:30 2016 -0700
> # Node ID af899e2937e1a8058e82e3eaf6b2160f6cf98fa9
> # Parent  4567ac4e7248ace445195b9de10720bf54d47a7d
> 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.

I've pushed the first two. Patch 3 looks fine but is a bit too entangled 
with patch 4 which I've some question on.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -20,16 +20,17 @@ 
 
 from __future__ import absolute_import
 import functools
 import os
 import random
 import sys
 import time
 from mercurial import (
+    changegroup,
     cmdutil,
     commands,
     copies,
     error,
     extensions,
     mdiff,
     merge,
     revlog,
@@ -274,16 +275,47 @@  def perfancestorset(ui, repo, revset, **
     heads = repo.changelog.headrevs()
     def d():
         s = repo.changelog.ancestors(heads)
         for rev in revs:
             rev in s
     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)
     dirstate = repo.dirstate
     'a' in dirstate
     def d():
         dirstate.dirs()
         del dirstate._dirs
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
@@ -48,16 +48,18 @@  perfstatus
    perfancestors
                  (no help text available)
    perfancestorset
                  (no help text available)
    perfannotate  (no help text available)
    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)
    perfdiffwd    Profile diff of working directory changes
    perfdirfoldmap
                  (no help text available)
    perfdirs      (no help text available)
    perfdirstate  (no help text available)
@@ -107,16 +109,17 @@  perfstatus
   
   (use 'hg help -v perfstatusext' to show built-in aliases and global options)
   $ hg perfaddremove
   $ hg perfancestors
   $ hg perfancestorset 2
   $ hg perfannotate a
   $ hg perfbranchmap
   $ hg perfcca
+  $ hg perfchangegroupchangelog
   $ hg perfchangeset 2
   $ hg perfctxfiles 2
   $ hg perfdiffwd
   $ hg perfdirfoldmap
   $ hg perfdirs
   $ hg perfdirstate
   $ hg perfdirstatedirs
   $ hg perfdirstatefoldmap