changeset 38771:1732db2f8210 stable

perf: add a perfphasesremote command This command measure the time we spend analysing remote phase during push and pull and display some information relevant to this computation. The `test-contrib-perf.t` expected output has to be updated but I do need these module for this perf command.
author Boris Feld <boris.feld@octobus.net>
date Fri, 17 Aug 2018 17:51:06 +0200
parents 3730b779ed5b
children c89e2fb207a1
files contrib/perf.py tests/test-contrib-perf.t
diffstat 2 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Wed Aug 15 14:43:40 2018 +0200
+++ b/contrib/perf.py	Fri Aug 17 17:51:06 2018 +0200
@@ -791,6 +791,63 @@
     timer(d)
     fm.end()
 
+@command('perfphasesremote',
+         [], "[DEST]")
+def perfphasesremote(ui, repo, dest=None, **opts):
+    """benchmark time needed to analyse phases of the remote server"""
+    from mercurial.node import (
+        bin,
+    )
+    from mercurial import (
+        exchange,
+        hg,
+        phases,
+    )
+    timer, fm = gettimer(ui, opts)
+
+    path = ui.paths.getpath(dest, default=('default-push', 'default'))
+    if not path:
+        raise error.abort(('default repository not configured!'),
+                         hint=("see 'hg help config.paths'"))
+    dest = path.pushloc or path.loc
+    branches = (path.branch, opts.get('branch') or [])
+    ui.status(('analysing phase of %s\n') % util.hidepassword(dest))
+    revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
+    other = hg.peer(repo, opts, dest)
+
+    # easier to perform discovery through the operation
+    op = exchange.pushoperation(repo, other)
+    exchange._pushdiscoverychangeset(op)
+
+    remotesubset = op.fallbackheads
+
+    with other.commandexecutor() as e:
+        remotephases = e.callcommand('listkeys',
+                       {'namespace': 'phases'}).result()
+    del other
+    publishing = remotephases.get('publishing', False)
+    if publishing:
+        ui.status(('publishing: yes\n'))
+    else:
+        ui.status(('publishing: no\n'))
+
+    nodemap = repo.changelog.nodemap
+    nonpublishroots = 0
+    for nhex, phase in remotephases.iteritems():
+        if nhex == 'publishing': # ignore data related to publish option
+            continue
+        node = bin(nhex)
+        if node in nodemap and int(phase):
+            nonpublishroots += 1
+    ui.status(('number of roots: %d\n') % len(remotephases))
+    ui.status(('number of known non public roots: %d\n') % nonpublishroots)
+    def d():
+        phases.remotephasessummary(repo,
+                                   remotesubset,
+                                   remotephases)
+    timer(d)
+    fm.end()
+
 @command('perfmanifest', [], 'REV')
 def perfmanifest(ui, repo, rev, **opts):
     """benchmark the time to read a manifest from disk and return a usable
--- a/tests/test-contrib-perf.t	Wed Aug 15 14:43:40 2018 +0200
+++ b/tests/test-contrib-perf.t	Fri Aug 17 17:51:06 2018 +0200
@@ -99,6 +99,8 @@
    perfpathcopies
                  (no help text available)
    perfphases    benchmark phasesets computation
+   perfphasesremote
+                 benchmark time needed to analyse phases of the remote server
    perfrawfiles  (no help text available)
    perfrevlogchunks
                  Benchmark operations on revlog chunks.
@@ -207,4 +209,7 @@
   contrib/perf.py:\d+: (re)
    >     from mercurial import (
    import newer module separately in try clause for early Mercurial
+  contrib/perf.py:\d+: (re)
+   >     from mercurial import (
+   import newer module separately in try clause for early Mercurial
   [1]