Skip to main content

ProfilerHandle

Struct ProfilerHandle 

Source
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.

Source

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.
Source

pub fn measure<F, R>(&self, label: &str, f: F) -> R
where 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 - Whatever f returned.
Source

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. Call mark.end() to push the ProfileEntry; drop without end() to discard the measurement.
Source

pub fn clear(&self)

Empties the entries vector. Useful between benchmarks (“measure just this call, not the previous ones too”) and in tests (“start from a clean slate”).

Source§

impl ProfilerHandle

Source

pub fn get_entries(&self) -> &Signal<Vec<ProfileEntry>>

Source

pub fn get_mut_entries(&mut self) -> &mut Signal<Vec<ProfileEntry>>

Source

pub fn set_entries(&mut self, val: Signal<Vec<ProfileEntry>>) -> &mut Self

Source§

impl ProfilerHandle

Source

pub fn new(entries: Signal<Vec<ProfileEntry>>) -> Self

Trait Implementations§

Source§

impl Clone for ProfilerHandle

Source§

fn clone(&self) -> ProfilerHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl 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).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more