2013-08-13 13:47:01 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
2013-09-11 00:31:17 +01:00
|
|
|
"fmt"
|
2013-08-13 13:47:01 +02:00
|
|
|
"log"
|
2013-09-11 00:31:17 +01:00
|
|
|
"os"
|
2013-08-14 18:24:20 +02:00
|
|
|
"runtime"
|
2013-08-13 13:47:01 +02:00
|
|
|
)
|
|
|
|
|
|
2013-09-11 00:10:35 +01:00
|
|
|
// command is a closure function which each command constructor
|
|
|
|
|
// builds and returns
|
|
|
|
|
type command func() error
|
|
|
|
|
|
2013-09-11 00:31:17 +01:00
|
|
|
var usage = fmt.Sprintf(
|
|
|
|
|
`Usage: vegeta [globals] <command> [options]
|
|
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
|
attack Hit the targets
|
|
|
|
|
report Report the results
|
2013-11-05 08:17:32 +00:00
|
|
|
rapid Hit the targets with multiple rates
|
2013-09-11 00:31:17 +01:00
|
|
|
|
|
|
|
|
Globals:
|
|
|
|
|
-cpus=%d Number of CPUs to use
|
|
|
|
|
`, runtime.NumCPU())
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
flag.Usage = func() { fmt.Print(usage) }
|
|
|
|
|
cpus := flag.Int("cpus", runtime.NumCPU(), "Number of CPUs to use")
|
|
|
|
|
flag.Parse()
|
|
|
|
|
runtime.GOMAXPROCS(*cpus)
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 13:47:01 +02:00
|
|
|
func main() {
|
2013-09-11 00:10:35 +01:00
|
|
|
commands := map[string]func([]string) command{
|
|
|
|
|
"attack": attackCmd,
|
|
|
|
|
"report": reportCmd,
|
2013-11-05 08:17:32 +00:00
|
|
|
"rapid": rapidCmd,
|
2013-09-11 00:10:35 +01:00
|
|
|
}
|
2013-09-07 22:59:12 +01:00
|
|
|
|
2013-09-11 00:31:17 +01:00
|
|
|
args := flag.Args()
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
|
flag.Usage()
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
2013-09-07 22:59:12 +01:00
|
|
|
|
2013-09-11 00:10:35 +01:00
|
|
|
if cmd, ok := commands[args[0]]; !ok {
|
|
|
|
|
log.Fatalf("Unknown command: %s", args[0])
|
|
|
|
|
} else if err := cmd(args[1:])(); err != nil {
|
|
|
|
|
log.Fatal(err)
|
2013-08-13 13:47:01 +02:00
|
|
|
}
|
|
|
|
|
}
|