perf-unbundle: add a perf command to time the unbundle operation
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 12 Jul 2022 01:13:56 +0200
changeset 49414 3c5d0f879404
parent 49413 b380583ad2f5
child 49415 5fe7e9eda0f3
perf-unbundle: add a perf command to time the unbundle operation Check documentation for details.
contrib/perf.py
tests/test-contrib-perf.t
--- a/contrib/perf.py	Mon Jul 11 23:30:24 2022 +0200
+++ b/contrib/perf.py	Tue Jul 12 01:13:56 2022 +0200
@@ -2590,6 +2590,51 @@
 
 
 @command(
+    b'perf::unbundle',
+    formatteropts,
+    b'BUNDLE_FILE',
+)
+def perf_unbundle(ui, repo, fname, **opts):
+    """benchmark application of a bundle in a repository.
+
+    This does not include the final transaction processing"""
+    from mercurial import exchange
+    from mercurial import bundle2
+
+    with repo.lock():
+        bundle = [None, None]
+        try:
+            with open(fname, mode="rb") as f:
+
+                def setup():
+                    gen, tr = bundle
+                    if tr is not None:
+                        tr.abort()
+                    bundle[:] = [None, None]
+                    f.seek(0)
+                    bundle[0] = exchange.readbundle(ui, f, fname)
+                    bundle[1] = repo.transaction(b'perf::unbundle')
+
+                def apply():
+                    gen, tr = bundle
+                    bundle2.applybundle(
+                        repo,
+                        gen,
+                        tr,
+                        source=b'perf::unbundle',
+                        url=fname,
+                    )
+
+                timer, fm = gettimer(ui, opts)
+                timer(apply, setup=setup)
+                fm.end()
+        finally:
+            gen, tr = bundle
+            if tr is not None:
+                tr.abort()
+
+
+@command(
     b'perf::unidiff|perfunidiff',
     revlogopts
     + formatteropts
--- a/tests/test-contrib-perf.t	Mon Jul 11 23:30:24 2022 +0200
+++ b/tests/test-contrib-perf.t	Tue Jul 12 01:13:56 2022 +0200
@@ -188,6 +188,8 @@
    perf::tags    (no help text available)
    perf::templating
                  test the rendering time of a given template
+   perf::unbundle
+                 benchmark application of a bundle in a repository.
    perf::unidiff
                  benchmark a unified diff between revisions
    perf::volatilesets
@@ -387,6 +389,15 @@
   searching for changes
   searching for changes
   $ hg perf::bundle 'last(all(), 5)'
+  $ hg bundle --exact --rev 'last(all(), 5)' last-5.hg
+  4 changesets found
+  $ hg perf::unbundle last-5.hg
+  adding changesets
+  adding manifests
+  adding file changes
+  transaction abort!
+  rollback completed
+
 
 test  profile-benchmark option
 ------------------------------