-
Notifications
You must be signed in to change notification settings - Fork 937
Skip last 10% allocations for leak detection #1299
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
Conversation
@apangin At the same time using a static value like last minute could also lead to bad outcomes for short profiling sessions I think we should have both a base static ignore window & % ignore window We can define a base max ignore window of for example 10 seconds So for short profiling sessions we would use the % evaluation while for longer profiling sessions we would use the base max ignore window we define. |
On the other hand, profiler will collect useful allocation data for 54 minutes - that's a lot! The approach proposed in this PR is simple and efficient. There is no point in complicating it without obvious benefits. |
@apangin As a user, I'd want to have this behavior documented, and to have the tail size configurable |
@fandreuz I agree on the documentation point - will add a sentence. |
There is a use case to record all allocations, in case the process is short-running or if this is executed as part of a CI, to verify lack of leaks. We could make the tail feature optiona, opt-out perhaps. |
OK, made this configurable with |
Looks good to me |
Description
For native leak profiling, ignore allocations made in the last 10% of the profiling session.
Motivation and context
#1064 introduced the feature to create a flamegraph of native memory allocations. With
--leak
option, only those allocations are displayed that do not have matchingfree
calls - such allocations are considered memory leaks. However, this algorithm is biased towards allocations made closer to the end of the profiling session, because such allocations are more likely to be freed only after the session has ended.To avoid such a bias, it is proposed to simply ignore younger allocations. For example, if a profiling session runs for 10 minutes, allocations made during the last minute won't be included in the leak flamegraph.
How has this been tested?
Created an artificial memory leak by not closing
DirectoryStream
and ranBefore the change:

After the change:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.