Trait EmbeddedProfiler

Source
pub trait EmbeddedProfiler {
    // Required method
    fn read_clock(&self) -> EPInstant;

    // Provided methods
    fn log_snapshot(&self, _snapshot: &EPSnapshot) { ... }
    fn at_start(&self) { ... }
    fn at_end(&self) { ... }
    fn start_snapshot(&self) -> EPInstant { ... }
    fn end_snapshot(
        &self,
        start: EPInstant,
        name: &'static str,
    ) -> Option<EPSnapshot> { ... }
}
Expand description

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.

Required Methods§

Source

fn read_clock(&self) -> EPInstant

Takes a reading from the clock.

Used by the underlying trait methods EmbeddedProfiler::start_snapshot and EmbeddedProfiler::end_snapshot.

Provided Methods§

Source

fn log_snapshot(&self, _snapshot: &EPSnapshot)

Optionally log the snapshot to some output, like a serial port.

Source

fn at_start(&self)

Optional function that gets called at the start of the snapshot recording.

If one would want to very simple profiling, they could use at_start and at_end to simply toggle a GPIO.

Source

fn at_end(&self)

Optional function that gets called at the end of the snapshot recording.

Source

fn start_snapshot(&self) -> EPInstant

takes the starting snapshot of a specific trace.

let start_time = my_profiler.start_snapshot();
function_to_profile();
if let Some(snapshot) = my_profiler.end_snapshot(start_time, "function_to_profile") {
    my_profiler.log_snapshot(&snapshot);
}
Source

fn end_snapshot( &self, start: EPInstant, name: &'static str, ) -> Option<EPSnapshot>

computes the duration of the snapshot given the start time, if there hasn’t been overflow.

Implementors§