changeset 50458:714b63a707b7

perf: introduce a `perf::stream-locked-section` command This command benchmark the initial part of a stream clone, where the repository is locked.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 28 Apr 2023 16:28:43 +0200
parents 392e2f31444a
children e1496403b08c
files contrib/perf.py tests/test-contrib-perf.t
diffstat 2 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Wed May 03 18:17:32 2023 -0300
+++ b/contrib/perf.py	Fri Apr 28 16:28:43 2023 +0200
@@ -1900,6 +1900,57 @@
     fm.end()
 
 
+@command(
+    b'perf::stream-locked-section',
+    [
+        (
+            b'',
+            b'stream-version',
+            b'latest',
+            b'stream version to us ("v1", "v2" or "latest", (the default))',
+        ),
+    ]
+    + formatteropts,
+)
+def perf_stream_clone_scan(ui, repo, stream_version, **opts):
+    """benchmark the initial, repo-locked, section of a stream-clone"""
+    import mercurial.streamclone
+
+    generatev1 = mercurial.streamclone.generatev1
+    generatev2 = mercurial.streamclone.generatev2
+
+    opts = _byteskwargs(opts)
+    timer, fm = gettimer(ui, opts)
+
+    # deletion of the generator may trigger some cleanup that we do not want to
+    # measure
+    result_holder = [None]
+
+    def setupone():
+        result_holder[0] = None
+
+    def runone_v1():
+        # the lock is held for the duration the initialisation
+        result_holder[0] = generatev1(repo)
+
+    def runone_v2():
+        # the lock is held for the duration the initialisation
+        result_holder[0] = generatev2(repo, None, None, True)
+
+    if stream_version == b'latest':
+        runone = runone_v2
+    elif stream_version == b'v2':
+        runone = runone_v2
+    elif stream_version == b'v1':
+        runone = runone_v1
+    else:
+        msg = b'unknown stream version: "%s"' % stream_version
+        raise error.Abort(msg)
+
+    timer(runone, setup=setupone, title=b"load")
+    fm.end()
+
+
 @command(b'perf::parents|perfparents', formatteropts)
 def perfparents(ui, repo, **opts):
     """benchmark the time necessary to fetch one changeset's parents.
--- a/tests/test-contrib-perf.t	Wed May 03 18:17:32 2023 -0300
+++ b/tests/test-contrib-perf.t	Fri Apr 28 16:28:43 2023 +0200
@@ -188,6 +188,8 @@
    perf::startup
                  (no help text available)
    perf::status  benchmark the performance of a single status call
+   perf::stream-locked-section
+                 benchmark the initial, repo-locked, section of a stream-clone
    perf::tags    (no help text available)
    perf::templating
                  test the rendering time of a given template