simplify finalization of the report

This commit is contained in:
Jaana Burcu Dogan
2016-11-06 13:17:28 -08:00
parent 74c4ca31d8
commit 53cffab544
2 changed files with 32 additions and 36 deletions
+30 -35
View File
@@ -67,45 +67,40 @@ func newReport(size int, results chan *result, output string, total time.Duratio
}
func (r *report) finalize() {
for {
select {
case res := <-r.results:
if res.err != nil {
r.errorDist[res.err.Error()]++
} else {
r.lats = append(r.lats, res.duration.Seconds())
r.avgTotal += res.duration.Seconds()
if r.trace {
r.avgConn += res.connDuration.Seconds()
r.avgDelay += res.delayDuration.Seconds()
r.avgDns += res.dnsDuration.Seconds()
r.avgReq += res.reqDuration.Seconds()
r.avgRes += res.resDuration.Seconds()
r.connLats = append(r.connLats, res.connDuration.Seconds())
r.dnsLats = append(r.dnsLats, res.dnsDuration.Seconds())
r.reqLats = append(r.reqLats, res.reqDuration.Seconds())
r.delayLats = append(r.delayLats, res.delayDuration.Seconds())
r.resLats = append(r.resLats, res.resDuration.Seconds())
}
r.statusCodeDist[res.statusCode]++
if res.contentLength > 0 {
r.sizeTotal += res.contentLength
}
}
default:
r.rps = float64(len(r.lats)) / r.total.Seconds()
r.average = r.avgTotal / float64(len(r.lats))
for res := range r.results {
if res.err != nil {
r.errorDist[res.err.Error()]++
} else {
r.lats = append(r.lats, res.duration.Seconds())
r.avgTotal += res.duration.Seconds()
if r.trace {
r.avgConn = r.avgConn / float64(len(r.lats))
r.avgDelay = r.avgDelay / float64(len(r.lats))
r.avgDns = r.avgDns / float64(len(r.lats))
r.avgReq = r.avgReq / float64(len(r.lats))
r.avgRes = r.avgRes / float64(len(r.lats))
r.avgConn += res.connDuration.Seconds()
r.avgDelay += res.delayDuration.Seconds()
r.avgDns += res.dnsDuration.Seconds()
r.avgReq += res.reqDuration.Seconds()
r.avgRes += res.resDuration.Seconds()
r.connLats = append(r.connLats, res.connDuration.Seconds())
r.dnsLats = append(r.dnsLats, res.dnsDuration.Seconds())
r.reqLats = append(r.reqLats, res.reqDuration.Seconds())
r.delayLats = append(r.delayLats, res.delayDuration.Seconds())
r.resLats = append(r.resLats, res.resDuration.Seconds())
}
r.statusCodeDist[res.statusCode]++
if res.contentLength > 0 {
r.sizeTotal += res.contentLength
}
r.print()
return
}
}
r.rps = float64(len(r.lats)) / r.total.Seconds()
r.average = r.avgTotal / float64(len(r.lats))
if r.trace {
r.avgConn = r.avgConn / float64(len(r.lats))
r.avgDelay = r.avgDelay / float64(len(r.lats))
r.avgDns = r.avgDns / float64(len(r.lats))
r.avgReq = r.avgReq / float64(len(r.lats))
r.avgRes = r.avgRes / float64(len(r.lats))
}
r.print()
}
func (r *report) printCSV() {
+2 -1
View File
@@ -130,6 +130,7 @@ func (b *Work) Run() {
go func() {
<-c
stopCh <- struct{}{}
close(b.results)
newReport(b.N, b.results, b.Output, time.Now().Sub(start), b.EnableTrace).finalize()
os.Exit(1)
}()
@@ -140,8 +141,8 @@ func (b *Work) Run() {
fmt.Println("All requests done.")
}
newReport(b.N, b.results, b.Output, time.Now().Sub(start), b.EnableTrace).finalize()
close(b.results)
newReport(b.N, b.results, b.Output, time.Now().Sub(start), b.EnableTrace).finalize()
}
func (b *Work) makeRequest(c *http.Client) {