Skip to content

Commit

Permalink
utils: Add function to write goroutine stacks to a file
Browse files Browse the repository at this point in the history
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
  • Loading branch information
mrunalp committed Oct 9, 2018
1 parent 9c40cfd commit c66d12b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions utils/utils.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"runtime"
"strings"
Expand Down Expand Up @@ -159,3 +160,16 @@ func WriteGoroutineStacks(w io.Writer) error {
_, err := w.Write(buf)
return err
}

// WriteGoroutineStacksToFile write goroutine stacks
// to the specified file.
func WriteGoroutineStacksToFile(path string) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
return err
}
defer f.Close()
defer f.Sync()

return WriteGoroutineStacks(f)
}

0 comments on commit c66d12b

Please sign in to comment.