mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Spew debugging
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
3b6cd20b0b
commit
4c62b12636
6 changed files with 59 additions and 14 deletions
|
@ -476,10 +476,6 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// set up SIGUSR1 handler on Unix-like systems, or a Win32 global event
|
||||
// on Windows to dump Go routine stacks
|
||||
setupDumpStackTrap(config.Root)
|
||||
|
||||
uidMaps, gidMaps, err := setupRemappedRoot(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -699,6 +695,10 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
|
|||
engineCpus.Set(float64(info.NCPU))
|
||||
engineMemory.Set(float64(info.MemTotal))
|
||||
|
||||
// set up SIGUSR1 handler on Unix-like systems, or a Win32 global event
|
||||
// on Windows to dump Go routine stacks
|
||||
d.setupDumpStackTrap(config.Root)
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
|
|
33
daemon/debugtrap.go
Normal file
33
daemon/debugtrap.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package daemon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const dataStructuresLogNameTemplate = "daemon-data-%s.log"
|
||||
|
||||
// dumpDaemon appends the daemon datastructures into file in dir and returns full path
|
||||
// to that file.
|
||||
func (d *Daemon) dumpDaemon(dir string) (string, error) {
|
||||
// Ensure we recover from a panic as we are doing this without any locking
|
||||
defer func() {
|
||||
recover()
|
||||
}()
|
||||
|
||||
path := filepath.Join(dir, fmt.Sprintf(dataStructuresLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1)))
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to open file to write the daemon datastructure dump")
|
||||
}
|
||||
defer f.Close()
|
||||
spew.Fdump(f, d) // Does not return an error
|
||||
f.Sync()
|
||||
return path, nil
|
||||
}
|
|
@ -7,12 +7,11 @@ import (
|
|||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
stackdump "github.com/docker/docker/pkg/signal"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
stackdump "github.com/docker/docker/pkg/signal"
|
||||
)
|
||||
|
||||
func setupDumpStackTrap(root string) {
|
||||
func (d *Daemon) setupDumpStackTrap(root string) {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGUSR1)
|
||||
go func() {
|
||||
|
@ -20,9 +19,15 @@ func setupDumpStackTrap(root string) {
|
|||
path, err := stackdump.DumpStacks(root)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to write goroutines dump")
|
||||
continue
|
||||
} else {
|
||||
logrus.Infof("goroutine stacks written to %s", path)
|
||||
}
|
||||
path, err = d.dumpDaemon(root)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to write daemon datastructure dump")
|
||||
} else {
|
||||
logrus.Infof("daemon datastructure dump written to %s", path)
|
||||
}
|
||||
logrus.Infof("goroutine stacks written to %s", path)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
package daemon
|
||||
|
||||
func setupDumpStackTrap(_ string) {
|
||||
func (d *Daemon) setupDumpStackTrap(_ string) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/docker/docker/pkg/system"
|
||||
)
|
||||
|
||||
func setupDumpStackTrap(root string) {
|
||||
func (d *Daemon) setupDumpStackTrap(root string) {
|
||||
// Windows does not support signals like *nix systems. So instead of
|
||||
// trapping on SIGUSR1 to dump stacks, we wait on a Win32 event to be
|
||||
// signaled. ACL'd to builtin administrators and local system
|
||||
|
@ -38,9 +38,15 @@ func setupDumpStackTrap(root string) {
|
|||
path, err := signal.DumpStacks(root)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to write goroutines dump")
|
||||
continue
|
||||
} else {
|
||||
logrus.Infof("goroutine stacks written to %s", path)
|
||||
}
|
||||
path, err = d.dumpDaemon(root)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to write daemon datastructure dump")
|
||||
} else {
|
||||
logrus.Infof("daemon datastructure dump written to %s", path)
|
||||
}
|
||||
logrus.Infof("goroutine stacks written to %s", path)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
gosignal "os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
@ -82,7 +83,7 @@ func DumpStacks(dir string) (string, error) {
|
|||
bufferLen *= 2
|
||||
}
|
||||
buf = buf[:stackSize]
|
||||
path := filepath.Join(dir, fmt.Sprintf(stacksLogNameTemplate, time.Now().Format(time.RFC3339)))
|
||||
path := filepath.Join(dir, fmt.Sprintf(stacksLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1)))
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to open file to write the goroutine stacks")
|
||||
|
|
Loading…
Reference in a new issue