Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Add stack dump.
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Liu <lantaol@google.com>
  • Loading branch information
Random-Liu committed Oct 27, 2017
1 parent 64c7196 commit 399a493
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/cri-containerd/cri_containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package main
import (
"flag"
"os"
"os/signal"
"runtime"
"syscall"

"github.com/docker/docker/pkg/reexec"
"github.com/golang/glog"
Expand Down Expand Up @@ -83,6 +86,7 @@ func main() {
cmd.AddCommand(versionCommand())

cmd.Run = func(cmd *cobra.Command, args []string) {
setupDumpStacksTrap()
if err := o.InitFlags(cmd.Flags()); err != nil {
glog.Exitf("Failed to init CRI containerd flags: %v", err)
}
Expand Down Expand Up @@ -118,3 +122,28 @@ func validateConfig(o *options.CRIContainerdOptions) {
selinux.SetDisabled()
}
}

func setupDumpStacksTrap() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGUSR1)
go func() {
for range c {
dumpStacks()
}
}()
}

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]
glog.V(0).Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
}

0 comments on commit 399a493

Please sign in to comment.