Skip to content

Instantly share code, notes, and snippets.

@jessedearing
Created January 5, 2017 23:39
Show Gist options
  • Save jessedearing/7f544238aee017a05eb1c526d932ffd1 to your computer and use it in GitHub Desktop.
Save jessedearing/7f544238aee017a05eb1c526d932ffd1 to your computer and use it in GitHub Desktop.
Have go dump a stack trace on USR1
package main
import (
"os"
"os/signal"
"runtime/pprof"
"syscall"
)
func main() {
sigchan := make(chan os.Signal)
go func() {
for _ = range sigchan {
ps := pprof.Profiles()
for _, pro := range ps {
pro.WriteTo(os.Stderr, 2)
}
}
}()
signal.Notify(sigchan, syscall.SIGUSR1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment