New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: heap, allocs, block, and mutex profiles truncate stacks at 32 frames #43669
Comments
Note for clarity: CPU profiles also have a limit: 64 frames. However, the back channel interface to runtime/pprof means that we could change that limit easily without breaking the API, and the variable size interface avoid extra memory use unless frames are actually that large. |
Change https://go.dev/cl/572396 mentions this issue: |
I come across this problem every once in a while when looking at customer profiles and profiles from internal applications, especially for memory profiles. Today I was looking at a live heap profile with > 50% of truncated stacks and got sufficiently annoyed to actually take another look at this issue and see if there is something that could be done that wouldn't involve a major overhaul of the memory profiler as discussed in this issue. (note: we only show 3 frames for truncated frames b/c they can cause a lot of storage/perf problems in some cases) I ended up submitting the idea I came up with as a new CL. It increases the stack size to 128 and deals with the MemProfileRecord API problem by embedding a reference to a bigger stack trace as a private struct field when needed. This shouldn't cause any Go 1 API compatibility issues, while fixing this problem. Memory usage will only be increased for applications that have memory profiling enabled and experience problems with truncated stack traces. PTAL and let me know what you think. If the change seems like a reasonable improvement, I can do the remaining work for mutex/block profiles as well to bring them in sync. |
I remember the first time I've encountered the stack depth limit in Go profiles and I found it quite confusing and obscure. I wonder, if we should at the same time make it more explicit that truncation has happened. Maybe that could be done fairly simply by inserting a logical root like |
At the very minimum, this phenomenon could be prominently documented - it took me a while to find out this issue, although it is obvious in retrospect looking at the flame graph! |
The runtime currently (as of Go 1.15) limits recorded stacks of several profile types to 32 frames. This causes deep stacks to become unrooted in pprof call graphs, leading to confusing results and interfering with aggregate statistics up the call graph.
These are hard-coded array bounds in the public runtime API for StackRecord (used in BlockProfileRecord) and MemProfileRecord. Unfortunately, this means these are part of the Go 1 runtime API, so we can't just change them. If we were to increase them, this would impact memory for relatively little gain, since stacks typically aren't this deep. Finally, we probably need some reasonable bound on stack depth just to avoid blowing up profiles.
The "right" fix, in my opinion, is to do what we did with CPU profiles: deprecate the runtime package interface in favor of runtime/pprof, create a log-based back channel from runtime to runtime/pprof that can handle variable-sized stack traces, and perform accumulation in runtime/pprof. That's quite a bit of engineering for a fairly obscure problem, though it would also help with labeling non-CPU profiles (#23458).
We don't have plans to fix this right now. This is just a tracking issue.
The text was updated successfully, but these errors were encountered: