|
|
@ -6,18 +6,20 @@ import (
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const timeFormat = "0102150405"
|
|
|
|
const (
|
|
|
|
|
|
|
|
profileDuration = time.Minute
|
|
|
|
|
|
|
|
timeFormat = "0102150405"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var done = make(chan struct{})
|
|
|
|
var done = make(chan struct{})
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
var profiler Stopper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://golang.org/pkg/os/signal/#Notify
|
|
|
|
// https://golang.org/pkg/os/signal/#Notify
|
|
|
|
signals := make(chan os.Signal, 1)
|
|
|
|
signals := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
|
|
|
|
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
|
|
|
@ -28,12 +30,11 @@ func init() {
|
|
|
|
case syscall.SIGUSR1:
|
|
|
|
case syscall.SIGUSR1:
|
|
|
|
dumpGoroutines(fileCreator{})
|
|
|
|
dumpGoroutines(fileCreator{})
|
|
|
|
case syscall.SIGUSR2:
|
|
|
|
case syscall.SIGUSR2:
|
|
|
|
if profiler == nil {
|
|
|
|
profiler := StartProfile()
|
|
|
|
profiler = StartProfile()
|
|
|
|
go func() {
|
|
|
|
} else {
|
|
|
|
<-time.After(profileDuration)
|
|
|
|
profiler.Stop()
|
|
|
|
profiler.Stop()
|
|
|
|
profiler = nil
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
case syscall.SIGTERM:
|
|
|
|
case syscall.SIGTERM:
|
|
|
|
stopOnSignal()
|
|
|
|
stopOnSignal()
|
|
|
|
gracefulStop(signals, syscall.SIGTERM)
|
|
|
|
gracefulStop(signals, syscall.SIGTERM)
|
|
|
|