github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/utils/dyn_pprof_unix.go (about) 1 // +build linux darwin freebsd unix 2 // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0. 3 4 package utils 5 6 import ( 7 "os" 8 "os/signal" 9 "syscall" 10 11 tidbutils "github.com/pingcap/tidb-tools/pkg/utils" 12 13 "github.com/pingcap/log" 14 "go.uber.org/zap" 15 ) 16 17 const startPProfSignal = syscall.SIGUSR1 18 19 // StartDynamicPProfListener starts the listener that will enable pprof when received `startPProfSignal`. 20 func StartDynamicPProfListener(tls *tidbutils.TLS) { 21 signalChan := make(chan os.Signal, 1) 22 signal.Notify(signalChan, startPProfSignal) 23 go func() { 24 for sig := range signalChan { 25 if sig == startPProfSignal { 26 log.Info("signal received, starting pprof...", zap.Stringer("signal", sig)) 27 if err := StartPProfListener("0.0.0.0:0", tls); err != nil { 28 log.Warn("failed to start pprof", zap.Error(err)) 29 return 30 } 31 } 32 } 33 }() 34 }