MCPcopy
hub / github.com/nats-io/nats.go / CSV

Method CSV

bench/bench.go:120–143  ·  view source on GitHub ↗

CSV generates a csv report of all the samples collected

()

Source from the content-addressed store, hash-verified

118
119// CSV generates a csv report of all the samples collected
120func (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
146func NewSample(jobCount int, msgSize int, start, end time.Time, nc *nats.Conn) *Sample {

Callers 2

mainFunction · 0.80
TestCsvFunction · 0.80

Calls 8

FatalfMethod · 0.80
RateMethod · 0.80
ThroughputMethod · 0.80
SecondsMethod · 0.80
DurationMethod · 0.80
WriteMethod · 0.45
FlushMethod · 0.45
StringMethod · 0.45

Tested by 1

TestCsvFunction · 0.64