Merge pull request #898 from coolljt0725/stack

Add SIGUSR1 to print the stack of containerd
This commit is contained in:
Derek McGowan 2017-05-26 16:26:50 -07:00 committed by GitHub
commit 7fc91b0591
3 changed files with 20 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime"
"time"
"github.com/boltdb/bolt"
@ -436,3 +437,18 @@ func interceptor(ctx gocontext.Context,
}
return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
}
func dumpStacks() {
var (
buf []byte
stackSize int
)
bufferLen := 16384
for stackSize == len(buf) {
buf = make([]byte, bufferLen)
stackSize = runtime.Stack(buf, true)
bufferLen *= 2
}
buf = buf[:stackSize]
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
}

View File

@ -50,6 +50,8 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
if err := reaper.Reap(); err != nil {
log.G(global).WithError(err).Error("reap containerd processes")
}
case unix.SIGUSR1:
dumpStacks()
default:
server.Stop()
return nil

View File

@ -39,6 +39,8 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
if err := reaper.Reap(); err != nil {
log.G(global).WithError(err).Error("reap containerd processes")
}
case unix.SIGUSR1:
dumpStacks()
default:
server.Stop()
return nil