From e3e4a11b1637e91d5d34b5be915d60c5bd010fe8 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 15 Aug 2019 10:17:39 +1000 Subject: [PATCH] Add some timing code to Client.dialFirst --- client.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index a3d6fca4..85b78c4c 100644 --- a/client.go +++ b/client.go @@ -505,7 +505,17 @@ func (cl *Client) dopplegangerAddr(addr string) bool { } // Returns a connection over UTP or TCP, whichever is first to connect. -func (cl *Client) dialFirst(ctx context.Context, addr string) dialResult { +func (cl *Client) dialFirst(ctx context.Context, addr string) (res dialResult) { + { + t := perf.NewTimer(perf.CallerName(0)) + defer func() { + if res.Conn == nil { + t.Mark(fmt.Sprintf("returned no conn (context: %v)", ctx.Err())) + } else { + t.Mark("returned conn over " + res.Network) + } + }() + } ctx, cancel := context.WithCancel(ctx) // As soon as we return one connection, cancel the others. defer cancel() @@ -532,7 +542,6 @@ func (cl *Client) dialFirst(ctx context.Context, addr string) dialResult { return true }) }() - var res dialResult // Wait for a successful connection. func() { defer perf.ScopeTimer()() -- 2.48.1