pub struct ProfilerHandle { /* private fields */ }Expand description
A handle to the profiler registered against the current hook context.
The handle owns the entries signal; calling
ProfilerHandle::entries() returns that signal so any
reactive read (Signal::get()) inside a closure subscribes
the enclosing render to new entries. The matching
measurement API is ProfilerHandle::measure(label, f)
(push-on-exit) or ProfilerHandle::begin(label) /
ProfilerHandle::end() (split-timer API for code paths
that don’t fit inside a single closure).
§Lifecycle
The handle is obtained via App::use_profiler() (or
directly via HookContext::profiler()), which slots it into
the current hook context. On every render at the same hook
index, the same handle is returned — so measurements
recorded from a previous render remain visible in
entries().
On hook-context teardown (component unmount, match-arm
switch, or explicit clear()), the handle is dropped and
its entries signal goes with it. If you need to keep
measurements alive past the lifetime of the component,
clone the entries vector out before the context is cleared.
Implementations§
Source§impl ProfilerHandle
Inherent implementation of ProfilerHandle.
impl ProfilerHandle
Inherent implementation of ProfilerHandle.
Sourcepub fn new_with_empty_entries() -> Self
pub fn new_with_empty_entries() -> Self
Constructs a ProfilerHandle with an empty entries log.
Lombok New cannot derive this for us because the
entries field is a Signal<...> rather than a plain
value — we cannot synthesise a meaningful default at
compile time, so the hook-context factory wires one up at
runtime via Signal::create(Vec::new()).
§Returns
ProfilerHandle- A profiler handle with no recorded measurements.
Sourcepub fn measure<F, R>(&self, label: &str, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn measure<F, R>(&self, label: &str, f: F) -> Rwhere
F: FnOnce() -> R,
Records a fresh measurement around the given closure.
Captures the start timestamp, runs f, captures the
end timestamp, and pushes a ProfileEntry { label, elapsed_ms, timestamp_ms } into the entries signal.
The elapsed_ms is >= 0.0 by construction (start is
always captured before f runs).
§Arguments
&str- The label for this measurement.F: FnOnce() -> R- The closure to measure. Can return any type — the return value is forwarded to the caller unchanged.
§Returns
R- Whateverfreturned.
Sourcepub fn begin(&self, label: &str) -> ProfilerMark
pub fn begin(&self, label: &str) -> ProfilerMark
Starts a measurement that will end later.
Use this when the measured region is not a single
closure — e.g. you want to bracket an async operation
or a callback fired from event handling. The returned
ProfilerMark knows the start timestamp and the
entries signal; pass it to end() when the work
completes.
§Arguments
&str- The label for this measurement.
§Returns
ProfilerMark- An RAII-ish guard. Callmark.end()to push theProfileEntry; drop withoutend()to discard the measurement.
Source§impl ProfilerHandle
impl ProfilerHandle
pub fn get_entries(&self) -> &Signal<Vec<ProfileEntry>>
pub fn get_mut_entries(&mut self) -> &mut Signal<Vec<ProfileEntry>>
pub fn set_entries(&mut self, val: Signal<Vec<ProfileEntry>>) -> &mut Self
Source§impl ProfilerHandle
impl ProfilerHandle
pub fn new(entries: Signal<Vec<ProfileEntry>>) -> Self
Trait Implementations§
Source§impl Clone for ProfilerHandle
impl Clone for ProfilerHandle
Source§fn clone(&self) -> ProfilerHandle
fn clone(&self) -> ProfilerHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ProfilerHandle
ProfilerHandle is Copy because Signal<Vec<ProfileEntry>>
is itself Copy (the registry hands out cheap usize
addresses; the vector lives in the global signal store).