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

Make standalone heap tracing more usefull and easy to read and analyse (IDFGH-12836) #13803

Closed
masterxq opened this issue May 18, 2024 · 6 comments
Assignees
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Feature Request Feature request for IDF

Comments

@masterxq
Copy link

masterxq commented May 18, 2024

Is your feature request related to a problem?

tracing down memory leaks currently works like this:

heap_trace_start();
//Wait or try something
heap_trace_stop();
heap_trace_dump();

Now you will see a lot of allocated memory leaks that are false positive. And will be freed soon.

This can be avoided with a some small changes to heap trace api.

Describe the solution you'd like.

As already mentioned many of the false positive will be freed soon and we don't want to see them.

This can be solved if it is possible only to stop tracing malloc and continue tracing free. Then it would be possible to wait longer or restart some services. So many of the false positive leaks will now be freed and new mallocs will not be collected. Now we have a more relevant output of the dump.

heap_trace_start();
//Wait or try something
heap_trace_stop_tracing_malloc(); //Only stop tracing malloc, continue tracing free.
//Wait longer for frees or test some actions that could trigger free
heap_trace_stop();
heap_trace_dump();

Now we should have much less false positives...

The standard workflow would still work, and it should be easily possible without breaking changes.

Describe alternatives you've considered.

Even better would be if this workflow would also be possible, so we better know when or with which action stuff will be freed.

heap_trace_start();
//Wait or try something
heap_trace_stop_tracing_malloc(); //Only stop tracing malloc, continue tracing free.
//Wait longer or test some actions
while(trace_heap)
{
 if(button_pressed)
   heap_trace_dump(); //Don't know if it is currently possible to call dump before stop
}
heap_trace_stop();

Additional context.

I think this would help a lot to make good bug reports about memory leaks without complicated JTAG setup, what really can be hard to setup in products where the problem appears.

After all this could help to fix a lot of memory leaks, by helping users by helping.

I think espressif has a lot of good developer tests, but also a lot of bugs that only appears in production, and there it is hard to analyze for the users, and it is hard to define test cases for the espressif team. So it is important to make the tests that works without special equipment in production as good as possible. This allows users to make tests in the final environment.

Additionally, it would help the user to find leaks in user code. Without have tons of false positives from the framework that will be freed the next few seconds :)

Thanks for reading :)

@masterxq masterxq added the Type: Feature Request Feature request for IDF label May 18, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label May 18, 2024
@github-actions github-actions bot changed the title Make standalone heap tracing more usefull and easy to read and analyse Make standalone heap tracing more usefull and easy to read and analyse (IDFGH-12836) May 18, 2024
@SoucheSouche
Copy link
Collaborator

Hello @masterxq, thanks for submitting this feature request.

It is perfectly fine to use heap_caps_dump when the tracing is running.
Concerning the feature request, I will investigate it but it seems to make sense to be able to stop recording new allocations while continuing to record free calls.

I will keep you updated about the solution I will choose to implement.

@espressif-bot espressif-bot added Status: Reviewing Issue is being reviewed and removed Status: Opened Issue is new labels May 20, 2024
@chipweinberger
Copy link
Contributor

i agree it makes sense

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Reviewing Issue is being reviewed labels May 22, 2024
@SoucheSouche
Copy link
Collaborator

SoucheSouche commented May 22, 2024

Hi @masterxq,
I just merged the new feature locally. It will be available with next sync.
I just ended up adding a new function heap_trace_alloc_pause that will internally skip the allocations recording and follow through with the frees.

@masterxq
Copy link
Author

masterxq commented May 22, 2024

Very fast, very cool and very useful!

I will try to honor the work invested and give it a test by using the new feature as soon as possible to create a bug report that is as qualitative as possible for me.

Can it also be merged into 4.4.x?

Please remember to trigger an update of the documentation, so users have the chance to use it, a good espressif with few bugs is good for everybody ^^

Thank you!

@SoucheSouche
Copy link
Collaborator

@masterxq,
The documentation has been updated and will now list the new function next to heap_trace_start and heap_trace_stop
Since it is a new feature, it will not be backported.

espressif-bot pushed a commit that referenced this issue May 25, 2024
This commit adds a feature to pause the heap tracing in the
sense that in this state, the heap tracing will no longer
record the new allocations but will continue to monitor
the free() in order to keep track of the status of the
allocations present in the list of records.

See #13803
@masterxq
Copy link
Author

Understand, thank you very much!

Best Regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

4 participants