-
Notifications
You must be signed in to change notification settings - Fork 5
/
nixbench.go
94 lines (78 loc) · 1.83 KB
/
nixbench.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
93
94
package main
import (
"fmt"
"os"
"sort"
"strings"
cli "gopkg.in/urfave/cli.v2"
yaml "gopkg.in/yaml.v2"
"github.com/jgillich/nixbench/modules"
)
// VERSION is set at build time
var VERSION = "master"
func main() {
moduleNames := []string{}
for key := range modules.Modules {
moduleNames = append(moduleNames, key)
}
app := &cli.App{
Name: "nixbench",
Usage: "A better benchmarking tool for servers",
Description: fmt.Sprintf("Loaded modules: %s", strings.Trim(fmt.Sprintf("%v", moduleNames), "[]")),
Version: VERSION,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "yaml",
Usage: "Output as yaml",
},
&cli.BoolFlag{
Name: "all",
Usage: "Run all modules",
},
&cli.StringSliceFlag{
Name: "module",
Aliases: []string{"m"},
Usage: "Modules to enable",
Value: cli.NewStringSlice("host", "cpu", "disk", "net", "geekbench"),
},
},
Action: func(c *cli.Context) error {
if !c.Bool("yaml") {
fmt.Printf("nixbench %s - https://github.com/jgillich/nixbench\n", VERSION)
}
enabledModules := c.StringSlice("module")
if c.Bool("all") {
enabledModules = moduleNames
}
sort.Strings(enabledModules)
for _, name := range enabledModules {
module, ok := modules.Modules[name]
if !ok {
return fmt.Errorf("unknown module '%s'", name)
}
if err := module.Run(); err != nil {
return err
}
if c.Bool("yaml") {
var r map[string]interface{} = map[string]interface{}{}
r[name] = module
yml, err := yaml.Marshal(r)
if err != nil {
return err
}
fmt.Printf(string(yml))
} else {
fmt.Printf("\n%s\n", name)
for i := 1; i <= len(name); i++ {
fmt.Print("-")
}
fmt.Print("\n")
module.Print()
fmt.Print("\n")
}
}
return nil
},
}
app.Run(os.Args)
}