pub struct TimingAspect { /* private fields */ }Expand description
Timing aspect that measures function execution time and collects statistics.
§Example
ⓘ
use aspect_std::TimingAspect;
use aspect_macros::aspect;
let timing = TimingAspect::new();
#[aspect(timing.clone())]
fn expensive_operation() -> Result<(), String> {
std::thread::sleep(std::time::Duration::from_millis(100));
Ok(())
}
// Later, print statistics
timing.print_stats();Implementations§
Source§impl TimingAspect
impl TimingAspect
Sourcepub fn with_threshold(self, threshold_ms: u64) -> Self
pub fn with_threshold(self, threshold_ms: u64) -> Self
Set a threshold in milliseconds. Only log functions exceeding this duration.
Sourcepub fn print_on_complete(self) -> Self
pub fn print_on_complete(self) -> Self
Print timing after each function completes.
Sourcepub fn get_stats(&self, function_name: &str) -> Option<FunctionStats>
pub fn get_stats(&self, function_name: &str) -> Option<FunctionStats>
Get statistics for a specific function.
Sourcepub fn all_stats(&self) -> Vec<FunctionStats>
pub fn all_stats(&self) -> Vec<FunctionStats>
Get all function statistics.
Sourcepub fn print_stats(&self)
pub fn print_stats(&self)
Print statistics for all functions.
Trait Implementations§
Source§impl Aspect for TimingAspect
impl Aspect for TimingAspect
Source§fn around(
&self,
pjp: ProceedingJoinPoint<'_>,
) -> Result<Box<dyn Any>, AspectError>
fn around( &self, pjp: ProceedingJoinPoint<'_>, ) -> Result<Box<dyn Any>, AspectError>
Advice that wraps the entire target function execution. Read more
Source§fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
fn after(&self, _ctx: &JoinPoint, _result: &(dyn Any + 'static))
Advice executed after the target function completes successfully. Read more
Source§fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
fn after_error(&self, _ctx: &JoinPoint, _error: &AspectError)
Advice executed when the target function encounters an error. Read more
Source§impl Clone for TimingAspect
impl Clone for TimingAspect
Source§fn clone(&self) -> TimingAspect
fn clone(&self) -> TimingAspect
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TimingAspect
impl !RefUnwindSafe for TimingAspect
impl Send for TimingAspect
impl Sync for TimingAspect
impl Unpin for TimingAspect
impl UnsafeUnpin for TimingAspect
impl !UnwindSafe for TimingAspect
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
Mutably borrows from an owned value. Read more