Example #1
0
// Run runs go test benchmarks matching regex in the current directory and writes
// benchmark data to a PSQL database by calling WriteSet. It returns any error
// encountered.
func (benchdb *BenchPSQL) Run() error {
	// Exec a subprocess for go test bench and write
	// to both stdout and a byte buffer.
	cmd := exec.Command("go", "test", "-bench", benchdb.Config.Regex,
		"-test.run", "XXX", "-benchmem")
	var out bytes.Buffer
	cmd.Stdout = io.MultiWriter(os.Stdout, &out)
	cmd.Stderr = io.Writer(os.Stderr)
	err := cmd.Run()
	if err != nil {
		return fmt.Errorf("command failed: %v", err)
	}

	benchSet, err := parse.ParseSet(&out)
	if err != nil {
		return fmt.Errorf("failed to parse benchmark data: %v", err)
	}

	// Writes parse set to sql database.
	_, err = benchdb.WriteSet(benchSet)
	if err != nil {
		return fmt.Errorf("failed to write benchSet to db: %v", err)
	}
	return nil
}
Example #2
0
// ParseBenchmarkOutput parses raw output from 'go test -test.bench' command.
func ParseBenchmarkOutput(out string) (*BenchmarkSet, error) {
	buf := bytes.NewBufferString(out)
	set, err := parse.ParseSet(buf)
	if err != nil {
		return nil, err
	}
	return &BenchmarkSet{
		Set: set,
	}, nil
}
Example #3
0
func parseFile(path string) parse.Set {
	f, err := os.Open(path)
	if err != nil {
		fatal(err)
	}
	defer f.Close()
	bb, err := parse.ParseSet(f)
	if err != nil {
		fatal(err)
	}
	if *best {
		selectBest(bb)
	}
	return bb
}
Example #4
0
func runTest(name string, maxprocs int) (parse.Set, error) {
	log.Printf("Start testing of %s", name)
	log.Print("Create cmd.............")
	cmd := exec.Command("go", "test", "-bench=.", "-benchmem", "-run=NONE", name+"/...")
	log.Println("Ok")

	log.Print("Create StdoutPipe......")
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		log.Println("Get pipe failed:", err)
		return nil, err
	}
	log.Println("Ok")

	log.Print("Start cmd..............")
	if err := cmd.Start(); err != nil {
		log.Println("Execution of ", name, " failed:", err)
		return nil, err
	}

	log.Println("Ok")

	log.Print("Start ParseSet........")
	res, err := parse.ParseSet(stdout)

	if err != nil {
		log.Println("Parsing of output failed ", name, " failed:", err)
		return nil, err
	}
	log.Println("Ok")

	log.Print("Wait for exit........")
	if err := cmd.Wait(); err != nil {
		log.Print("Failed:", err)
		return nil, err
	}

	log.Println("Ok")

	return res, nil

}
Example #5
0
func CreateHandler(w http.ResponseWriter, r *http.Request) {
	f, _, err := r.FormFile("benchmark")

	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	set, err := parse.ParseSet(f)

	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	fmt.Println(set)

	w.WriteHeader(http.StatusOK)
	w.Write([]byte(`OK`))
}
Example #6
0
func (benchdb *BenchKVStore) Run() error {
	cmd := exec.Command("go", "test", "-bench", benchdb.Config.Regex,
		"-test.run", "XXX", "-benchmem")
	var out bytes.Buffer
	cmd.Stdout = io.MultiWriter(os.Stdout, &out)
	cmd.Stderr = io.Writer(os.Stderr)
	err := cmd.Run()
	if err != nil {
		return fmt.Errorf("Failed to run command, err: %v\n", err)
	}

	benchSet, err := parse.ParseSet(&out)
	if err != nil {
		return fmt.Errorf("Failed to parse benchmark data, err: %\n", err)
	}

	_, err = benchdb.WriteSet(benchSet)
	if err != nil {
		fmt.Errorf("Failed to write benchSet to CB, err: %v\n", err)
	}
	return nil
}