From b4e97c0ed882dfd67cc1c1ade6ec4b2b67535c1f Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 19 Nov 2018 10:48:26 -0500 Subject: [PATCH] cmd/stress: prefix logs with start date/time Currently, stress logs are named "/tmp/go-stress-" plus a random number. This makes it really annoying to tease apart failures from different stress runs. This CL changes the default prefix to "/tmp/go-stress--" where the date/time part is when the stress command started. This naming clusters logs by stress invocation, making it easy to tease apart invocations, even if there are multiple stresses running concurrently or they are run back-to-back. This also provides a flag to override this prefix. Change-Id: I043e5ee7168ba6db4e2355e39b147071edbc6864 Reviewed-on: https://go-review.googlesource.com/c/150047 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- cmd/stress/stress.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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)