Skip to content

Commit 3dd8421

Browse files
erwinvaneykrakyll
authored andcommitted
Add request offset to csv (#126)
1 parent 9fdda5a commit 3dd8421

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

requester/print.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/*
16+
Hey supports two output formats: summary and CSV
17+
18+
The summary output presents a number of statistics about the requests in a
19+
human-readable format, including:
20+
- general statistics: requests/second, total runtime, and average, fastest, and slowest requests.
21+
- a response time histogram.
22+
- a percentile latency distribution.
23+
- statistics (average, fastest, slowest) on the stages of the requests.
24+
25+
The comma-separated CSV format is proceeded by a header, and consists of the following columns:
26+
1. response-time: Total time taken for request (in seconds)
27+
2. DNS+dialup: Time taken to establish the TCP connection (in seconds)
28+
3. DNS: Time taken to do the DNS lookup (in seconds)
29+
4. Request-write: Time taken to write full request (in seconds)
30+
5. Response-delay: Time taken to first byte received (in seconds)
31+
6. Response-read: Time taken to read full response (in seconds)
32+
7. status-code: HTTP status code of the response (e.g. 200)
33+
8. offset: The time since the start of the benchmark when the request was started. (in seconds)
34+
*/
1535
package requester
1636

1737
import (
@@ -103,7 +123,6 @@ Status code distribution:{{ range $code, $num := .StatusCodeDist }}
103123
{{ if gt (len .ErrorDist) 0 }}Error distribution:{{ range $err, $num := .ErrorDist }}
104124
[{{ $num }}] {{ $err }}{{ end }}{{ end }}
105125
`
106-
csvTmpl = `{{ $connLats := .ConnLats }}{{ $dnsLats := .DnsLats }}{{ $dnsLats := .DnsLats }}{{ $reqLats := .ReqLats }}{{ $delayLats := .DelayLats }}{{ $resLats := .ResLats }}{{ $statusCodeLats := .StatusCodes }}
107-
response-time,DNS+dialup,DNS,Request-write,Response-delay,Response-read,status-code{{ range $i, $v := .Lats }}
108-
{{ formatNumber $v }},{{ formatNumber (index $connLats $i) }},{{ formatNumber (index $dnsLats $i) }},{{ formatNumber (index $reqLats $i) }},{{ formatNumber (index $delayLats $i) }},{{ formatNumber (index $resLats $i) }},{{ formatNumberInt (index $statusCodeLats $i) }}{{ end }}`
126+
csvTmpl = `{{ $connLats := .ConnLats }}{{ $dnsLats := .DnsLats }}{{ $dnsLats := .DnsLats }}{{ $reqLats := .ReqLats }}{{ $delayLats := .DelayLats }}{{ $resLats := .ResLats }}{{ $statusCodeLats := .StatusCodes }}{{ $offsets := .Offsets}}response-time,DNS+dialup,DNS,Request-write,Response-delay,Response-read,status-code,offset{{ range $i, $v := .Lats }}
127+
{{ formatNumber $v }},{{ formatNumber (index $connLats $i) }},{{ formatNumber (index $dnsLats $i) }},{{ formatNumber (index $reqLats $i) }},{{ formatNumber (index $delayLats $i) }},{{ formatNumber (index $resLats $i) }},{{ formatNumberInt (index $statusCodeLats $i) }},{{ formatNumber (index $offsets $i) }}{{ end }}`
109128
)

requester/report.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type report struct {
4747
reqLats []float64
4848
resLats []float64
4949
delayLats []float64
50+
offsets []float64
5051
statusCodes []int
5152

5253
results chan *result
@@ -101,6 +102,7 @@ func runReporter(r *report) {
101102
r.delayLats = append(r.delayLats, res.delayDuration.Seconds())
102103
r.resLats = append(r.resLats, res.resDuration.Seconds())
103104
r.statusCodes = append(r.statusCodes, res.statusCode)
105+
r.offsets = append(r.offsets, res.offset.Seconds())
104106
}
105107
if res.contentLength > 0 {
106108
r.sizeTotal += res.contentLength
@@ -158,6 +160,7 @@ func (r *report) snapshot() Report {
158160
ReqLats: make([]float64, len(r.lats)),
159161
ResLats: make([]float64, len(r.lats)),
160162
DelayLats: make([]float64, len(r.lats)),
163+
Offsets: make([]float64, len(r.lats)),
161164
StatusCodes: make([]int, len(r.lats)),
162165
}
163166

@@ -174,6 +177,7 @@ func (r *report) snapshot() Report {
174177
copy(snapshot.ResLats, r.resLats)
175178
copy(snapshot.DelayLats, r.delayLats)
176179
copy(snapshot.StatusCodes, r.statusCodes)
180+
copy(snapshot.Offsets, r.offsets)
177181

178182
sort.Float64s(r.lats)
179183
r.fastest = r.lats[0]
@@ -292,6 +296,7 @@ type Report struct {
292296
ReqLats []float64
293297
ResLats []float64
294298
DelayLats []float64
299+
Offsets []float64
295300
StatusCodes []int
296301

297302
Total time.Duration

requester/requester.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const maxIdleConn = 500
3737
type result struct {
3838
err error
3939
statusCode int
40+
offset time.Duration
4041
duration time.Duration
4142
connDuration time.Duration // connection setup(DNS lookup + Dial up) duration
4243
dnsDuration time.Duration // dns lookup duration
@@ -183,6 +184,7 @@ func (b *Work) makeRequest(c *http.Client) {
183184
resDuration = t - resStart
184185
finish := t - s
185186
b.results <- &result{
187+
offset: s,
186188
statusCode: code,
187189
duration: finish,
188190
err: err,

0 commit comments

Comments
 (0)