-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
92 lines (73 loc) · 2.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"errors"
"flag"
"os"
"github.com/jaimelopez/chihuahua/executor"
"github.com/jaimelopez/chihuahua/logger"
"github.com/jaimelopez/chihuahua/parameters"
"github.com/jaimelopez/chihuahua/printer"
"github.com/jaimelopez/chihuahua/storage"
)
const appHeader = `
___ _ _ _ _
/ __\ |__ (_) |__ _ _ __ _| |__ _ _ __ _
/ / | '_ \| | '_ \| | | |/ _. | '_ \| | | |/ _. |
/ /___| | | | | | | | |_| | (_| | | | | |_| | (_| |
\____/|_| |_|_|_| |_|\____|\____|_| |_|\____|\____|
`
const (
successExitCode int = 0
badUsageExitCode int = 0
performanceErrorExitCode int = 1
)
func main() {
params := parameters.NewFromFlags()
if *params.Group == "" || *params.Driver == "" || *params.Destination == "" {
usage()
}
strg, err := storage.New(*params.Group, *params.Driver, *params.Destination)
if err != nil {
logger.Error("setting up storage", err)
}
latestResult, err := strg.GetLatest()
if err != nil {
logger.Error("retrieving latest benchmarks results", err)
}
var currentResult *executor.Result
if *params.FromFile == "" {
currentResult, err = executor.Run(*params.Duration, *params.Debug)
} else {
currentResult, err = executor.FromFile(*params.FromFile)
}
if err != nil {
logger.Error("executing benchmarks", err)
} else if len(*currentResult) == 0 {
logger.Error("executing benchmarks", errors.New("no tests found"))
}
succeed, comparision := executor.Compare(latestResult, currentResult, uint(*params.Threshold))
if *params.Results {
printer.Print(comparision)
}
if *params.Save && (succeed || *params.Force) {
err = strg.Persist(currentResult)
if err != nil {
logger.Error("saving results:", err)
}
}
if succeed {
exit("Good perfomance dude!", successExitCode)
} else if *params.Force {
exit("Bad performance but forcing...", successExitCode)
}
exit("Bad performance!", performanceErrorExitCode)
}
func usage() {
logger.Info(appHeader)
flag.PrintDefaults()
exit("", badUsageExitCode)
}
func exit(msg string, status int) {
logger.Info(msg)
os.Exit(status)
}