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

Commit

Permalink
Merge pull request #366 from Random-Liu/add-dump-stack
Browse files Browse the repository at this point in the history
Add stack dump.
  • Loading branch information
Random-Liu committed Oct 28, 2017
2 parents 6cded68 + 439ee0a commit c3b03f8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmd/cri-containerd/cri_containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"

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

cmd.RunE = func(cmd *cobra.Command, args []string) error {
setupDumpStacksTrap()
if err := o.InitFlags(cmd.Flags()); err != nil {
return fmt.Errorf("failed to init CRI containerd flags: %v", err)
}
Expand Down Expand Up @@ -155,3 +159,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 c3b03f8

Please sign in to comment.