Skip to content

Commit

Permalink
feat: auto stop profiling after one minute (zeromicro#3742)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Nov 24, 2023
1 parent eb14d13 commit ede7e68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 1 addition & 3 deletions core/collection/ring.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package collection

import (
"sync"
)
import "sync"

// A Ring can be used as fixed size ring.
type Ring struct {
Expand Down
17 changes: 9 additions & 8 deletions core/proc/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/zeromicro/go-zero/core/logx"
)

const timeFormat = "0102150405"
const (
profileDuration = time.Minute
timeFormat = "0102150405"
)

var done = make(chan struct{})

func init() {
go func() {
var profiler Stopper

// https://golang.org/pkg/os/signal/#Notify
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
Expand All @@ -28,12 +30,11 @@ func init() {
case syscall.SIGUSR1:
dumpGoroutines(fileCreator{})
case syscall.SIGUSR2:
if profiler == nil {
profiler = StartProfile()
} else {
profiler := StartProfile()
go func() {
<-time.After(profileDuration)
profiler.Stop()
profiler = nil
}
}()
case syscall.SIGTERM:
stopOnSignal()
gracefulStop(signals, syscall.SIGTERM)
Expand Down

0 comments on commit ede7e68

Please sign in to comment.