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
impl Profiler
Sourcepub fn enabled(enabled: bool) -> Self
pub fn enabled(enabled: bool) -> Self
Create a profiler with an explicit enabled/disabled flag.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether the profiler is currently recording events.
Sourcepub fn begin_trace(&mut self)
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.
Sourcepub fn end_trace(&mut self) -> Option<ProfileTrace>
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.
Sourcepub fn begin_event(&mut self, _name: impl Into<String>) -> Instant
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.
Sourcepub fn end_event(
&mut self,
name: impl Into<String>,
start_time: Instant,
flops: u64,
)
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).
Sourcepub fn profile<F, R>(&mut self, name: impl Into<String>, flops: u64, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn profile<F, R>(&mut self, name: impl Into<String>, flops: u64, f: F) -> Rwhere
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.
Sourcepub fn scoped<'a>(&'a mut self, name: impl Into<String>) -> ProfileGuard<'a>
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.
Sourcepub fn traces(&self) -> &[ProfileTrace]
pub fn traces(&self) -> &[ProfileTrace]
All completed traces (oldest first).
Sourcepub fn last_trace(&self) -> Option<&ProfileTrace>
pub fn last_trace(&self) -> Option<&ProfileTrace>
The most recently completed trace, if any.
Sourcepub fn aggregate_stats(&self) -> AggregateStats
pub fn aggregate_stats(&self) -> AggregateStats
Aggregate statistics across all completed traces.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Profiler
impl RefUnwindSafe for Profiler
impl Send for Profiler
impl Sync for Profiler
impl Unpin for Profiler
impl UnsafeUnpin for Profiler
impl UnwindSafe for Profiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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