...
1
2
3
4
5
6
7 package benchmark
8
9 import (
10 "context"
11 "encoding/json"
12 "flag"
13 "fmt"
14 "io/ioutil"
15 "os"
16 )
17
18 func DriverBenchmarkMain() int {
19 var hasErrors bool
20 var outputFileName string
21 flag.StringVar(&outputFileName, "output", "perf.json", "path to write the 'perf.json' file")
22 flag.Parse()
23
24 ctx := context.Background()
25 output := []interface{}{}
26 for _, res := range runDriverCases(ctx) {
27 if res.HasErrors() {
28 hasErrors = true
29 }
30
31 evg, err := res.EvergreenPerfFormat()
32 if err != nil {
33 hasErrors = true
34 continue
35 }
36
37 output = append(output, evg...)
38 }
39
40 evgOutput, err := json.MarshalIndent(output, "", " ")
41 if err != nil {
42 return 1
43 }
44 evgOutput = append(evgOutput, []byte("\n")...)
45
46 if outputFileName == "" {
47 fmt.Println(string(evgOutput))
48 } else {
49
50
51
52 err := ioutil.WriteFile(outputFileName, evgOutput, 0644)
53 if err != nil {
54 fmt.Fprintf(os.Stderr, "problem writing file '%s': %s", outputFileName, err.Error())
55 return 1
56 }
57 }
58
59 if hasErrors {
60 return 1
61 }
62
63 return 0
64 }
65
66 func runDriverCases(ctx context.Context) []*BenchResult {
67 cases := getAllCases()
68
69 results := []*BenchResult{}
70 for _, bc := range cases {
71 results = append(results, bc.Run(ctx))
72 }
73
74 return results
75 }
76
View as plain text