#performance #no-std

no-std embedded-profiling

Profiling for no-std embedded targets

13 releases

0.3.0 Dec 25, 2021
0.2.4 Dec 20, 2021
0.1.6 Nov 24, 2021
0.1.4 Oct 31, 2021

#2042 in Embedded development

Download history 17/week @ 2024-03-11 9/week @ 2024-03-18 7/week @ 2024-03-25 40/week @ 2024-04-01 9/week @ 2024-04-08 31/week @ 2024-04-15 20/week @ 2024-04-22 13/week @ 2024-05-06 7/week @ 2024-05-13 13/week @ 2024-05-20 15/week @ 2024-05-27 14/week @ 2024-06-03 12/week @ 2024-06-10 15/week @ 2024-06-17 20/week @ 2024-06-24

62 downloads per month
Used in 5 crates

MIT/Apache

23KB
302 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.

Alternatively, if you don't want to use the globally installed profiler or have the overhead of dyn trait objects, you can obviously use the trait methods directly on the struct that implements the trait.

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 & EmbeddedProfiler Implementations

A working example program on a feather_m4 development board is provided in the embedded-profiling github repo. These examples use some libraries implementing this trait, ep-systick, ep-dwt, and ep-pin-toggle.

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.57 and up. It might compile with older versions but that may change in any new patch release.

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

~160–375KB