From 9a3401882bd7deacf53a41c5e057f39738206988 Mon Sep 17 00:00:00 2001 From: knqyf263 Date: Wed, 15 Jan 2020 11:05:21 +0200 Subject: [PATCH] feat(option): add --base to specify a base commit --- README.md | 8 ++++++++ config.go | 2 ++ main.go | 11 +++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b3026d..fd1033b 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ - [Run only those benchmarks matching a regular expression](#run-only-those-benchmarks-matching-a-regular-expression) - [Show only benchmarks with worse score](#show-only-benchmarks-with-worse-score) - [Specify a threshold](#specify-a-threshold) + - [Specify a base commit compared with HEAD](#specify-a-base-commit-compared-with-head) - [Usage](#usage) - [Q&A](#qa) - [A result of benchmarks is unstable](#a-result-of-benchmarks-is-unstable) @@ -217,6 +218,13 @@ The following option means the program fails if a benchmark score gets worse tha $ cob -threshold 0.5 ./... ``` +## Specify a base commit compared with HEAD +By default, `cob` uses `HEAD~1`. If you compare benchmarks with different commit, you can use `--base` option. + +``` +$ cob --base origin/master ./... +``` + # Usage ``` diff --git a/config.go b/config.go index 54d0b03..677b44f 100644 --- a/config.go +++ b/config.go @@ -6,6 +6,7 @@ type config struct { args []string onlyDegression bool threshold float64 + base string bench string benchmem bool benchtime string @@ -17,6 +18,7 @@ func newConfig(c *cli.Context) config { args: c.Args().Slice(), onlyDegression: c.Bool("only-degression"), threshold: c.Float64("threshold"), + base: c.String("base"), bench: c.String("bench"), benchmem: c.Bool("benchmem"), benchtime: c.String("benchtime"), diff --git a/main.go b/main.go index 47bb67a..dc978ae 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,8 @@ import ( "os/exec" "strings" + "gopkg.in/src-d/go-git.v4/plumbing" + "golang.org/x/xerrors" "github.com/olekukonko/tablewriter" @@ -40,6 +42,11 @@ func main() { Usage: "The program fails if the benchmark gets worse than the threshold", Value: 0.2, }, + &cli.StringFlag{ + Name: "base", + Usage: "Specify a base commit compared with HEAD", + Value: "HEAD~1", + }, &cli.StringFlag{ Name: "bench", Usage: "Run only those benchmarks matching a regular expression.", @@ -78,7 +85,7 @@ func run(c config) error { return xerrors.Errorf("unable to get the reference where HEAD is pointing to: %w", err) } - prev, err := r.ResolveRevision("HEAD~1") + prev, err := r.ResolveRevision(plumbing.Revision(c.base)) if err != nil { return xerrors.Errorf("unable to resolves revision to corresponding hash: %w", err) } @@ -104,7 +111,7 @@ func run(c config) error { args := prepareBenchArgs(c) - log.Printf("Run Benchmark: %s %s", prev, "HEAD{@1}") + log.Printf("Run Benchmark: %s %s", prev, c.base) prevSet, err := runBenchmark(args) if err != nil { return xerrors.Errorf("failed to run a benchmark: %w", err)