Skip to main content

ProfilerRunner

Struct ProfilerRunner 

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

A background thread that dumps out stats, flamegraphs, and does other periodic cleanup.

  1. Dumps out top retained memory stats to both logs and disk
  2. Can optionally dump out flamegraphs
  3. Lets you choose between dumping retained or allocated reports/flamegraphs

The runner thread will check the amount of retained memory as estimated by this profiler, every check_interval_secs. If the retained memory changes from the previous time by more than report_pct_change_trigger, then it will dump out a memory report of the top either retained or allocated stack traces as a file to the chosen reporting_path directory on disk. The file will have the ISO8601 timestamp and the amount of retained memory in the filename for convenience. Optionally, a flamegraph will also be dumped.

Note that ProfilerRunner uses log framework to periodically dump out logs. The app is responsible for initializing the logging infrastructure.

To run. no_run because spawning the reporting thread and creating its output directory are side effects that do not belong in a doctest:

    use ying_profiler::{YingProfiler, utils::ProfilerRunner};
    static YING_ALLOC: YingProfiler = YingProfiler::default();
    ProfilerRunner::default().spawn(&YING_ALLOC);

Builder pattern can also be used.

    use ying_profiler::{YingProfiler, utils::ProfilerRunnerBuilder};
    static YING_ALLOC: YingProfiler = YingProfiler::default();
    let runner = ProfilerRunnerBuilder::default()
        .check_interval_secs(60usize)
        .gen_flamegraphs(true)
        .reporting_path("profiler_output/")
        .build()
        .unwrap();
     runner.spawn(&YING_ALLOC);

Implementations§

Source§

impl ProfilerRunner

Source

pub fn new( check_interval_secs: usize, report_pct_change_trigger: usize, reporting_path: &str, expand_frames: bool, gen_flamegraphs: bool, measure_allocated_not_retained: bool, ) -> Self

Creates a new ProfilerRunner with specific parameters

Source

pub fn spawn(&self, profiler: &'static YingProfiler)

Spawn a new background thread to run profiler and get stats. Creates reporting_path if it does not already exist.

Trait Implementations§

Source§

impl Clone for ProfilerRunner

Source§

fn clone(&self) -> ProfilerRunner

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProfilerRunner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProfilerRunner

Creates a new ProfilerRunner with default values. Writes reports to current directory, does not expand frames, every 5 minute checks on memory, 10% change triggers report. No flamegraphs, retained memory.

Source§

fn default() -> Self

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

impl PartialEq for ProfilerRunner

Source§

fn eq(&self, other: &ProfilerRunner) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ProfilerRunner

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.