-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver and native driver performance testing commands + refactoring
This closes #15, closes #21 Signed-off-by: lwsanty <[email protected]>
- Loading branch information
Showing
14 changed files
with
944 additions
and
151 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,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 | ||
} |
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,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) | ||
} |
Oops, something went wrong.