From: Matt Joiner Date: Thu, 15 Aug 2019 00:17:39 +0000 (+1000) Subject: Add some timing code to Client.dialFirst X-Git-Tag: v1.6.0~1 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e3e4a11b1637e91d5d34b5be915d60c5bd010fe8;p=btrtrc.git Add some timing code to Client.dialFirst --- 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()()