Malloc frequency profiler

Overview

Rust

Malloc frequency profiler

This malloc frequency profiler helps detect program hotspots that perform a large number of memory allocations. Many small allocations can slow down your application and lead to memory fragmentation. Typical symptoms include seeing malloc at the top of the application's CPU profile, as well as observing that the resident set size (RSS) of the appliciation significantly exceeds the amount of memory it allocates from the heap.

Note: malloc_freq is different from heap profilers like valgrind's massif, which track program's heap usage at any give point in time, in two ways. First, heap profilers ignore short-lived allocations that do not affect the heap size significantly. Second, heap profilers track the amount of allocated memory, whereas malloc_freq focuses on the number of calls to malloc.

malloc_freq can be used to profile programs in Rust or any other compiled language.

Enabling malloc_freq in a Rust program

To enable malloc_freq in a Rust program, configure it as a global allocator instead of [std::alloc::System]:

use malloc_freq::ProfAllocator;

#[global_allocator]
static GLOBAL: ProfAllocator = ProfAllocator;

fn main() {}

Using malloc_freq via LD_PRELOAD

For programs in other languages, including a mix of Rust, C, etc., use the companion [lib_malloc_freq] crate, which produces a dynamic library that can be used via LD_PRELOAD to intercept all malloc calls issued by the program:

LD_PRELOAD=libmalloc_freq.so ./my_program

Viewing malloc_freq profiles

Upon successful program termination, malloc_freq stores the malloc profile in the malloc_freq. directory. The directory will contain a file for each thread in the program. To view the profile, use the mf_print tool from this crate, e.g.:

mf_print --dir malloc_freq.<pid> --threshold 0.2

where the --threshold switch specifies the significance threshold of profile entries in percents (profile entries with fewer than threshold% malloc calls are skipped in the output). mf_print outputs a human-readable profile that lists program callstacks that perform malloc calls, annotated with the number of malloc calls and the total number of bytes allocated by each stack trace.

Installation

To install the mf_print executable:

cargo install malloc_freq

To use malloc_freq in your Rust program via the global_allocator attribute, simply include it as a dependency in your Cargo.toml:

[dependencies]
malloc_freq = "0.1"

To use malloc_freq via LD_PRELOAD, you will need to download and build this repository:

git clone [email protected]:ryzhyk/malloc_freq.git
cd malloc_freq
cargo build --release --all

Use the compiled target/release/libmalloc_freq.so library with LD_PRELOAD, as described above.

TODOs

  • Generate profile on abnormal program termination (e.g., panic or SIGKILL).

  • Subsampling for lower overhead. malloc_freq can slow down the target program significantly, as it currently intercepts all malloc calls and records their stack traces int he profile.

You might also like...
Library to calculate TF-IDF (Term Frequency - Inverse Document Frequency) for generic documents.

Library to calculate TF-IDF (Term Frequency - Inverse Document Frequency) for generic documents. The library provides strategies to act on objects that implement certain document traits (NaiveDocument, ProcessedDocument, ExpandableDocument).

memory-profiler — A memory profiler for Linux
memory-profiler — A memory profiler for Linux

A memory profiler for Linux Features Can be used to analyze memory leaks, see where exactly the memory is being consumed, identify temporary allocatio

Implementation of malloc, realloc, calloc, and free in Rust.
Implementation of malloc, realloc, calloc, and free in Rust.

malloc-rs Implementation of malloc, realloc, calloc, and free in Rust. Note: No thread safe Architecture 512 bytes or less is allocated by Segregated

messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code.
messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code.

messloc is a drop in replacement for malloc that can transparently recover from memory fragmentation without any changes to application code. Goals Al

Arduino Nano frequency counter with atomic clock accuracy
Arduino Nano frequency counter with atomic clock accuracy

Arduino Nano frequency counter with atomic clock accuracy Project description and test setup With this project you can measure a frequency from less t

VST2 frequency modulation synthesizer written in Rust
VST2 frequency modulation synthesizer written in Rust

OctaSine VST2 frequency modulation synthesizer written in Rust. Official website with downloads OctaSine.com Audio examples SoundCloud Screenshots Lig

Sample and plot power consumption, average frequency and cpu die temperatures over time.
Sample and plot power consumption, average frequency and cpu die temperatures over time.

sense Sense is a small tool to gather data on cpu temperature, power usage and clock frequency and plot graphs during some load. Dependencies Sense is

Site frequency spectrum estimation based on window expectation-maximisation algorithm

winsfs winsfs is a tool for inference of the site frequency spectrum ("SFS"). Quickstart Assuming SAF files have already been made, default estimation

MO's Trading - an online contest for high frequency trading

MO's Trading - an online contest for high frequency trading

Rate limit guard - Lazy rate limit semaphore implementation to control your asynchronous code frequency execution

Lazy rate limit semaphore (a.k.a fixed window algorithm without queueing) implementation to control your asynchronous code frequency execution

The frequency-perfect synthesizer for a PC-speaker

🎵 BeeSynth Project The frequency-perfect synthesizer for a PC speaker ✔️ Features Written in Rust 🦀 Support playing MP3, WAV, FLAC, tracker music an

Simple profiler scopes for wgpu using timer queries

wgpu-profiler Simple profiler scopes for wgpu using timer queries Features Easy to use profiler scopes Allows nesting! Can be disabled by runtime flag

Show puffin profiler flamegraph in-game using egui

Show puffin profiler flamegraph in-game using egui puffin is an instrumentation profiler where you opt-in to profile parts of your code: fn my_functio

A tracing profiler for the Sega MegaDrive/Genesis
A tracing profiler for the Sega MegaDrive/Genesis

md-profiler, a tracing profiler for the Sega MegaDrive/Genesis This program, meant to be used with this fork of BlastEm, helps you finding bottlenecks

Simple timings profiler

profl Simple timings profiler Example fn main() - std::io::Result() { profl::init("timings.data"); let mut total = 0; for i in 0..1000

Py-spy - Sampling profiler for Python programs
Py-spy - Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

🐦 Friendly little instrumentation profiler for Rust 🦀
🐦 Friendly little instrumentation profiler for Rust 🦀

🐦 puffin The friendly little instrumentation profiler for Rust How to use fn my_function() { puffin::profile_function!(); ... if ... {

Twiggy🌱 is a code size profiler
Twiggy🌱 is a code size profiler

Twiggy 🌱 A code size profiler for Wasm Guide | Contributing | Chat Built with 🦀 🕸 by The Rust and WebAssembly Working Group About Twiggy is a code

The axiom profiler for exploring and visualizing SMT solver quantifier instantiations (made via E-matching).

Axiom Profiler A tool for visualising, analysing and understanding quantifier instantiations made via E-matching in a run of an SMT solver (at present

Owner
Leonid Ryzhyk
Leonid Ryzhyk
Arduino Nano frequency counter with atomic clock accuracy

Arduino Nano frequency counter with atomic clock accuracy Project description and test setup With this project you can measure a frequency from less t

Frank Buss 24 Apr 3, 2022
Rate limit guard - Lazy rate limit semaphore implementation to control your asynchronous code frequency execution

Lazy rate limit semaphore (a.k.a fixed window algorithm without queueing) implementation to control your asynchronous code frequency execution

Yan Kurbatov 4 Aug 1, 2022
A tracing profiler for the Sega MegaDrive/Genesis

md-profiler, a tracing profiler for the Sega MegaDrive/Genesis This program, meant to be used with this fork of BlastEm, helps you finding bottlenecks

null 15 Nov 3, 2022
Simple timings profiler

profl Simple timings profiler Example fn main() -> std::io::Result<()> { profl::init("timings.data"); let mut total = 0; for i in 0..1000

Broxus 1 Dec 9, 2021
Py-spy - Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

Ben Frederickson 9.5k Jan 8, 2023
🐦 Friendly little instrumentation profiler for Rust 🦀

?? puffin The friendly little instrumentation profiler for Rust How to use fn my_function() { puffin::profile_function!(); ... if ... {

Embark 848 Dec 29, 2022
The axiom profiler for exploring and visualizing SMT solver quantifier instantiations (made via E-matching).

Axiom Profiler A tool for visualising, analysing and understanding quantifier instantiations made via E-matching in a run of an SMT solver (at present

Viper Project 18 Oct 18, 2022
A memory profiler for Linux.

Bytehound - a memory profiler for Linux Features Can be used to analyze memory leaks, see where exactly the memory is being consumed, identify tempora

Koute 3.3k Dec 25, 2022
Sampling profiler and tracer for Ruby (CRuby) which runs in BPF

rbperf rbperf is a low-overhead sampling profiler and tracer for Ruby (CRuby) which runs in BPF Build To build rbperf you would need a Linux machine w

Javier Honduvilla Coto 75 Dec 19, 2022
🐝🦀🔥 An ebpf based CPU profiler written in Rust

profile-bee ?? ?? ?? Profile Bee is an eBPF based CPU profiler written in Rust for performance and efficiency. Aya is used for building the BPF progra

Joshua Koo 5 Dec 16, 2022