captplanet: add ctrl+\ for dumping goroutines (#416)
This commit is contained in:
parent
c3a1d71616
commit
3b98b93f05
1
.gitignore
vendored
1
.gitignore
vendored
@ -36,6 +36,7 @@ protos/google/*
|
|||||||
*test_bolt.db
|
*test_bolt.db
|
||||||
|
|
||||||
*.coverprofile
|
*.coverprofile
|
||||||
|
*.log
|
||||||
|
|
||||||
/release/
|
/release/
|
||||||
*.swp
|
*.swp
|
||||||
|
@ -4,10 +4,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
||||||
|
"storj.io/storj/internal/memory"
|
||||||
"storj.io/storj/pkg/process"
|
"storj.io/storj/pkg/process"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +31,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
go dumpHandler()
|
||||||
|
|
||||||
// process.Exec will load this for this command.
|
// process.Exec will load this for this command.
|
||||||
runCmd.Flags().String("config",
|
runCmd.Flags().String("config",
|
||||||
filepath.Join(defaultConfDir, "config.yaml"), "path to configuration")
|
filepath.Join(defaultConfDir, "config.yaml"), "path to configuration")
|
||||||
@ -30,3 +40,33 @@ func main() {
|
|||||||
filepath.Join(defaultConfDir, "setup.yaml"), "path to configuration")
|
filepath.Join(defaultConfDir, "setup.yaml"), "path to configuration")
|
||||||
process.Exec(rootCmd)
|
process.Exec(rootCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dumpHandler listens for Ctrl+\ on Unix
|
||||||
|
func dumpHandler() {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
// unsupported on Windows
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sigs := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigs, syscall.SIGQUIT)
|
||||||
|
for range sigs {
|
||||||
|
dumpGoroutines()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpGoroutines() {
|
||||||
|
buf := make([]byte, memory.MB)
|
||||||
|
n := runtime.Stack(buf, true)
|
||||||
|
|
||||||
|
p := time.Now().Format("dump-2006-01-02T15-04-05.999999999.log")
|
||||||
|
if abs, err := filepath.Abs(p); err == nil {
|
||||||
|
p = abs
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "Writing stack traces to \"%v\"\n", p)
|
||||||
|
|
||||||
|
err := ioutil.WriteFile(p, buf[:n], 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user