changeset 49411:b081a5aab782

perf-bundle: add a new command to benchmark bundle creation time
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 11 Jul 2022 22:50:59 +0200
parents 2bbd7bc7d6c4
children 3635aae8b2e9
files contrib/perf.py tests/test-contrib-perf.t
diffstat 2 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Tue Jul 12 01:34:18 2022 +0200
+++ b/contrib/perf.py	Mon Jul 11 22:50:59 2022 +0200
@@ -974,6 +974,56 @@
     fm.end()
 
 
+@command(b'perf::bundle', formatteropts, b'REVS')
+def perfbundle(ui, repo, *revs, **opts):
+    """benchmark the creation of a bundle from a repository
+
+    For now, this create a `none-v1` bundle.
+    """
+    from mercurial import bundlecaches
+    from mercurial import discovery
+    from mercurial import bundle2
+
+    opts = _byteskwargs(opts)
+    timer, fm = gettimer(ui, opts)
+
+    cl = repo.changelog
+    revs = scmutil.revrange(repo, revs)
+    if not revs:
+        raise error.Abort(b"not revision specified")
+    # make it a consistent set (ie: without topological gaps)
+    old_len = len(revs)
+    revs = list(repo.revs(b"%ld::%ld", revs, revs))
+    if old_len != len(revs):
+        new_count = len(revs) - old_len
+        msg = b"add %d new revisions to make it a consistent set\n"
+        ui.write_err(msg % new_count)
+
+    targets = [cl.node(r) for r in repo.revs(b"heads(::%ld)", revs)]
+    bases = [cl.node(r) for r in repo.revs(b"heads(::%ld - %ld)", revs, revs)]
+    outgoing = discovery.outgoing(repo, bases, targets)
+
+    bundlespec = bundlecaches.parsebundlespec(
+        repo, b"none", strict=False
+    )
+
+    bversion = b'HG10' + bundlespec.wirecompression
+
+    def do_bundle():
+        bundle2.writenewbundle(
+            ui,
+            repo,
+            b'perf::bundle',
+            os.devnull,
+            bversion,
+            outgoing,
+            {},
+        )
+
+    timer(do_bundle)
+    fm.end()
+
+
 @command(b'perf::bundleread|perfbundleread', formatteropts, b'BUNDLE')
 def perfbundleread(ui, repo, bundlepath, **opts):
     """Benchmark reading of bundle files.
--- a/tests/test-contrib-perf.t	Tue Jul 12 01:34:18 2022 +0200
+++ b/tests/test-contrib-perf.t	Mon Jul 11 22:50:59 2022 +0200
@@ -96,6 +96,7 @@
    perf::branchmapupdate
                  benchmark branchmap update from for <base> revs to <target>
                  revs
+   perf::bundle  benchmark the creation of a bundle from a repository
    perf::bundleread
                  Benchmark reading of bundle files.
    perf::cca     (no help text available)
@@ -385,6 +386,7 @@
   searching for changes
   searching for changes
   searching for changes
+  $ hg perf::bundle 'last(all(), 5)'
 
 test  profile-benchmark option
 ------------------------------