- Make sure your rust application uses https://github.com/gnzlbg/jemallocator as the global memory allocator (when in doubt, grep
jemallocatorin yourCargo.lock). - Install
jemalloc(we'll only needjeprof),dot,ps2pdfandlibunwindon your system. Enable jemallocator'sprofilingfeature (ifjemallocatoris an indirect dependency, one trick to do is to add a dependencyjemallocator = { version = "*", features = ["profiling"] }to your app and let cargo select the||of features for you). export _RJEM_MALLOC_CONF=prof:true,lg_prof_interval:32,lg_prof_sample:19.lg_prof_intervalsets how often profile dump should be written to disk measured in allocated bytes. The value is passed as a power of two, which is 2^32 in our case, i.e. every 4 GiB of allocations of long-lived objects (see https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Heap-Profiling).lg_prof_sample:19tells jemalloc to take a profiling sample every 2^19 = 512 KiB.- Running your binary should produce a bunch of
jeprof.*.heapfiles (depending on your_RJEM_MALLOC_CONF). - To produce a PDF output, run
jeprof --show_bytes --pdf "/path/to/<binary>" jeprof.*.heap > <binary>.pdf, where<binary>is the binary you are profiling, e.g.jeprof --show_bytes --pdf `which ripgrep` jeprof.2805.204.i204.heap > ripgrep.pdf. You probably want to select the latestjeprof.*.heapfile, see http://jemalloc.net/mailman/jemalloc-discuss/2015-November/001205.html.
Last active
July 30, 2025 12:54
-
-
Save ordian/928dc2bd45022cddd547528f64db9174 to your computer and use it in GitHub Desktop.
HOWTO: heap profiling with jemallocator
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually: run jeprof on the same system that the binary is running on (i.e. where the dump files are generated)