mirror of
https://github.com/google/gops.git
synced 2024-11-27 08:31:17 +02:00
keep trace and profile files when go tool chain is not available (#52)
This commit is contained in:
parent
f6c95cf224
commit
6865b1eab5
13
cmd.go
13
cmd.go
@ -65,11 +65,15 @@ func trace(addr net.TCPAddr) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(tmpfile.Name())
|
|
||||||
if err := ioutil.WriteFile(tmpfile.Name(), out, 0); err != nil {
|
if err := ioutil.WriteFile(tmpfile.Name(), out, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("Trace dump saved to: %s\n", tmpfile.Name())
|
fmt.Printf("Trace dump saved to: %s\n", tmpfile.Name())
|
||||||
|
// If go tool chain not found, stopping here and keep trace file.
|
||||||
|
if _, err := exec.LookPath("go"); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer os.Remove(tmpfile.Name())
|
||||||
cmd := exec.Command("go", "tool", "trace", tmpfile.Name())
|
cmd := exec.Command("go", "tool", "trace", tmpfile.Name())
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
@ -92,10 +96,15 @@ func pprof(addr net.TCPAddr, p byte) error {
|
|||||||
if len(out) == 0 {
|
if len(out) == 0 {
|
||||||
return errors.New("failed to read the profile")
|
return errors.New("failed to read the profile")
|
||||||
}
|
}
|
||||||
defer os.Remove(tmpDumpFile.Name())
|
|
||||||
if err := ioutil.WriteFile(tmpDumpFile.Name(), out, 0); err != nil {
|
if err := ioutil.WriteFile(tmpDumpFile.Name(), out, 0); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Profile dump saved to: %s\n", tmpDumpFile.Name())
|
||||||
|
// If go tool chain not found, stopping here and keep dump file.
|
||||||
|
if _, err := exec.LookPath("go"); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer os.Remove(tmpDumpFile.Name())
|
||||||
}
|
}
|
||||||
// Download running binary
|
// Download running binary
|
||||||
tmpBinFile, err := ioutil.TempFile("", "binary")
|
tmpBinFile, err := ioutil.TempFile("", "binary")
|
||||||
|
Loading…
Reference in New Issue
Block a user