MCPcopy Create free account
hub / github.com/imroc/req / TraceInfo

Method TraceInfo

request.go:84–152  ·  view source on GitHub ↗

TraceInfo returns the trace information, only available if trace is enabled (see Request.EnableTrace and Client.EnableTraceAll).

()

Source from the content-addressed store, hash-verified

82// TraceInfo returns the trace information, only available if trace is enabled
83// (see Request.EnableTrace and Client.EnableTraceAll).
84func (r *Request) TraceInfo() TraceInfo {
85 ct := r.trace
86
87 if ct == nil {
88 return TraceInfo{}
89 }
90
91 ti := TraceInfo{
92 IsConnReused: ct.gotConnInfo.Reused,
93 IsConnWasIdle: ct.gotConnInfo.WasIdle,
94 ConnIdleTime: ct.gotConnInfo.IdleTime,
95 }
96
97 endTime := ct.endTime
98 if endTime.IsZero() { // in case timeout
99 endTime = r.responseReturnTime
100 }
101
102 if !ct.tlsHandshakeStart.IsZero() {
103 if !ct.tlsHandshakeDone.IsZero() {
104 ti.TLSHandshakeTime = ct.tlsHandshakeDone.Sub(ct.tlsHandshakeStart)
105 } else {
106 ti.TLSHandshakeTime = endTime.Sub(ct.tlsHandshakeStart)
107 }
108 }
109
110 if ct.gotConnInfo.Reused {
111 ti.TotalTime = endTime.Sub(ct.getConn)
112 } else {
113 if ct.dnsStart.IsZero() {
114 ti.TotalTime = endTime.Sub(r.StartTime)
115 } else {
116 ti.TotalTime = endTime.Sub(ct.dnsStart)
117 }
118 }
119
120 dnsDone := ct.dnsDone
121 if dnsDone.IsZero() {
122 dnsDone = endTime
123 }
124
125 if !ct.dnsStart.IsZero() {
126 ti.DNSLookupTime = dnsDone.Sub(ct.dnsStart)
127 }
128
129 // Only calculate on successful connections
130 if !ct.connectDone.IsZero() {
131 ti.TCPConnectTime = ct.connectDone.Sub(dnsDone)
132 }
133
134 // Only calculate on successful connections
135 if !ct.gotConn.IsZero() {
136 ti.ConnectTime = ct.gotConn.Sub(ct.getConn)
137 }
138
139 // Only calculate on successful connections
140 if !ct.gotFirstResponseByte.IsZero() {
141 ti.FirstResponseTime = ct.gotFirstResponseByte.Sub(ct.gotConn)

Callers 3

TestTraceAllFunction · 0.45
assertTraceInfoFunction · 0.45
TestTraceOnTimeoutFunction · 0.45

Calls 3

IsZeroMethod · 0.80
RemoteAddrMethod · 0.45
LocalAddrMethod · 0.45

Tested by 3

TestTraceAllFunction · 0.36
assertTraceInfoFunction · 0.36
TestTraceOnTimeoutFunction · 0.36