Skip to main content

SamplingProfiler

Struct SamplingProfiler 

Source
pub struct SamplingProfiler {
    pub samples: Vec<ProfileSample>,
    pub enabled: bool,
    pub interval_ns: u64,
    pub current_stack: Vec<String>,
}
Expand description

A sampling-based profiler.

Fields§

§samples: Vec<ProfileSample>

Collected samples.

§enabled: bool

Whether sampling is enabled.

§interval_ns: u64

Configured sampling interval in nanoseconds.

§current_stack: Vec<String>

Current simulated call stack.

Implementations§

Source§

impl SamplingProfiler

Source

pub fn new(interval_ns: u64) -> Self

Create a new sampling profiler with the given interval.

Source

pub fn enable(&mut self)

Enable the profiler.

Source

pub fn disable(&mut self)

Disable the profiler.

Source

pub fn enter(&mut self, function: &str)

Simulate entering a function.

Source

pub fn leave(&mut self, function: &str)

Simulate leaving a function.

Source

pub fn take_sample(&mut self, thread_id: u64)

Take a sample of the current call stack.

Source

pub fn flat_profile(&self) -> Vec<(String, usize)>

Compute the flat profile: (function_name, hit_count) sorted by count.

Source

pub fn cumulative_profile(&self) -> Vec<(String, usize)>

Compute the cumulative profile: each function gets credit for every sample it appears in (at any depth).

Source

pub fn sample_count(&self) -> usize

Total number of samples collected.

Source

pub fn avg_stack_depth(&self) -> f64

Average call stack depth across all samples.

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