Merge pull request #3231 from kevpar/dump-stacks-to-file
Don't write dumped stacks to file for ETW capture state
This commit is contained in:
		| @@ -278,7 +278,7 @@ func setLevel(context *cli.Context, config *srvconfig.Config) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func dumpStacks() { | func dumpStacks(writeToFile bool) { | ||||||
| 	var ( | 	var ( | ||||||
| 		buf       []byte | 		buf       []byte | ||||||
| 		stackSize int | 		stackSize int | ||||||
| @@ -292,13 +292,15 @@ func dumpStacks() { | |||||||
| 	buf = buf[:stackSize] | 	buf = buf[:stackSize] | ||||||
| 	logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf) | 	logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf) | ||||||
|  |  | ||||||
| 	// Also write to file to aid gathering diagnostics | 	if writeToFile { | ||||||
| 	name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid())) | 		// Also write to file to aid gathering diagnostics | ||||||
| 	f, err := os.Create(name) | 		name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid())) | ||||||
| 	if err != nil { | 		f, err := os.Create(name) | ||||||
| 		return | 		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) |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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") | 				log.G(ctx).WithField("signal", s).Debug("received signal") | ||||||
| 				switch s { | 				switch s { | ||||||
| 				case unix.SIGUSR1: | 				case unix.SIGUSR1: | ||||||
| 					dumpStacks() | 					dumpStacks(true) | ||||||
| 				case unix.SIGPIPE: | 				case unix.SIGPIPE: | ||||||
| 					continue | 					continue | ||||||
| 				default: | 				default: | ||||||
|   | |||||||
| @@ -88,14 +88,14 @@ func setupDumpStacks() { | |||||||
| 		logrus.Debugf("Stackdump - waiting signal at %s", event) | 		logrus.Debugf("Stackdump - waiting signal at %s", event) | ||||||
| 		for { | 		for { | ||||||
| 			windows.WaitForSingleObject(h, windows.INFINITE) | 			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) { | func etwCallback(sourceID *guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) { | ||||||
| 	if state == etw.ProviderStateCaptureState { | 	if state == etw.ProviderStateCaptureState { | ||||||
| 		dumpStacks() | 		dumpStacks(false) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Phil Estes
					Phil Estes