# HG changeset patch # User Pierre-Yves David # Date 2022-07-11 23:13:56 # Node ID 3c5d0f87940434a74da9546dad46fd098818b830 # Parent b380583ad2f56089778a2be205b399c261b95846 perf-unbundle: add a perf command to time the unbundle operation Check documentation for details. diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -2590,6 +2590,51 @@ def perfbdiff(ui, repo, file_, rev=None, @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 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 @@ -188,6 +188,8 @@ perfstatus 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 @@ Test pre-run feature 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 ------------------------------