]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/pprof: store temporary files in temporary directory
authorRuss Cox <rsc@golang.org>
Tue, 14 Jul 2015 19:43:33 +0000 (15:43 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 15 Jul 2015 04:30:50 +0000 (04:30 +0000)
Fixes #9180.

Change-Id: Id5adaea0ca9005946fb89c88a10c6f59d8c0943c
Reviewed-on: https://go-review.googlesource.com/12202
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/cmd/pprof/internal/commands/commands.go
src/cmd/pprof/internal/driver/driver.go

index 175c7cc99cfb595a469406c2132d426119f20a8b..9570cd0440409965db320ca1d7e3730c11e4332e 100644 (file)
@@ -9,6 +9,7 @@ import (
        "bytes"
        "fmt"
        "io"
+       "io/ioutil"
        "os"
        "os/exec"
        "runtime"
@@ -185,9 +186,26 @@ func saveSVGToFile() PostProcessor {
        }
 }
 
+var vizTmpDir string
+
+func makeVizTmpDir() error {
+       if vizTmpDir != "" {
+               return nil
+       }
+       name, err := ioutil.TempDir("", "pprof-")
+       if err != nil {
+               return err
+       }
+       vizTmpDir = name
+       return nil
+}
+
 func invokeVisualizer(interactive **bool, format PostProcessor, suffix string, visualizers []string) PostProcessor {
        return func(input *bytes.Buffer, output io.Writer, ui plugin.UI) error {
-               tempFile, err := tempfile.New(os.Getenv("PPROF_TMPDIR"), "pprof", "."+suffix)
+               if err := makeVizTmpDir(); err != nil {
+                       return err
+               }
+               tempFile, err := tempfile.New(vizTmpDir, "pprof", "."+suffix)
                if err != nil {
                        return err
                }
index 7f345a3bc27ad1daf00b713f20cd7259eafcf24d..df6a2d18b25a837acc283d60601f757405ae3c95 100644 (file)
@@ -894,7 +894,7 @@ var usageMsg = "Output file parameters (for file-based output formats):\n" +
        "  -help             This message"
 
 var usageMsgVars = "Environment Variables:\n" +
-       "   PPROF_TMPDIR       Location for temporary files (default $HOME/pprof)\n" +
+       "   PPROF_TMPDIR       Location for saved profiles (default $HOME/pprof)\n" +
        "   PPROF_TOOLS        Search path for object-level tools\n" +
        "   PPROF_BINARY_PATH  Search path for local binary files\n" +
        "                      default: $HOME/pprof/binaries\n" +