-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsg.go
56 lines (46 loc) · 1.4 KB
/
sg.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
// Package main is the main engine of the stress gauge.
package main
import (
"flag"
"fmt"
"github.com/op/go-logging"
"os"
"sync"
)
// log is the logger, duh.
var log = logging.MustGetLogger("sg")
// profileFile stores the filename of the profile to run.
var profileFile string
// completionWg is the completion wait group, which will wait for all requests to go through.
var completionWg sync.WaitGroup
// totalSentRequests stores the total number of sent requests.
var totalSentRequests int
// profile stores the profile to stress.
var profile *Profile
// init parses the flags.
func init() {
totalSentRequests = 0
flag.StringVar(&profileFile, "profile", "", "path to stress profile")
logFormat := logging.MustStringFormatter("%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level}%{color:reset} %{message}")
logging.SetBackend(logging.NewBackendFormatter(logging.NewLogBackend(os.Stderr, "", 0), logFormat))
}
func main() {
flag.Parse()
err := loadProfile(profileFile)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
stress(profile) // blocking call
log.Notice("Saved output to %s.", saveResult(profile, profileFile))
}
func stress(profile *Profile) {
for _, test := range profile.Tests {
log.Notice("Starting test %s.", test)
for _, r := range test.Requests {
r.Spawn(nil, &completionWg)
}
completionWg.Wait()
}
log.Notice("Sent a total of %d requests.", totalSentRequests)
}