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§
Sourcefn read_clock(&self) -> EPInstant
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§
Sourcefn log_snapshot(&self, _snapshot: &EPSnapshot)
fn log_snapshot(&self, _snapshot: &EPSnapshot)
Optionally log the snapshot to some output, like a serial port.
Sourcefn at_start(&self)
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.
Sourcefn start_snapshot(&self) -> EPInstant
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);
}Sourcefn end_snapshot(
&self,
start: EPInstant,
name: &'static str,
) -> Option<EPSnapshot>
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".