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

Provide a way to programmatically save memory heap snapshot in csv or other human readable format #247

Open
KimFromMarietta opened this issue Sep 19, 2024 · 4 comments

Comments

@KimFromMarietta
Copy link

I've been able to save heap snapshots from a running Flutter application to CSV within the devtools. I can also save a memory heap snapshot programmatically from my Flutter application with NativeRuntime.writeHeapSnapshotToFile.

How do I convert the saved heap snapshot to csv or other human readable form? I'd like to parse the saved snapshot instead of viewing it in the devtools UI. Thanks

@polina-c
Copy link
Contributor

polina-c commented Sep 28, 2024

Run DevTools not connected to the app (for example with VSCode > Flutter Side Panel > Icon "Open DevTools")
Open DevTools > Memory
Click arrow up button to import the snapshot
Save the snapshot as CSV.

Let me know if there are issues.

CC @kenzieschmoll

@KimFromMarietta
Copy link
Author

KimFromMarietta commented Oct 10, 2024

@polina-c , thank you very much for responding. I should have been clearer.

I understand how to manually upload the heap snapshot my flutter app saves to my device emulator with NativeRuntime.writeHeapSnapshotToFile and manually convert it to a CSV.

What I would like to find is a programmatic way in my flutter program or a separate dart script to just convert the heapsnapshot to a csv without the step to manually upload the heapsnapshot to flutter devtools and then manually save it as a csv.

My goal is to programmatically take a heap snapshot at different points in my flutter app and automatically compare the values to figure out which widgets are responsible for my memory leakage. Thanks

Or is there a better way you could suggest, please? Thanks

@polina-c
Copy link
Contributor

Thank you for clarifying.

You can create such a script.

Check source code of DevTools and copy the snippets from the Memory screen that are doing import of the snapshot. DevTools is doing a lot of calculations for the snapshot. May be you do not need them.

Then you can create your code to save it to CSV. Or, copy the one from DevTools.

Does it help?

@KimFromMarietta
Copy link
Author

This does help, @polina-c Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants