Skip to content
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

Open
aclements opened this issue Jan 13, 2021 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@aclements
Copy link
Member

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.

@aclements aclements added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jan 13, 2021
@aclements aclements added this to the Unplanned milestone Jan 13, 2021
@prattmic
Copy link
Member

prattmic commented Jan 13, 2021

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.

@gopherbot
Copy link

Change https://go.dev/cl/572396 mentions this issue: runtime/pprof: increase mem profile stack depth to 128

@felixge
Copy link
Contributor

felixge commented Mar 20, 2024

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.

2024-03-20 Continuous Profiler - Explorer  Datadog at 17 41 54@2x

(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.

@felixge
Copy link
Contributor

felixge commented Mar 20, 2024

cc @prattmic @mknyszek

@simonswine
Copy link

simonswine commented Apr 3, 2024

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 [truncated].

@moio
Copy link

moio commented Apr 10, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants