Skip to content

Commit

Permalink
driver and native driver performance testing commands + refactoring
Browse files Browse the repository at this point in the history
This closes #15, closes #21

Signed-off-by: lwsanty <lwsanty@gmail.com>
  • Loading branch information
lwsanty committed Sep 17, 2019
1 parent c610584 commit 62a865f
Show file tree
Hide file tree
Showing 14 changed files with 944 additions and 151 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ deploy:
tags: true

after_deploy:
- cd cmd/native-driver-performance/ ; CGO_ENABLED=0 go build -o ../../build/native-driver-performance ; cd ../..
- DOCKER_PUSH_MASTER=1 make docker-push-latest-release
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ FROM srcd/dind-golang:docker-18.09.7-go-1.12.7
RUN apk update && apk upgrade && \
apk add --no-cache bash git build-base

RUN mkdir -p /root/utils

COPY build/bin/bblfsh-performance /root/
COPY build/bin/native-driver-performance /root/utils/
WORKDIR /root

ENTRYPOINT ["./bblfsh-performance"]
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,99 @@ Either locally or in CI:
3) save output test benchmark output to the file
4) run `bblfsh-performance parse-and-store` and pass the filepath(s) as an argument
### driver-native
```bash
./bblfsh-performance driver-native --help
run language driver container and perform benchmark tests over the native driver, store results into a given storage
Usage:
bblfsh-performance driver-native [--language=<language>] [--commit=<commit-id>] [--storage=<storage>] [--filter-prefix=<filter-prefix>] [--native=<path-to-native>] <directory> [flags]
Aliases:
driver-native, dn, native
Examples:
WARNING! Requires native-driver-performance binary to be build
WARNING! To access storage corresponding environment variables should be set.
Full examples of usage scripts are following:
# for prometheus pushgateway
export PROM_ADDRESS="localhost:9091"
export PROM_JOB=pushgateway
./bblfsh-performance driver-native \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
--native /home/lwsanty/goproj/lwsanty/performance/cmd/native-driver-performance/native-driver-performance \
/var/testdata/fixtures
# for influx db
export INFLUX_ADDRESS="http://localhost:8086"
export INFLUX_USERNAME=""
export INFLUX_PASSWORD=""
export INFLUX_DB=mydb
export INFLUX_MEASUREMENT=benchmark
./bblfsh-performance driver-native \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
--native /home/lwsanty/goproj/lwsanty/performance/cmd/native-driver-performance/native-driver-performance \
--storage=influxdb \
/var/testdata/fixtures
Flags:
-c, --commit string commit id that's being tested and will be used as a tag in performance report
--exclude-suffixes strings file suffixes to be excluded (default [.legacy,.native,.uast])
--filter-prefix string file prefix to be filtered (default "bench_")
-h, --help help for driver-native
-l, --language string name of the language to be tested
-n, --native string path to native driver performance util (default "/root/utils/native-driver-test")
-s, --storage string storage kind to store the results(prom, influxdb, file) (default "prom")
```

### driver
```bash
./bblfsh-performance driver --help
run language driver container and perform benchmark tests over the driver, store results into a given storage

Usage:
bblfsh-performance driver [--language=<language>] [--commit=<commit-id>] [--storage=<storage>] [--filter-prefix=<filter-prefix>] <directory> [flags]

Aliases:
driver, d

Examples:
WARNING! To access storage corresponding environment variables should be set.
Full examples of usage scripts are following:

# for prometheus pushgateway
export PROM_ADDRESS="localhost:9091"
export PROM_JOB=pushgateway
./bblfsh-performance driver \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
/var/testdata/fixtures

# for influx db
export INFLUX_ADDRESS="http://localhost:8086"
export INFLUX_USERNAME=""
export INFLUX_PASSWORD=""
export INFLUX_DB=mydb
export INFLUX_MEASUREMENT=benchmark
./bblfsh-performance driver \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
--storage=influxdb \
/var/testdata/fixtures


Flags:
-c, --commit string commit id that's being tested and will be used as a tag in performance report
--exclude-suffixes strings file suffixes to be excluded (default [.legacy,.native,.uast])
--filter-prefix string file prefix to be filtered (default "bench_")
-h, --help help for driver
-l, --language string name of the language to be tested
-s, --storage string storage kind to store the results(prom, influxdb, file) (default "prom")
```
### end-2-end
```bash
Expand Down
114 changes: 114 additions & 0 deletions cmd/bblfsh-performance/driver/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package driver

import (
"context"
"fmt"
"os"
"os/signal"

"github.com/bblfsh/performance"
"github.com/bblfsh/performance/docker"
helper "github.com/bblfsh/performance/grpc-helper"
"github.com/bblfsh/performance/storage"
"github.com/bblfsh/performance/storage/file"
"github.com/bblfsh/performance/storage/influxdb"
prom "github.com/bblfsh/performance/storage/prom-pushgateway"

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

const fileFilterPrefix = performance.FileFilterPrefix

// Cmd return configured driver-native command
func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "driver [--language=<language>] [--commit=<commit-id>] [--storage=<storage>] [--filter-prefix=<filter-prefix>] <directory>",
Aliases: []string{"d"},
Args: cobra.MinimumNArgs(1),
Short: "run language driver container and perform benchmark tests over the driver, store results into a given storage",
Example: `WARNING! To access storage corresponding environment variables should be set.
Full examples of usage scripts are following:
# for prometheus pushgateway
export PROM_ADDRESS="localhost:9091"
export PROM_JOB=pushgateway
./bblfsh-performance driver \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
/var/testdata/fixtures
# for influx db
export INFLUX_ADDRESS="http://localhost:8086"
export INFLUX_USERNAME=""
export INFLUX_PASSWORD=""
export INFLUX_DB=mydb
export INFLUX_MEASUREMENT=benchmark
./bblfsh-performance driver \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
--storage=influxdb \
/var/testdata/fixtures
`,
RunE: performance.RunESilenced(func(cmd *cobra.Command, args []string) error {
language, _ := cmd.Flags().GetString("language")
commit, _ := cmd.Flags().GetString("commit")
excludeSubstrings, _ := cmd.Flags().GetStringSlice("exclude-suffixes")
stor, _ := cmd.Flags().GetString("storage")
filterPrefix, _ := cmd.Flags().GetString("filter-prefix")

if _, err := storage.ValidateKind(stor); err != nil {
return err
}

log.Debugf("download and build driver")
image, err := docker.DownloadAndBuildDriver(language, commit)
if err != nil {
return err
}

log.Debugf("run driver container")
driver, err := docker.RunDriver(image)
if err != nil {
return err
}
defer driver.Close()

// prepare context
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
cancel()
}()
go func() {
select {
case <-c:
cancel()
case <-ctx.Done():
}
}()

return helper.BenchmarkGRPCAndStore(ctx, helper.BenchmarkGRPCMeta{
Address: driver.Address,
Commit: commit,
ExcludeSubstrings: excludeSubstrings,
Dirs: args,
FilterPrefix: filterPrefix,
Language: language,
Level: performance.DriverLevel,
Storage: stor,
})
}),
}

flags := cmd.Flags()
flags.StringP("language", "l", "", "name of the language to be tested")
flags.StringP("commit", "c", "", "commit id that's being tested and will be used as a tag in performance report")
flags.StringSlice("exclude-suffixes", []string{".legacy", ".native", ".uast"}, "file suffixes to be excluded")
flags.String("filter-prefix", fileFilterPrefix, "file prefix to be filtered")
flags.StringP("storage", "s", prom.Kind, fmt.Sprintf("storage kind to store the results(%s, %s, %s)", prom.Kind, influxdb.Kind, file.Kind))

return cmd
}
167 changes: 167 additions & 0 deletions cmd/bblfsh-performance/drivernative/drivernative.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package drivernative

import (
"context"
"encoding/json"
"fmt"
"os"
"os/signal"
"path/filepath"

"github.com/bblfsh/performance"
"github.com/bblfsh/performance/docker"
"github.com/bblfsh/performance/storage"
"github.com/bblfsh/performance/storage/file"
"github.com/bblfsh/performance/storage/influxdb"
prom_pushgateway "github.com/bblfsh/performance/storage/prom-pushgateway"

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

const (
fileFilterPrefix = performance.FileFilterPrefix
containerTmp = "/tmp"
containerFixtures = containerTmp + "/fixtures"
results = "results.txt"
)

// Cmd return configured driver-native command
func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "driver-native [--language=<language>] [--commit=<commit-id>] [--storage=<storage>] [--filter-prefix=<filter-prefix>] [--native=<path-to-native>] <directory>",
Aliases: []string{"dn", "native"},
Args: cobra.MinimumNArgs(1),
Short: "run language driver container and perform benchmark tests over the native driver, store results into a given storage",
Example: `WARNING! Requires native-driver-performance binary to be build
WARNING! To access storage corresponding environment variables should be set.
Full examples of usage scripts are following:
# for prometheus pushgateway
export PROM_ADDRESS="localhost:9091"
export PROM_JOB=pushgateway
./bblfsh-performance driver-native \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
--native /home/lwsanty/goproj/lwsanty/performance/cmd/native-driver-performance/native-driver-performance \
/var/testdata/fixtures
# for influx db
export INFLUX_ADDRESS="http://localhost:8086"
export INFLUX_USERNAME=""
export INFLUX_PASSWORD=""
export INFLUX_DB=mydb
export INFLUX_MEASUREMENT=benchmark
./bblfsh-performance driver-native \
--language go \
--commit 096361d09049c27e829fd5a6658f1914fd3b62ac \
--native /home/lwsanty/goproj/lwsanty/performance/cmd/native-driver-performance/native-driver-performance \
--storage=influxdb \
/var/testdata/fixtures
`,
RunE: performance.RunESilenced(func(cmd *cobra.Command, args []string) error {
language, _ := cmd.Flags().GetString("language")
commit, _ := cmd.Flags().GetString("commit")
stor, _ := cmd.Flags().GetString("storage")
filterPrefix, _ := cmd.Flags().GetString("filter-prefix")
native, _ := cmd.Flags().GetString("native")

fixtures := args[0]
execDst := getSubTmp(filepath.Base(native))
resultsPath := getSubTmp(results)

log.Debugf("validating storage")
if _, err := storage.ValidateKind(stor); err != nil {
return err
}

log.Debugf("download and build driver")
image, err := docker.DownloadAndBuildDriver(language, commit)
if err != nil {
return err
}

log.Debugf("run driver container")
driver, err := docker.RunDriver(image, fixtures+":"+containerFixtures)
if err != nil {
return err
}
defer driver.Close()

// prepare context
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
cancel()
}()
go func() {
select {
case <-c:
cancel()
case <-ctx.Done():
}
}()

log.Debugf("copying file %v to container's dst: %v", native, execDst)
if err := driver.Upload(ctx, native, execDst); err != nil {
return err
}

log.Debugf("executing command on driver")
//if err := driver.Exec(ctx, "sh", "-c", "dfgdfg"); err != nil {
if err := driver.Exec(ctx,
[]string{"LOG_LEVEL=debug"},
execDst,
"--filter-prefix="+filterPrefix,
"--fixtures="+containerFixtures,
"--results="+resultsPath,
); err != nil {
return err
}

log.Debugf("getting results")
data, err := driver.GetResults(ctx, resultsPath)
if err != nil {
return err
}

var benchmarks []performance.Benchmark
if err := json.Unmarshal(data, &benchmarks); err != nil {
return err
}

// store data
storageClient, err := storage.NewClient(stor)
if err != nil {
return err
}
defer storageClient.Close()

if err := storageClient.Dump(map[string]string{
"language": language,
"commit": commit,
"level": performance.DriverNativeLevel,
}, benchmarks...); err != nil {
return err
}

return nil
}),
}

flags := cmd.Flags()
flags.StringP("native", "n", "/root/utils/native-driver-test", "path to native driver performance util")
flags.StringP("language", "l", "", "name of the language to be tested")
flags.StringP("commit", "c", "", "commit id that's being tested and will be used as a tag in performance report")
flags.StringSlice("exclude-suffixes", []string{".legacy", ".native", ".uast"}, "file suffixes to be excluded")
flags.String("filter-prefix", fileFilterPrefix, "file prefix to be filtered")
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))

return cmd
}

func getSubTmp(name string) string {
return filepath.Join(containerTmp, name)
}
Loading

0 comments on commit 62a865f

Please sign in to comment.