-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from jeffa5/csv-output
Add CSV output
- Loading branch information
Showing
11 changed files
with
205 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package measurement | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"time" | ||
) | ||
|
||
type csventry struct { | ||
// start time of the operation in us from unix epoch | ||
startUs int64 | ||
// latency of the operation in us | ||
latencyUs int64 | ||
} | ||
|
||
type csvs struct { | ||
opCsv map[string][]csventry | ||
} | ||
|
||
func InitCSV() *csvs { | ||
return &csvs{ | ||
opCsv: make(map[string][]csventry), | ||
} | ||
} | ||
|
||
func (c *csvs) Measure(op string, start time.Time, lan time.Duration) { | ||
c.opCsv[op] = append(c.opCsv[op], csventry{ | ||
startUs: start.UnixMicro(), | ||
latencyUs: lan.Microseconds(), | ||
}) | ||
} | ||
|
||
func (c *csvs) Output(w io.Writer) error { | ||
_, err := fmt.Fprintln(w, "operation,timestamp_us,latency_us") | ||
if err != nil { | ||
return err | ||
} | ||
for op, entries := range c.opCsv { | ||
for _, entry := range entries { | ||
_, err := fmt.Fprintf(w, "%s,%d,%d\n", op, entry.startUs, entry.latencyUs) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (c *csvs) Summary() { | ||
// do nothing as csvs don't keep a summary | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package measurement | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"sort" | ||
"time" | ||
|
||
"github.com/magiconair/properties" | ||
"github.com/pingcap/go-ycsb/pkg/prop" | ||
"github.com/pingcap/go-ycsb/pkg/util" | ||
) | ||
|
||
type histograms struct { | ||
p *properties.Properties | ||
|
||
histograms map[string]*histogram | ||
} | ||
|
||
func (h *histograms) Measure(op string, start time.Time, lan time.Duration) { | ||
opM, ok := h.histograms[op] | ||
if !ok { | ||
opM = newHistogram() | ||
h.histograms[op] = opM | ||
} | ||
|
||
opM.Measure(lan) | ||
} | ||
|
||
func (h *histograms) summary() map[string][]string { | ||
summaries := make(map[string][]string, len(h.histograms)) | ||
for op, opM := range h.histograms { | ||
summaries[op] = opM.Summary() | ||
} | ||
return summaries | ||
} | ||
|
||
func (h *histograms) Summary() { | ||
h.Output(os.Stdout) | ||
} | ||
|
||
func (h *histograms) Output(w io.Writer) error { | ||
summaries := h.summary() | ||
keys := make([]string, 0, len(summaries)) | ||
for k := range summaries { | ||
keys = append(keys, k) | ||
} | ||
sort.Strings(keys) | ||
|
||
lines := [][]string{} | ||
for _, op := range keys { | ||
line := []string{op} | ||
line = append(line, summaries[op]...) | ||
lines = append(lines, line) | ||
} | ||
|
||
outputStyle := h.p.GetString(prop.OutputStyle, util.OutputStylePlain) | ||
switch outputStyle { | ||
case util.OutputStylePlain: | ||
util.RenderString(w, "%-6s - %s\n", header, lines) | ||
case util.OutputStyleJson: | ||
util.RenderJson(w, header, lines) | ||
case util.OutputStyleTable: | ||
util.RenderTable(w, header, lines) | ||
default: | ||
panic("unsupported outputstyle: " + outputStyle) | ||
} | ||
return nil | ||
} | ||
|
||
func InitHistograms(p *properties.Properties) *histograms { | ||
return &histograms{ | ||
p: p, | ||
histograms: make(map[string]*histogram, 16), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.