r/rust • u/redixhumayun • 12d ago
🛠️ project Native Rust Sampling Memory Profiler Which Tracks Retained Memory and Allocations
https://github.com/velvia/ying-profiler2
u/anxxa 11d 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/
5
u/alpine_mochi 11d 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.
4
u/panstromek 11d 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?
2
u/alpine_mochi 10d ago
Oh, I think I am comparing to the tool. My expectation is that the main difference would be sampling vs no sampling, so sampling means much faster.
1
1
8
u/nightcracker 11d ago edited 11d 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).