Remix.run Logo
▲ lalitmaganti 2 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 2 hours ago | parent [-]

How does this work? Is it sampling the heap or tracking all allocations?

▲lalitmaganti 2 hours ago | parent [-]

It samples the heap via Poisson sampling (https://perfetto.dev/docs/design-docs/heapprofd-sampling) so that large allocations are certain to be sampled and small allocations are more likely to be dropped.

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 2 hours ago | parent [-]

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.