Crate embedded_profiling

Source
Expand description

§Embedded-Profiling

A lightweight framework for profiling functions, geared towards no-std embedded environments. 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.

§Usage

You can manually start & end your snapshot:

let start = embedded_profiling::start_snapshot();
// (...) some expensive computation
if let Some(snapshot) = embedded_profiling::end_snapshot(start, "name-of-computation") {
    // Optionally, log it if we didn't overflow
    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 the set_profiler function.

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

§Features

§container-u64

Use a u64 as the time storage type instead of u32 for longer running profiling.

§proc-macros

enables the proc-macros feature in embedded-profiling. Enables the embedded_profiling::profile_function procedural macro.

Re-exports§

pub use fugit;

Structs§

EPSnapshot
A recorded snapshot.
SetProfilerError
Indicates that setting the profiler has gone awry, probably because the profiler has already been set.

Traits§

EmbeddedProfiler
The main trait to implement. All that is required is a way to read time and a way to output our results, if desired. You can also implement functions that get called when a snapshot starts and ends.

Functions§

convert_instant
Converts an instant of an unknown fraction NOM/DENOM to our microsecond representation.
end_snapshot
computes the duration of the snapshot given the start time using the globally configured profiler.
log_snapshot
Logs the given snapshot with the globally configured profiler.
profile
Profiles the given closure target with name name.
profiler
Returns a reference to the configured profiler.
set_profiler
Sets the global profiler.
start_snapshot
takes the starting snapshot of a specific trace.

Type Aliases§

EPContainer
The underlying container of our Duration/Instant types. Can be either u32 or u64, depending on features (default: u32).
EPDuration
Our Duration type, representing time elapsed in microseconds.
EPInstant
Our Instant type, representing a snapshot in time from a clock with 1 µs precision (or at least, converted to this representation).
EPInstantGeneric
An Instant type but with a generic fraction. This needs to be converted into EPInstant for use in the EmbeddedProfiler::read_clock function.

Attribute Macros§

profile_function
profiles the annotated function using embedded_profiling.