MCPcopy
hub / github.com/tsenart/vegeta / Close

Method Close

lib/metrics.go:90–115  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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.
90func (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
117func (m *Metrics) init() {
118 if m.StatusCodes == nil {

Callers 7

decodeMetricsFunction · 0.95
TestAttackDurationFunction · 0.95
TestMetrics_AddFunction · 0.95
BenchmarkMetricsFunction · 0.95

Calls 2

initMethod · 0.95
QuantileMethod · 0.80

Tested by 7

decodeMetricsFunction · 0.76
TestAttackDurationFunction · 0.76
TestMetrics_AddFunction · 0.76
BenchmarkMetricsFunction · 0.76