]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add some timing code to Client.dialFirst
authorMatt Joiner <anacrolix@gmail.com>
Thu, 15 Aug 2019 00:17:39 +0000 (10:17 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 15 Aug 2019 00:17:39 +0000 (10:17 +1000)
client.go

index a3d6fca466c3b54d8916d8271ceed0b9d322c007..85b78c4cae1e0190df3b3d72abe1c9078e48580c 100644 (file)
--- 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()()