Skip to content

Commit 1e7dab4

Browse files
lwsantykuba--
authored andcommitted
fix parseBenchmarkName (#26)
prefixes were not trimmed correctly Signed-off-by: lwsanty <lwsanty@gmail.com>
1 parent 8ef5b1c commit 1e7dab4

File tree

8 files changed

+33
-32
lines changed

8 files changed

+33
-32
lines changed

cmd/bblfsh-performance/driver/driver.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ import (
1212
"github.com/bblfsh/performance/storage"
1313
"github.com/bblfsh/performance/storage/file"
1414
"github.com/bblfsh/performance/storage/influxdb"
15-
prom "github.com/bblfsh/performance/storage/prom-pushgateway"
15+
"github.com/bblfsh/performance/storage/pushgateway"
1616

1717
"github.com/spf13/cobra"
1818
"gopkg.in/src-d/go-log.v1"
1919
)
2020

21-
const fileFilterPrefix = performance.FileFilterPrefix
22-
2321
// Cmd return configured driver-native command
2422
func Cmd() *cobra.Command {
2523
cmd := &cobra.Command{
@@ -107,8 +105,8 @@ export INFLUX_MEASUREMENT=benchmark
107105
flags.StringP("language", "l", "", "name of the language to be tested")
108106
flags.StringP("commit", "c", "", "commit id that's being tested and will be used as a tag in performance report")
109107
flags.StringSlice("exclude-suffixes", []string{".legacy", ".native", ".uast"}, "file suffixes to be excluded")
110-
flags.String("filter-prefix", fileFilterPrefix, "file prefix to be filtered")
111-
flags.StringP("storage", "s", prom.Kind, fmt.Sprintf("storage kind to store the results(%s, %s, %s)", prom.Kind, influxdb.Kind, file.Kind))
108+
flags.String("filter-prefix", performance.FileFilterPrefix, "file prefix to be filtered")
109+
flags.StringP("storage", "s", pushgateway.Kind, fmt.Sprintf("storage kind to store the results(%s, %s, %s)", pushgateway.Kind, influxdb.Kind, file.Kind))
112110

113111
return cmd
114112
}

cmd/bblfsh-performance/drivernative/drivernative.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import (
1313
"github.com/bblfsh/performance/storage"
1414
"github.com/bblfsh/performance/storage/file"
1515
"github.com/bblfsh/performance/storage/influxdb"
16-
prom_pushgateway "github.com/bblfsh/performance/storage/prom-pushgateway"
16+
"github.com/bblfsh/performance/storage/pushgateway"
1717

1818
"github.com/spf13/cobra"
1919
"gopkg.in/src-d/go-log.v1"
2020
)
2121

2222
const (
23-
fileFilterPrefix = performance.FileFilterPrefix
2423
containerTmp = "/tmp"
2524
containerFixtures = containerTmp + "/fixtures"
2625
results = "results.txt"
@@ -156,8 +155,8 @@ export INFLUX_MEASUREMENT=benchmark
156155
flags.StringP("language", "l", "", "name of the language to be tested")
157156
flags.StringP("commit", "c", "", "commit id that's being tested and will be used as a tag in performance report")
158157
flags.StringSlice("exclude-suffixes", []string{".legacy", ".native", ".uast"}, "file suffixes to be excluded")
159-
flags.String("filter-prefix", fileFilterPrefix, "file prefix to be filtered")
160-
flags.StringP("storage", "s", prom_pushgateway.Kind, fmt.Sprintf("storage kind to store the results(%s, %s, %s)", prom_pushgateway.Kind, influxdb.Kind, file.Kind))
158+
flags.String("filter-prefix", performance.FileFilterPrefix, "file prefix to be filtered")
159+
flags.StringP("storage", "s", pushgateway.Kind, fmt.Sprintf("storage kind to store the results(%s, %s, %s)", pushgateway.Kind, influxdb.Kind, file.Kind))
161160

162161
return cmd
163162
}

cmd/bblfsh-performance/endtoend/endtoend.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ import (
1212
"github.com/bblfsh/performance/storage"
1313
"github.com/bblfsh/performance/storage/file"
1414
"github.com/bblfsh/performance/storage/influxdb"
15-
prom_pushgateway "github.com/bblfsh/performance/storage/prom-pushgateway"
15+
"github.com/bblfsh/performance/storage/pushgateway"
1616

1717
"github.com/spf13/cobra"
1818
"gopkg.in/src-d/go-log.v1"
1919
)
2020

21-
const (
22-
fileFilterPrefix = performance.FileFilterPrefix
23-
24-
bblfshDefaultConfTag = "latest-drivers"
25-
)
21+
const bblfshDefaultConfTag = "latest-drivers"
2622

2723
// TODO(lwsanty): https://github.com/bblfsh/performance/issues/2
2824
// Cmd return configured end to end command
@@ -128,9 +124,9 @@ export INFLUX_MEASUREMENT=benchmark
128124
flags.StringP("commit", "c", "", "commit id that's being tested and will be used as a tag in performance report")
129125
flags.StringSlice("exclude-suffixes", []string{".legacy", ".native", ".uast"}, "file suffixes to be excluded")
130126
flags.StringP("docker-tag", "t", bblfshDefaultConfTag, "bblfshd docker image tag to be tested")
131-
flags.String("filter-prefix", fileFilterPrefix, "file prefix to be filtered")
132-
flags.StringP("storage", "s", prom_pushgateway.Kind, "storage kind to store the results"+
133-
fmt.Sprintf("(%s, %s, %s)", prom_pushgateway.Kind, influxdb.Kind, file.Kind))
127+
flags.String("filter-prefix", performance.FileFilterPrefix, "file prefix to be filtered")
128+
flags.StringP("storage", "s", pushgateway.Kind, "storage kind to store the results"+
129+
fmt.Sprintf("(%s, %s, %s)", pushgateway.Kind, influxdb.Kind, file.Kind))
134130
flags.Bool("custom-driver", false, "if this flag is set to true CLI pulls corresponding language driver repo's commit, builds docker image and installs it onto the bblfsh container")
135131

136132
return cmd

cmd/bblfsh-performance/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/bblfsh/performance/cmd/bblfsh-performance/parseandstore"
1111
_ "github.com/bblfsh/performance/storage/file"
1212
_ "github.com/bblfsh/performance/storage/influxdb"
13-
_ "github.com/bblfsh/performance/storage/prom-pushgateway"
13+
_ "github.com/bblfsh/performance/storage/pushgateway"
1414

1515
"github.com/spf13/cobra"
1616
)

cmd/bblfsh-performance/parseandstore/parseandstore.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/bblfsh/performance/storage"
99
"github.com/bblfsh/performance/storage/file"
1010
"github.com/bblfsh/performance/storage/influxdb"
11-
"github.com/bblfsh/performance/storage/prom-pushgateway"
1211

12+
"github.com/bblfsh/performance/storage/pushgateway"
1313
"github.com/spf13/cobra"
1414
"golang.org/x/tools/benchmark/parse"
1515
)
@@ -39,6 +39,7 @@ bblfsh-performance parse-and-store --language=go --commit=3d9682b --storage="inf
3939
RunE: performance.RunESilenced(func(cmd *cobra.Command, args []string) error {
4040
language, _ := cmd.Flags().GetString("language")
4141
commit, _ := cmd.Flags().GetString("commit")
42+
filterPrefix, _ := cmd.Flags().GetString("filter-prefix")
4243
stor, _ := cmd.Flags().GetString("storage")
4344

4445
c, err := storage.NewClient(stor)
@@ -49,7 +50,7 @@ bblfsh-performance parse-and-store --language=go --commit=3d9682b --storage="inf
4950

5051
// TODO(lwsanty): parallelize
5152
for _, p := range args {
52-
benchmarks, err := getBenchmarks(p)
53+
benchmarks, err := getBenchmarks(p, filterPrefix)
5354
if err != nil {
5455
return err
5556
}
@@ -70,13 +71,14 @@ bblfsh-performance parse-and-store --language=go --commit=3d9682b --storage="inf
7071
flags := cmd.Flags()
7172
flags.StringP("language", "l", "", "name of the language to be tested")
7273
flags.StringP("commit", "c", "", "commit id that's being tested and will be used as a tag in performance report")
73-
flags.StringP("storage", "s", prom_pushgateway.Kind, "storage kind to store the results"+
74-
fmt.Sprintf("(%s, %s, %s)", prom_pushgateway.Kind, influxdb.Kind, file.Kind))
74+
flags.String("filter-prefix", performance.FileFilterPrefix, "file prefix to be filtered")
75+
flags.StringP("storage", "s", pushgateway.Kind, "storage kind to store the results"+
76+
fmt.Sprintf("(%s, %s, %s)", pushgateway.Kind, influxdb.Kind, file.Kind))
7577

7678
return cmd
7779
}
7880

79-
func getBenchmarks(path string) ([]performance.Benchmark, error) {
81+
func getBenchmarks(path string, trimPrefixes ...string) ([]performance.Benchmark, error) {
8082
f, err := os.Open(path)
8183
if err != nil {
8284
return nil, err
@@ -91,7 +93,7 @@ func getBenchmarks(path string) ([]performance.Benchmark, error) {
9193
for _, s := range set {
9294
var benchmarkSet []performance.Benchmark
9395
for _, b := range s {
94-
benchmarkSet = append(benchmarkSet, performance.NewBenchmark(b))
96+
benchmarkSet = append(benchmarkSet, performance.NewBenchmark(b, trimPrefixes...))
9597
}
9698
result = append(result, benchmarkSet...)
9799
}

cmd/native-driver-performance/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
// TODO: fixtures filters and so on
2424
fixtures := flag.String("fixtures", "", "path to fixtures directory")
2525
resultsFile := flag.String("results", "", "path to file to store benchmark results")
26-
filterPrefix := flag.String("filter-prefix", "", "file prefix to be filtered")
26+
filterPrefix := flag.String("filter-prefix", performance.FileFilterPrefix, "file prefix to be filtered")
2727

2828
flag.Parse()
2929

common.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,24 @@ func BenchmarkResultToBenchmark(name string, b *testing.BenchmarkResult, trimPre
6262
}
6363

6464
// parseBenchmarkName removes the path and suffixes from benchmark info
65-
// Example: BenchmarkGoDriver/transform/accumulator_factory-4 -> accumulator_factory
65+
// Example1: BenchmarkGoDriver/transform/accumulator_factory-4 -> accumulator_factory
66+
// Example2: BenchmarkGoDriver/transform/bench_accumulator_factory-4 -> accumulator_factory, where "bench_" is a trimPrefixes
6667
func parseBenchmarkName(name string, trimPrefixes ...string) string {
67-
for _, tp := range trimPrefixes {
68-
name = strings.TrimPrefix(name, tp)
68+
trim := func(name string) (res string) {
69+
for _, tp := range trimPrefixes {
70+
if strings.HasPrefix(name, tp) {
71+
return strings.TrimPrefix(name, tp)
72+
}
73+
}
74+
return name
6975
}
7076
if i := strings.LastIndex(name, "/"); i >= 0 {
7177
name = name[i+1:]
7278
}
7379
if i := strings.IndexAny(name, "-."); i >= 0 {
74-
return name[:i]
80+
return trim(name[:i])
7581
}
76-
return name
82+
return trim(name)
7783
}
7884

7985
// TODO(lwsanty): https://github.com/spf13/cobra/issues/340
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package prom_pushgateway
1+
package pushgateway
22

33
import (
44
"time"

0 commit comments

Comments
 (0)