Don't write dumped stacks to file for ETW capture state

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
This commit is contained in:
Kevin Parsons 2019-04-18 17:46:35 -07:00
parent a91e04356d
commit 0376dd4605
3 changed files with 14 additions and 12 deletions

View File

@ -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
@ -292,6 +292,7 @@ func dumpStacks() {
buf = buf[:stackSize]
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
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)
@ -301,4 +302,5 @@ func dumpStacks() {
defer f.Close()
f.WriteString(string(buf))
logrus.Infof("goroutine stack dump written to %s", name)
}
}

View File

@ -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:

View File

@ -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)
}
}