Skip to content

Commit

Permalink
Don't write dumped stacks to file for ETW capture state
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
  • Loading branch information
kevpar committed Apr 19, 2019
1 parent a91e043 commit 0376dd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
20 changes: 11 additions & 9 deletions cmd/containerd/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func setLevel(context *cli.Context, config *srvconfig.Config) error {
return nil
}

func dumpStacks() {
func dumpStacks(writeToFile bool) {
var (
buf []byte
stackSize int
Expand All @@ -292,13 +292,15 @@ func dumpStacks() {
buf = buf[:stackSize]
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)

// Also write to file to aid gathering diagnostics
name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid()))
f, err := os.Create(name)
if err != nil {
return
if writeToFile {
// Also write to file to aid gathering diagnostics
name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid()))
f, err := os.Create(name)
if err != nil {
return
}
defer f.Close()
f.WriteString(string(buf))
logrus.Infof("goroutine stack dump written to %s", name)
}
defer f.Close()
f.WriteString(string(buf))
logrus.Infof("goroutine stack dump written to %s", name)
}
2 changes: 1 addition & 1 deletion cmd/containerd/command/main_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func handleSignals(ctx context.Context, signals chan os.Signal, serverC chan *se
log.G(ctx).WithField("signal", s).Debug("received signal")
switch s {
case unix.SIGUSR1:
dumpStacks()
dumpStacks(true)
case unix.SIGPIPE:
continue
default:
Expand Down
4 changes: 2 additions & 2 deletions cmd/containerd/command/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ func setupDumpStacks() {
logrus.Debugf("Stackdump - waiting signal at %s", event)
for {
windows.WaitForSingleObject(h, windows.INFINITE)
dumpStacks()
dumpStacks(true)
}
}()
}

func etwCallback(sourceID *guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
if state == etw.ProviderStateCaptureState {
dumpStacks()
dumpStacks(false)
}
}

Expand Down

0 comments on commit 0376dd4

Please sign in to comment.