This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
123 lines (104 loc) · 2.8 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
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
118
119
120
121
122
123
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
"runtime"
"strings"
)
var usage = `
Usage: %[1]s [run] PLATFORM [PLATFORM ...]
Benchmark one or more platforms.
Examples:
%[1]s platform/python/django
%[1]s run platform/javascript/express
Usage: %[1]s report RESULT [RESULT ...]
Print an HTML report summarizing the results of one or more benchmark runs.
Reports are automatically created after a successful benchmark run.
This subcommand allows re-generating a report from benchmark result data on demand.
Examples:
%[1]s report result/python/django/20210818-082527-tbnfsga
%[1]s report result/python/django/20210818-*
Usage: %[1]s compare RESULT [RESULT ...]
Compares various runs using benchstat.
Examples:
%[1]s compare result/python/django/20210818-082527-tbnfsga result/platform/python/django/20210909-150838-bcvjada
%[1]s compare result/python/django/20210818-*
`
func printUsage() {
fmt.Fprintf(os.Stderr, strings.TrimSpace(usage), filepath.Base(os.Args[0]))
fmt.Fprintln(os.Stderr)
}
// openBrowser controls whether to open a web browser to show HTML reports. The
// default behavior is to open a browser, unless running multiple benchmarks
// from a single command line execution.
var openBrowser = true
// sanityCheckMode affects benchmark configuration to perform sanity checks
// instead of a regular run. In sanity check mode, benchmarks are run for a
// short duration for the sole purpose of validating that the target app works
// as expected and that instrumented apps do what they need to do.
var sanityCheckMode bool
func main() {
log.SetFlags(log.LstdFlags | log.Lmsgprefix)
log.SetPrefix("[sentry-sdk-benchmark] ")
defer func() {
if err := recover(); err != nil {
_, file, line, ok := runtime.Caller(2)
if !ok {
panic(err)
}
log.Fatalf("Failure: %s:%d: %s", file, line, err)
}
}()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
flag.BoolVar(&openBrowser, "browser", true, "open report in browser")
flag.BoolVar(&sanityCheckMode, "s", false, "sanity check mode (for project maintainers)")
flag.Parse()
if len(flag.Args()) < 1 {
printUsage()
os.Exit(2)
}
switch args := flag.Args(); args[0] {
case "report":
args = args[1:]
if len(args) == 0 {
printUsage()
os.Exit(2)
}
if len(args) > 1 {
openBrowser = false
}
Report(args)
case "compare":
args = args[1:]
if len(args) == 0 {
printUsage()
os.Exit(2)
}
Compare(args)
case "run":
args = args[1:]
fallthrough
default:
if len(args) == 0 {
printUsage()
os.Exit(2)
}
if len(args) > 1 {
openBrowser = false
}
for _, path := range args {
bc := BenchmarkConfigFromPath(path)
if sanityCheckMode {
bc.PlatformConfig.RPS = 3
bc.PlatformConfig.Duration = "5s"
}
Benchmark(ctx, bc)
}
}
}