koute / bytehound

A memory profiler for Linux.
Other
4.49k stars 193 forks source link

A kingdom for a flamegraph of live allocations! #86

Closed matklad closed 2 years ago

matklad commented 2 years ago

I am profiling an application which uses obscene amounts of memory, but is not, strictly speaking, leaking memory: if I kill the app, everything is cleanly deallocated.

Still, I'd love to know what takes all the memory. I think what I need is to take a look at the live allocations at some specific point in time, and get a famegraph. This'll give me essentially a profile for a heap snapshot at a point in time.

Can I already get this with bytehound? I've seen flamegraph for leaked memory, and the graph of the total live allocations, but neither is quite what I am looking for.

matklad commented 2 years ago

A hack to get what I want using what I have: add std::process::abort() to turn live into leaked

koute commented 2 years ago

Yes you can.

You can probably either: a) on the overview page zoom into the region which excludes the end part (left click and hold; double click to reset if you made a mistake), right click and open the allocations from that range, and then from the filter in the lifetime tab select "Only not deallocated in current time range", b) use this scripting method either as a custom filter or in the scripting console, e.g. allocations().only_not_deallocated_until_at_most(data().runtime() * 0.98) which will give you a list of all of the allocations which were not deallocated within the 98% of the total program runtime.

matklad commented 2 years ago

Awesome, this works! The only thing I was missing is the actual flamegraph, which is over here:

image

Consider surfacing this in UI as "flamegraph of live allocations" context-menu entry on a right click in the overview

matklad commented 2 years ago

Looking somewhat more carefully, this doesn't quite work, but seems easy to fix https://github.com/koute/bytehound/pull/88

koute commented 2 years ago

With the version on master you can now right click on the graph and select "Allocations: alive here" to get a list of all of the allocations alive at a given point in time.

matklad commented 2 years ago

Works like a charm, many thanks!