|
@@ -16,10 +16,8 @@ package driver
|
16
|
16
|
|
17
|
17
|
import (
|
18
|
18
|
"bytes"
|
19
|
|
- "encoding/base64"
|
20
|
19
|
"fmt"
|
21
|
20
|
"io"
|
22
|
|
- "math/rand"
|
23
|
21
|
"net/http"
|
24
|
22
|
"net/url"
|
25
|
23
|
"os"
|
|
@@ -407,11 +405,16 @@ func profileProtoReader(path string, ui plugin.UI) (io.ReadCloser, error) {
|
407
|
405
|
}
|
408
|
406
|
if bytes.Equal(actualHeader, perfHeader) {
|
409
|
407
|
sourceFile.Close()
|
410
|
|
- profileFile, convertErr := convertPerfData(path, ui)
|
|
408
|
+ profileFilePath, convertErr := convertPerfData(path, ui)
|
411
|
409
|
if convertErr != nil {
|
412
|
410
|
return nil, convertErr
|
413
|
411
|
}
|
414
|
|
- return os.Open(profileFile)
|
|
412
|
+ profileFile, openErr := os.Open(profileFilePath)
|
|
413
|
+ if openErr != nil {
|
|
414
|
+ os.Remove(profileFilePath)
|
|
415
|
+ return nil, openErr
|
|
416
|
+ }
|
|
417
|
+ return DeleteOnClose(profileFile), nil
|
415
|
418
|
}
|
416
|
419
|
return sourceFile, nil
|
417
|
420
|
}
|
|
@@ -423,19 +426,16 @@ func convertPerfData(perfPath string, ui plugin.UI) (string, error) {
|
423
|
426
|
ui.Print(fmt.Sprintf(
|
424
|
427
|
"Converting %s to a profile.proto... (May take a few minutes)",
|
425
|
428
|
perfPath))
|
426
|
|
- randomBytes := make([]byte, 32)
|
427
|
|
- _, randErr := rand.Read(randomBytes)
|
428
|
|
- if randErr != nil {
|
429
|
|
- return "", randErr
|
430
|
|
- }
|
431
|
|
- randomFileName := "/tmp/pprof_" +
|
432
|
|
- base64.StdEncoding.EncodeToString(randomBytes)
|
433
|
|
- cmd := exec.Command("perf_to_profile", perfPath, randomFileName)
|
|
429
|
+ profilePath, err := newTempFilePath("/tmp", "pprof_", ".pb.gz")
|
|
430
|
+ if err != nil {
|
|
431
|
+ return "", err
|
|
432
|
+ }
|
|
433
|
+ cmd := exec.Command("perf_to_profile", perfPath, profilePath)
|
434
|
434
|
if err := cmd.Run(); err != nil {
|
|
435
|
+ os.Remove(profilePath)
|
435
|
436
|
return "", err
|
436
|
437
|
}
|
437
|
|
-
|
438
|
|
- return randomFileName, nil
|
|
438
|
+ return profilePath, nil
|
439
|
439
|
}
|
440
|
440
|
|
441
|
441
|
// adjustURL validates if a profile source is a URL and returns an
|