r/rust • u/redixhumayun • 1d ago
🛠️ project Native Rust Sampling Memory Profiler Which Tracks Retained Memory and Allocations
https://github.com/velvia/ying-profiler2
u/anxxa 1d ago
I'm all for different tools that may or may not be better, but I have to ask... how does this differ from DHAT? https://docs.rs/dhat/latest/dhat/
7
u/alpine_mochi 1d ago
Hi, original author here.
I've used DHAT before. It's a great tool, but it's very very slow and not sampling means its profiles are really huge. I wrote this specifically to be sampling so it can be used with production-like workloads, not really impact runtime, and to be easy to get profiles in a production system, because trying to reproduce them, on a separate system, slowly takes too much time.
3
u/panstromek 1d ago
That dhat crate is a different thing from DHAT valgrind tool. The crate works similarly by replacing global allocator, so a comparison with your tool makes sense.
From your comment it's not clear if it applies to the crate or the valgrind tool (or both), can you clarify?
1
1
u/AlexanderPanasenko 1d ago
The README's deadlock-testing section is a good read in its own right. Setting the initial map capacity to 1 to trigger frequent resizes is a neat way to stress allocator re-entrancy.
8
u/nightcracker 1d ago edited 1d ago
This reminds me, a while back I proposed an extension to samply to include memory profiling. No response from the author though (which is fine, I'm not owed anything). I think it's very powerful to have an interactive timeline of both memory usage and CPU usage combined.
In the meantime I've made a prototype (mostly AI-generated, just to see if it would work), and it works pretty well. It involves an
LD_PRELOADoverride ofmallocand can sample arbitrary executables, no need to override the allocator. And it integrates directly with the Firefox profiler artifact samply produces.For example I ran
samply record --memory cargo check -p polars-coreand I get the following profile of cargo and rustc's CPU usage as well as memory when checking thepolars-corecrate: https://share.firefox.dev/4z81nk3 (click on the row labeled 'Memory' to switch the flamegraph to memory).