In my experience trying to track down memory leaks in Android is kind of difficult since I couldn't find a good tool that would record all allocation traffic. There's stuff that will capture a Java heap snapshot, some things will interpose malloc and free, but there's not really a one-stop thing that does both that I could find. The best option I could see was the profiler in Android Studio, which was super buggy and had very few correlation features :(
lalitmaganti 1 hours ago [-]
While this article is focused on the Java heap dump side of Perfetto, we do support both native and Java heap dumps in a single trace.
Recently we've also been investing into a new feature of the UI called Memscope (https://perfetto.dev/docs/visualization/memscope) to put this behind a one-click graphical interface which hides all the complex configuration options of Perfetto and "just works" collecting both Java heap dumps and native heap profiling.
On the analysis side, we then time align them and present it with a new exploration UI. This is still under very active development so it should continue getting better with time :)
saagarjha 1 hours ago [-]
How does this work? Is it sampling the heap or tracking all allocations?
If you do play around with the config directly, you can actually configure a "track all allocaitons" mode but in practice this is not super useful: either you end up slowing the device to a complete crawl or you drop lots of data as you just cannot keep up. [1]
In practice, we've found a sampling of 4096 (the default) to provide a very good tradeoff between accuracy and performance.
[1] The option is called `sampling_interval_bytes` and, as the documentation describes (https://perfetto.dev/docs/reference/trace-config-proto#Heapp...), setting it to `1` means perfect accuracy. You usually will also want `block_client` so that the data isn't dropped (but as noted there it slows down the device a lot).
saagarjha 1 hours ago [-]
Ah, neat, I will play around with this! I am generally ok with Poisson sampling but there are some cases where I'm trying to correlate specific allocations to each other (for example, a code path where I am trying to check that it does in fact make exactly n of a certain object) where I am ok with running things slower, so I'll try this to see if it can help.
izacus 24 minutes ago [-]
The tool mentioned in the article - Perfetto - does have heap allocation profiling capability.
It can be done in background/from CLI as well.
cute_boi 2 hours ago [-]
Duh!
I got excited, only to get angry after reading the first paragraph. If you want me to invest my time and read it, please make sure you write it yourself and not generally everything using AI. I’m not against AI, but articles like these make my blood boil.
Rendered at 18:02:09 GMT+0000 (UTC) with Wasmer Edge.
Recently we've also been investing into a new feature of the UI called Memscope (https://perfetto.dev/docs/visualization/memscope) to put this behind a one-click graphical interface which hides all the complex configuration options of Perfetto and "just works" collecting both Java heap dumps and native heap profiling.
On the analysis side, we then time align them and present it with a new exploration UI. This is still under very active development so it should continue getting better with time :)
If you do play around with the config directly, you can actually configure a "track all allocaitons" mode but in practice this is not super useful: either you end up slowing the device to a complete crawl or you drop lots of data as you just cannot keep up. [1]
In practice, we've found a sampling of 4096 (the default) to provide a very good tradeoff between accuracy and performance.
[1] The option is called `sampling_interval_bytes` and, as the documentation describes (https://perfetto.dev/docs/reference/trace-config-proto#Heapp...), setting it to `1` means perfect accuracy. You usually will also want `block_client` so that the data isn't dropped (but as noted there it slows down the device a lot).
It can be done in background/from CLI as well.
I got excited, only to get angry after reading the first paragraph. If you want me to invest my time and read it, please make sure you write it yourself and not generally everything using AI. I’m not against AI, but articles like these make my blood boil.