#performance #profiling #no-std

no-std embedded-profiling

Profiling for no-std embedded targets

7 releases

Uses new Rust 2021

0.1.6 Nov 24, 2021
0.1.5 Nov 1, 2021
0.1.4 Oct 31, 2021

#48 in Profiling

Download history 20/week @ 2021-10-25 68/week @ 2021-11-01 9/week @ 2021-11-08 6/week @ 2021-11-15 20/week @ 2021-11-22

123 downloads per month

MIT/Apache

17KB
231 lines

Embedded-Profiling

A lightweight framework for profiling functions, geared towards no-std embedded environments.

Documentation

Usage

Initialization is very similar to how the log crate is initialized. By default, there is a no-op profiler that does nothing until you call set_profiler. Once your profiler has been installed, your profiling functionality will be in use.

You can manually start & end your snapshot:

let start = embedded_profiling::start_snapshot();
// (...) some expensive computation
let snapshot = embedded_profiling::end_snapshot(start, "name-of-computation");
// Optionally, log it
embedded_profiling::log_snapshot(&snapshot);

Or profile some code in a closure:

embedded_profiling::profile("profile println", || {
    println!("profiling this closure");
});

With a Procedural Macro

With the proc-macros feature enabled, you can simply annotate the target function with the procedural macro profile_function. Note that you must first set your profiler with theset_profiler function.

#[embedded_profiling::profile_function]
fn my_long_running_function() {
    println!("Hello, world!");
}

Example Project & DWT Timer Implementation

A working example program on a feather_m4 development board is provided in the embedded-profiling github repo. The embedded-profiling library also provides a basic timer implementation using the DWT/systick functionality found in most Cortex-M microcontrollers. The implementation is heavily inspired (read: copied and lightly modified) from the RTIC dwt-systick-monotonic crate.

License

This code is licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~400–550KB