Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
97 lines (85 sloc) 2.13 KB
package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/spf13/pflag"
"go.bobheadxi.dev/gobenchdata/bench"
)
// Version is the version of gobenchdata
var Version string
var (
jsonOut = pflag.String("json", "", "output as json to file")
appendOut = pflag.BoolP("append", "a", false, "append to output file")
flat = pflag.BoolP("flat", "f", false, "flatten JSON output into one run per line")
noSort = pflag.Bool("no-sort", false, "disable sorting")
prune = pflag.Int("prune", 0, "number of runs to keep (default: keep all)")
version = pflag.StringP("version", "v", "", "version to tag in your benchmark output")
tags = pflag.StringArrayP("tag", "t", nil, "array of tags to include in result")
)
func main() {
pflag.Parse()
if len(pflag.Args()) > 0 {
switch cmd := pflag.Args()[0]; cmd {
case "version":
if Version == "" {
println("gobenchdata version unknown")
} else {
println("gobenchdata " + Version)
}
case "help":
showHelp()
case "merge":
args := pflag.Args()[1:]
if len(args) < 1 {
panic("no merge targets provided")
}
merge(args...)
default:
showHelp()
os.Exit(1)
}
return
}
fi, err := os.Stdin.Stat()
if err != nil {
panic(err)
} else if fi.Mode()&os.ModeNamedPipe == 0 {
showHelp()
panic("gobenchdata should be used with a pipe")
}
parser := bench.NewParser(bufio.NewReader(os.Stdin))
suites, err := parser.Read()
if err != nil {
panic(err)
}
fmt.Printf("detected %d benchmark suites\n", len(suites))
// set up results
results := []bench.Run{{
Version: *version,
Date: time.Now().Unix(),
Tags: *tags,
Suites: suites,
}}
if *appendOut {
if *jsonOut == "" {
panic("file output needs to be set (try '--json')")
}
b, err := ioutil.ReadFile(*jsonOut)
if err != nil && !os.IsNotExist(err) {
panic(err)
} else if !os.IsNotExist(err) {
var runs []bench.Run
if err := json.Unmarshal(b, &runs); err != nil {
panic(err)
}
results = append(results, runs...)
} else {
fmt.Printf("could not find specified output file '%s' - creating a new file\n", *jsonOut)
}
}
output(results)
}
You can’t perform that action at this time.