Close implements the Close method of the Report interface by computing derived summary metrics which don't need to be run on every Add call.
()
| 88 | // Close implements the Close method of the Report interface by computing |
| 89 | // derived summary metrics which don't need to be run on every Add call. |
| 90 | func (m *Metrics) Close() { |
| 91 | m.init() |
| 92 | |
| 93 | if m.Requests == 0 { |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | m.Rate = float64(m.Requests) |
| 98 | m.Throughput = float64(m.success) |
| 99 | m.Duration = m.Latest.Sub(m.Earliest) |
| 100 | m.Wait = m.End.Sub(m.Latest) |
| 101 | if secs := m.Duration.Seconds(); secs > 0 { |
| 102 | m.Rate /= secs |
| 103 | // No need to check for zero because we know m.Duration > 0 |
| 104 | m.Throughput /= (m.Duration + m.Wait).Seconds() |
| 105 | } |
| 106 | |
| 107 | m.BytesIn.Mean = float64(m.BytesIn.Total) / float64(m.Requests) |
| 108 | m.BytesOut.Mean = float64(m.BytesOut.Total) / float64(m.Requests) |
| 109 | m.Success = float64(m.success) / float64(m.Requests) |
| 110 | m.Latencies.Mean = time.Duration(float64(m.Latencies.Total) / float64(m.Requests)) |
| 111 | m.Latencies.P50 = m.Latencies.Quantile(0.50) |
| 112 | m.Latencies.P90 = m.Latencies.Quantile(0.90) |
| 113 | m.Latencies.P95 = m.Latencies.Quantile(0.95) |
| 114 | m.Latencies.P99 = m.Latencies.Quantile(0.99) |
| 115 | } |
| 116 | |
| 117 | func (m *Metrics) init() { |
| 118 | if m.StatusCodes == nil { |