Skip to main content

YingProfiler

Struct YingProfiler 

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

Ying is a memory profiling Allocator wrapper. Ying is the Chinese word for an eagle.

Implementations§

Source§

impl YingProfiler

Source

pub const fn new(sampling_ratio: u32, single_alloc_limit: usize) -> Self

sampling_ratio: number of allocations for every sampled allocation

Source

pub const fn default() -> Self

Source

pub fn start_profiling(&'static self) -> ProfilerRunner

Starts periodic memory reporting on a background thread and returns the ProfilerRunner that was spawned. This is the one-line way to turn Ying on:

    use ying_profiler::YingProfiler;

    #[global_allocator]
    static YING_ALLOC: YingProfiler = YingProfiler::default();

    fn main() {
        YING_ALLOC.start_profiling();
    }

This is a convenience only, and adds no capability of its own: it builds a ProfilerRunner with a fixed set of values and calls ProfilerRunner::spawn. Those values are a 5 minute DEFAULT_CHECK_INTERVAL_SECS check interval, a 10% DEFAULT_PCT_CHANGE_TRIGGER change before a report is written, output to DEFAULT_REPORTING_PATH (created if it does not exist), flamegraphs on, retained rather than allocated memory, and inlined frames left unexpanded.

To change any of those, build the ProfilerRunner yourself with ProfilerRunnerBuilder and call spawn on it instead. The returned runner records the settings in use, but the reporting thread has already been started with them; changing the returned value has no effect.

Source

pub fn total_retained_bytes() -> usize

Total outstanding retained bytes (not just sampled but all allocations)

Source

pub fn profiled_bytes_allocated() -> usize

Total bytes allocated for profiled allocations

Source

pub fn profiled_bytes_retained() -> usize

Profiled bytes retained - retained memory usage amongst profiled allocations

Source

pub fn symbol_map_size(&self) -> usize

Source

pub fn num_outstanding_allocs(&self) -> usize

Number of entries for outstanding sampled allocations map

Source

pub fn num_stack_traces(&self) -> usize

Number of distinct stack traces that have been sampled

Source

pub fn top_k_stacks_by_allocated(&self, k: usize) -> Vec<StackStats>

Get the top k stack traces by total profiled bytes allocated, in descending order. Note that “profiled bytes” refers to the bytes allocated during sampling by this profiler.

Source

pub fn top_k_stacks_by_retained(&self, k: usize) -> Vec<StackStats>

Get the top k stack traces by retained sampled memory, in descending order.

Source

pub fn reset_state_for_testing_only(&self)

Source

pub fn testing_only_guarantee_next_sample(&self)

Trait Implementations§

Source§

impl GlobalAlloc for YingProfiler

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates memory as described by the given layout. Read more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocates the block of memory at the given ptr pointer with the given layout. Read more
Source§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more
1.28.0 · Source§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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.