#valgrind #callgrind #api-bindings #helgrind #cachegrind #massif

crabgrind

Rust bindings to "Valgrind Client Request" interface

3 releases

Uses old Rust 2015

0.1.10 Nov 1, 2023
0.1.9 Mar 26, 2023
0.1.8 Dec 14, 2022

#64 in Profiling

Download history 40/week @ 2023-12-13 17/week @ 2023-12-20 53/week @ 2024-01-03 493/week @ 2024-01-10 20/week @ 2024-01-17 14/week @ 2024-01-24 7/week @ 2024-01-31 20/week @ 2024-02-07 27/week @ 2024-02-14 59/week @ 2024-02-21 81/week @ 2024-02-28 75/week @ 2024-03-06 102/week @ 2024-03-13 62/week @ 2024-03-20 38/week @ 2024-03-27

290 downloads per month
Used in 3 crates (2 directly)

MIT license

60KB
742 lines

crabgrind

Valgrind Client Request interface for Rust programs

crates.io libs.rs documentation license

crabgrind allows Rust programs running under Valgrind to interact with the tools and virtualized environment.

Valgrind's "client request interface" is primarily accessible through a set of C macros in Valgrind's header files. However, these macros cannot be utilized in languages that lack support for C-preprocessor, such as Rust. To address this, crabgrind wraps "client request interface" macros with C functions and expose this API to Rust programs.

This library is essentially a wrapper. It only adds type conversions and some structure, while all the real things happens inside Valgrind.

Table of Contents

Valgrind 3 API coverage

Quickstart

crabgrind does not link against Valgrind but instead reads its header files, which must be accessible during build.

If you have installed Vallgrind using OS-specific package manager, the paths to the headers are likely to be resolved automatically by cc.

In case of manual installation or any missing file error, you can set the path to the Valgrind headers location through the DEP_VALGRIND environment variable. For example:

DEP_VALGRIND=/usr/include cargo build

add dependency Cargo.toml

[dependencies]
crabgrind = "0.1"

use some of the Valgrind's API

use crabgrind as cg;

fn main() {
    if matches!(cg::run_mode(), cg::RunMode::Native) {
        println!("run me under Valgrind");
    } else {
        cg::println!("Hey, Valgrind!");
    }
}

and run under Valgrind,

using cargo-valgrind:

cargo valgrind run

manually:

cargo build

valgrind ./target/debug/appname

Examples

Overhead

from Valgrind docs

The code added to your binary has negligible performance impact: on x86, amd64, ppc32, ppc64 and ARM, the overhead is 6 simple integer instructions and is probably undetectable except in tight loops.

... the code does nothing when not run on Valgrind, so you are not forced to run your program under Valgrind just because you use the macros in this file.

Although your loops should be very tight (like a well-executed dance move) to notice any impact, keep in mind that:

  • Wrapping each macros in a function implies function call overhead regardless of the run mode. This can potentially impact the performance of your Rust program.
  • Functions that return std::result::Result involve branching, which can also have an impact on performance.
  • Functions that take strings as parameters internally convert them to std::ffi::CString, which can introduce additional overhead.

Safety

No

License

crabgrind is distributed under MIT license.

Valgrind itself is a GPL2, however valgrind/*.h headers are distributed under a BSD-style license, so we can use them without worrying about license conflicts.

No runtime deps

~180KB