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 b4b679e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Binary file added cmd/cri-containerd/.cri_containerd.go.swp
Binary file not shown.
27 changes: 27 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,26 @@ 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() {
buf := make([]byte, 1024)
for {
n := runtime.Stack(buf, true)
if n < len(buf) {
buf = buf[:n]
break
}
buf = make([]byte, 2*len(buf))
}
glog.V(0).Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
}

0 comments on commit b4b679e

Please sign in to comment.