Patchwork [4,of,4] sshpeer: add support for request tracing

login
register
mail settings
Submitter Boris Feld
Date Jan. 16, 2018, 6:16 p.m.
Message ID <6c6a7d225fef954f6e33.1516126591@FB>
Download mbox | patch
Permalink /patch/26791/
State Superseded
Headers show

Comments

Boris Feld - Jan. 16, 2018, 6:16 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1515757977 0
#      Fri Jan 12 11:52:57 2018 +0000
# Node ID 6c6a7d225fef954f6e33eb734cd3a9ce72b0f85b
# Parent  2d1a4bbddd7e4075b0e082cabf84d901f5b92b5b
# EXP-Topic exchangedebug
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 6c6a7d225fef
sshpeer: add support for request tracing

The new 'devel.debug.peer-request' option now also display some information
about request going through ssh peer.
Yuya Nishihara - Jan. 17, 2018, 1:32 p.m.
On Tue, 16 Jan 2018 19:16:31 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1515757977 0
> #      Fri Jan 12 11:52:57 2018 +0000
> # Node ID 6c6a7d225fef954f6e33eb734cd3a9ce72b0f85b
> # Parent  2d1a4bbddd7e4075b0e082cabf84d901f5b92b5b
> # EXP-Topic exchangedebug
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 6c6a7d225fef
> sshpeer: add support for request tracing

Seems fine.

A few nits. Can you send V2?

> diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
> --- a/mercurial/sshpeer.py
> +++ b/mercurial/sshpeer.py
> @@ -282,6 +282,16 @@ class sshpeer(wireproto.wirepeer):
>          yield wireproto.unescapearg(work)
>  
>      def _callstream(self, cmd, **args):

Needs pycompat.byteskwargs(args) here.

> +        if self.ui.configbool('devel', 'debug.peer-request'):

Perhaps it's better to test ui.debugflag, too. 'devel.*' flag might be
enabled by config file, but this is needed only when --debug is given by
command line.

> +            dbg = self.ui.debug
> +            line = 'devel-peer-request: %s\n'
> +            dbg(line % cmd)
> +            for key, value in sorted(args.items()):
> +                if not isinstance(value, dict):
> +                    dbg(line % '  %s: %d bytes' % (key, len(value)))
> +                else:
> +                    for dk, dv in sorted(value.items()):
> +                        dbg(line % '  %s-%s: %d' % (key, dk, len(value)))
                                                                    ^^^^^
                                                                    dv?
>          args = pycompat.byteskwargs(args)
>          self.ui.debug("sending %s command\n" % cmd)
>          self._pipeo.write("%s\n" % cmd)

Patch

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -282,6 +282,16 @@  class sshpeer(wireproto.wirepeer):
         yield wireproto.unescapearg(work)
 
     def _callstream(self, cmd, **args):
+        if self.ui.configbool('devel', 'debug.peer-request'):
+            dbg = self.ui.debug
+            line = 'devel-peer-request: %s\n'
+            dbg(line % cmd)
+            for key, value in sorted(args.items()):
+                if not isinstance(value, dict):
+                    dbg(line % '  %s: %d bytes' % (key, len(value)))
+                else:
+                    for dk, dv in sorted(value.items()):
+                        dbg(line % '  %s-%s: %d' % (key, dk, len(value)))
         args = pycompat.byteskwargs(args)
         self.ui.debug("sending %s command\n" % cmd)
         self._pipeo.write("%s\n" % cmd)
diff --git a/tests/test-ssh.t b/tests/test-ssh.t
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -478,19 +478,32 @@  stderr from remote commands should be pr
 
 debug output
 
-  $ hg pull --debug ssh://user@dummy/remote
+  $ hg pull --debug ssh://user@dummy/remote --config devel.debug.peer-request=yes
   pulling from ssh://user@dummy/remote
   running .* ".*/dummyssh" ['"]user@dummy['"] ('|")hg -R remote serve --stdio('|") (re)
+  devel-peer-request: hello
   sending hello command
+  devel-peer-request: between
+  devel-peer-request:   pairs: 81 bytes
   sending between command
   remote: 384
   remote: capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS$ unbundle=HG10GZ,HG10BZ,HG10UN
   remote: 1
   query 1; heads
+  devel-peer-request: batch
+  devel-peer-request:   cmds: 141 bytes
   sending batch command
   searching for changes
   all remote heads known locally
   no changes found
+  devel-peer-request: getbundle
+  devel-peer-request:   bookmarks: 1 bytes
+  devel-peer-request:   bundlecaps: 233 bytes
+  devel-peer-request:   cg: 1 bytes
+  devel-peer-request:   common: 122 bytes
+  devel-peer-request:   heads: 122 bytes
+  devel-peer-request:   listkeys: 9 bytes
+  devel-peer-request:   phases: 1 bytes
   sending getbundle command
   bundle2-input-bundle: with-transaction
   bundle2-input-part: "bookmarks" supported