CSV generates a csv report of all the samples collected
()
| 118 | |
| 119 | // CSV generates a csv report of all the samples collected |
| 120 | func (bm *Benchmark) CSV() string { |
| 121 | var buffer bytes.Buffer |
| 122 | writer := csv.NewWriter(&buffer) |
| 123 | headers := []string{"#RunID", "ClientID", "MsgCount", "MsgBytes", "MsgsPerSec", "BytesPerSec", "DurationSecs"} |
| 124 | if err := writer.Write(headers); err != nil { |
| 125 | log.Fatalf("Error while serializing headers %q: %v", headers, err) |
| 126 | } |
| 127 | groups := []*SampleGroup{bm.Subs, bm.Pubs} |
| 128 | pre := "S" |
| 129 | for i, g := range groups { |
| 130 | if i == 1 { |
| 131 | pre = "P" |
| 132 | } |
| 133 | for j, c := range g.Samples { |
| 134 | r := []string{bm.RunID, fmt.Sprintf("%s%d", pre, j), fmt.Sprintf("%d", c.MsgCnt), fmt.Sprintf("%d", c.MsgBytes), fmt.Sprintf("%d", c.Rate()), fmt.Sprintf("%f", c.Throughput()), fmt.Sprintf("%f", c.Duration().Seconds())} |
| 135 | if err := writer.Write(r); err != nil { |
| 136 | log.Fatalf("Error while serializing %v: %v", c, err) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | writer.Flush() |
| 142 | return buffer.String() |
| 143 | } |
| 144 | |
| 145 | // NewSample creates a new Sample initialized to the provided values. The nats.Conn information captured |
| 146 | func NewSample(jobCount int, msgSize int, start, end time.Time, nc *nats.Conn) *Sample { |