diff --git a/cmd/stress/stress.go b/cmd/stress/stress.go index ee68917cba..b1dda15e9d 100644 --- a/cmd/stress/stress.go +++ b/cmd/stress/stress.go @@ -20,6 +20,7 @@ import ( "io/ioutil" "os" "os/exec" + "path/filepath" "regexp" "runtime" "syscall" @@ -32,6 +33,7 @@ var ( flagKill = flag.Bool("kill", true, "kill timed out processes if true, otherwise just print pid (to attach with gdb)") flagFailure = flag.String("failure", "", "fail only if output matches `regexp`") flagIgnore = flag.String("ignore", "", "ignore failure if output matches `regexp`") + flagOutput = flag.String("o", defaultPrefix(), "output failure logs to `path` plus a unique suffix") ) func init() { @@ -47,6 +49,11 @@ Usage: } } +func defaultPrefix() string { + date := time.Now().Format("go-stress-20060102T150405-") + return filepath.Join(os.TempDir(), date) +} + func main() { flag.Parse() if *flagP <= 0 || *flagTimeout <= 0 || len(flag.Args()) == 0 { @@ -115,7 +122,8 @@ func main() { continue } fails++ - f, err := ioutil.TempFile("", "go-stress") + dir, path := filepath.Split(*flagOutput) + f, err := ioutil.TempFile(dir, path) if err != nil { fmt.Printf("failed to create temp file: %v\n", err) os.Exit(1)