in systemtest/benchtest/main.go [166:254]
func Run(allBenchmarks ...BenchmarkFunc) error {
// Set flags in package testing.
testing.Init()
if err := flag.Set("test.benchtime", benchConfig.Benchtime.String()); err != nil {
return err
}
// Sets the http.DefaultClient.Transport.TLSClientConfig.InsecureSkipVerify
// to match the "-secure" flag value.
verifyTLS := loadgencfg.Config.Secure
http.DefaultClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: !verifyTLS},
}
os.Setenv("ELASTIC_APM_VERIFY_SERVER_CERT", fmt.Sprint(verifyTLS))
var profiles profiles
if err := profiles.init(); err != nil {
return err
}
defer func() {
if err := profiles.writeProfiles(); err != nil {
log.Printf("failed to write profiles: %s", err)
}
}()
matchRE := benchConfig.RunRE
benchmarks := make([]benchmark, 0, len(allBenchmarks))
for _, benchmarkFunc := range allBenchmarks {
name, err := benchmarkFuncName(benchmarkFunc)
if err != nil {
return err
}
if matchRE == nil || matchRE.MatchString(name) {
benchmarks = append(benchmarks, benchmark{
name: name,
f: benchmarkFunc,
})
}
}
sort.Slice(benchmarks, func(i, j int) bool {
return benchmarks[i].name < benchmarks[j].name
})
var maxLen int
agentsList := benchConfig.AgentsList
for _, agents := range agentsList {
for _, benchmark := range benchmarks {
if n := len(fullBenchmarkName(benchmark.name, agents)); n > maxLen {
maxLen = n
}
}
}
// Warm up the APM Server with the specified `-agents`. Only the first
// value in the list will be used.
if len(agentsList) > 0 && benchConfig.WarmupTime.Seconds() > 0 {
agents := agentsList[0]
serverURL := loadgencfg.Config.ServerURL.String()
secretToken := loadgencfg.Config.SecretToken
if err := warmup(agents, benchConfig.WarmupTime, serverURL, secretToken); err != nil {
return fmt.Errorf("warm-up failed with %d agents: %v", agents, err)
}
}
for _, agents := range agentsList {
runtime.GOMAXPROCS(int(agents))
for _, benchmark := range benchmarks {
name := fullBenchmarkName(benchmark.name, agents)
for i := 0; i < int(benchConfig.Count); i++ {
profileChan := profiles.record(name)
result, failed, skipped, err := runBenchmark(benchmark.f)
if err != nil {
return err
}
if skipped {
continue
}
if failed {
fmt.Fprintf(os.Stderr, "--- FAIL: %s\n", name)
return fmt.Errorf("benchmark %q failed", name)
} else {
fmt.Fprintf(os.Stderr, "%-*s\t%s\t%s\n", maxLen, name, result, result.MemString())
}
if err := <-profileChan; err != nil {
return err
}
}
}
}
return nil
}