You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
678 B
31 lines
678 B
package proc |
|
|
|
import ( |
|
"fmt" |
|
"git.diulo.com/mogfee/kit/logx" |
|
"os" |
|
"path" |
|
"runtime/pprof" |
|
"syscall" |
|
"time" |
|
) |
|
|
|
const ( |
|
goroutineProfile = "goroutine" |
|
debuglevel = 2 |
|
) |
|
|
|
func dumpGoroutines() { |
|
command := path.Base(os.Args[0]) |
|
pid := syscall.Getpid() |
|
|
|
dumpFile := path.Join(os.TempDir(), fmt.Sprintf("%s-%d-goroutines-%s.dump", |
|
command, pid, time.Now().Format(timeFormat))) |
|
logx.Infof("Got dump goroutine signal, printing goroutine profile to %s", dumpFile) |
|
if f, err := os.Create(dumpFile); err != nil { |
|
logx.Errorf("Failed to dump goroutine profile, error: %v", err) |
|
} else { |
|
defer f.Close() |
|
pprof.Lookup(goroutineProfile).WriteTo(f, debuglevel) |
|
} |
|
}
|
|
|