-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
117 lines (92 loc) · 2.55 KB
/
run.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"context"
"flag"
"fmt"
"runtime"
"time"
"github.com/google/subcommands"
"github.com/google/uuid"
"github.com/mmcloughlin/goperf/internal/flags"
"github.com/mmcloughlin/goperf/pkg/command"
"github.com/mmcloughlin/goperf/pkg/fs"
"github.com/mmcloughlin/goperf/pkg/job"
"github.com/mmcloughlin/goperf/pkg/platform"
"github.com/mmcloughlin/goperf/pkg/runner"
)
var defaultModule = job.Module{
Path: "github.com/klauspost/compress",
Version: "b949da471e55fbe4393e6eb595602d936f5c312e",
}
type Run struct {
command.Base
*platform.Platform
toolchainconfig flags.TypeParams
mod job.Module
output string
preserve bool
goproxy string
}
func NewRun(b command.Base, p *platform.Platform) *Run {
return &Run{
Base: b,
Platform: p,
toolchainconfig: flags.TypeParams{
Type: "release",
Params: flags.Params{
{Key: "version", Value: runtime.Version()},
},
},
}
}
func (*Run) Name() string { return "run" }
func (*Run) Synopsis() string { return "run benchmark suites against a version of the go toolchain" }
func (*Run) Usage() string {
return ""
}
func (cmd *Run) SetFlags(f *flag.FlagSet) {
f.Var(&cmd.toolchainconfig, "toolchain", "toolchain configuration")
f.StringVar(&cmd.mod.Path, "modpath", defaultModule.Path, "module path")
f.StringVar(&cmd.mod.Version, "modrev", defaultModule.Version, "module revision")
f.StringVar(&cmd.output, "output", "", "output path")
f.BoolVar(&cmd.preserve, "preserve", false, "preserve working directory")
f.StringVar(&cmd.goproxy, "goproxy", "", "GOPROXY value for the benchark runner")
cmd.Platform.SetFlags(f)
}
func (cmd *Run) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
// Build toolchain.
tc, err := runner.NewToolchain(cmd.toolchainconfig.Type, cmd.toolchainconfig.Params.Map())
if err != nil {
return cmd.Error(err)
}
// Construct workspace.
w, err := runner.NewWorkspace(runner.WithLogger(cmd.Log))
if err != nil {
return cmd.Error(err)
}
if cmd.output != "" {
w.Options(runner.WithArtifactStore(fs.NewLocal(cmd.output)))
}
// Initialize runner.
r := runner.NewRunner(w, tc)
if cmd.goproxy != "" {
r.SetGoProxy(cmd.goproxy)
}
if err := cmd.ConfigureRunner(r); err != nil {
return cmd.Error(err)
}
r.Init(ctx)
// Run benchmark.
suite := job.Suite{
Module: cmd.mod,
Short: true,
BenchTime: 10 * time.Millisecond,
}
output := fmt.Sprintf("%s.out", uuid.New())
r.Benchmark(ctx, suite, output)
// Clean.
if !cmd.preserve {
r.Clean(ctx)
}
return cmd.Status(w.Error())
}