Skip to main content

Profiler

Struct Profiler 

Source
pub struct Profiler { /* private fields */ }
Expand description

Main inference profiler.

Maintains a stack of completed ProfileTraces and an optional in-progress trace. Use Self::begin_trace / Self::end_trace to bracket an inference pass, and Self::profile (or the begin_event/end_event pair) to record individual operations.

Implementations§

Source§

impl Profiler

Source

pub fn new() -> Self

Create an enabled profiler.

Source

pub fn enabled(enabled: bool) -> Self

Create a profiler with an explicit enabled/disabled flag.

Source

pub fn is_enabled(&self) -> bool

Whether the profiler is currently recording events.

Source

pub fn begin_trace(&mut self)

Begin a new trace.

Any previous in-progress trace is discarded; call Self::end_trace first if you want to keep it.

Source

pub fn end_trace(&mut self) -> Option<ProfileTrace>

Finalise the current trace, push it to the completed list, and return a clone.

Returns None if no trace is in progress.

Source

pub fn begin_event(&mut self, _name: impl Into<String>) -> Instant

Record the start of an event and return the Instant.

Pair with Self::end_event.

Source

pub fn end_event( &mut self, name: impl Into<String>, start_time: Instant, flops: u64, )

Complete an event started at start_time and record it in the active trace (if any).

Source

pub fn profile<F, R>(&mut self, name: impl Into<String>, flops: u64, f: F) -> R
where F: FnOnce() -> R,

Time f, record the event as name with flops estimated FLOPs, and return whatever f returns.

When the profiler is disabled the closure is still executed; only recording is skipped.

Source

pub fn scoped<'a>(&'a mut self, name: impl Into<String>) -> ProfileGuard<'a>

Return a scoped guard that records an event when dropped.

This allows recording events that span a ?-early-return path without an explicit end_event call.

Source

pub fn traces(&self) -> &[ProfileTrace]

All completed traces (oldest first).

Source

pub fn last_trace(&self) -> Option<&ProfileTrace>

The most recently completed trace, if any.

Source

pub fn aggregate_stats(&self) -> AggregateStats

Aggregate statistics across all completed traces.

Trait Implementations§

Source§

impl Default for Profiler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,