Skip to content

Commit

Permalink
Changes to show the right amount of time (#331)
Browse files Browse the repository at this point in the history
* Changes to take the correct amount of time
* Returned to origial way to calculate ConnTime and added a new time called TCPConnTime. And changed DNSStart check to inside client trace context.
* Added godoc comment to TCPConnTime
* Capitalized TCP and added ending period
  • Loading branch information
JoaquinJimenezGarcia authored May 10, 2020
1 parent ad527eb commit 2f5fe95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ func (r *Request) TraceInfo() TraceInfo {
return TraceInfo{
DNSLookup: ct.dnsDone.Sub(ct.dnsStart),
ConnTime: ct.gotConn.Sub(ct.getConn),
TCPConnTime: ct.connectDone.Sub(ct.dnsDone),
TLSHandshake: ct.tlsHandshakeDone.Sub(ct.tlsHandshakeStart),
ServerTime: ct.gotFirstResponseByte.Sub(ct.gotConn),
ResponseTime: ct.endTime.Sub(ct.gotFirstResponseByte),
Expand Down
21 changes: 15 additions & 6 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type TraceInfo struct {
// ConnTime is a duration that took to obtain a successful connection.
ConnTime time.Duration

// TCPConnTime is a duration that took to obtain the TCP connection.
TCPConnTime time.Duration

// TLSHandshake is a duration that TLS handshake took place.
TLSHandshake time.Duration

Expand Down Expand Up @@ -63,6 +66,7 @@ type TraceInfo struct {
type clientTrace struct {
getConn time.Time
gotConn time.Time
connectDone time.Time
gotFirstResponseByte time.Time
dnsStart time.Time
dnsDone time.Time
Expand All @@ -86,14 +90,19 @@ func (t *clientTrace) createContext(ctx context.Context) context.Context {
DNSDone: func(_ httptrace.DNSDoneInfo) {
t.dnsDone = time.Now()
},
GetConn: func(_ string) {
t.getConn = time.Now()
if t.dnsStart.IsZero() {
t.dnsStart = t.getConn
}
ConnectStart: func(_, _ string) {
if t.dnsDone.IsZero() {
t.dnsDone = t.getConn
t.dnsDone = time.Now()
}
if t.dnsStart.IsZero() {
t.dnsStart = t.dnsDone
}
},
ConnectDone: func(net, addr string, err error) {
t.connectDone = time.Now()
},
GetConn: func(_ string) {
t.getConn = time.Now()
},
GotConn: func(ci httptrace.GotConnInfo) {
t.gotConn = time.Now()
Expand Down

0 comments on commit 2f5fe95

Please sign in to comment.