ProfilerOptionsBuilder

Struct ProfilerOptionsBuilder 

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

Builder for ProfilerOptions.

Implementations§

Source§

impl ProfilerOptionsBuilder

Source

pub fn with_native_mem(self, native_mem_interval: String) -> Self

Same as ProfilerOptionsBuilder::with_native_mem_bytes, but pass the string input directly to async_profiler.

The value is the interval in bytes or in other units, if followed by k (kilobytes), m (megabytes), or g (gigabytes).

Prefer using ProfilerOptionsBuilder::with_native_mem_bytes, since it’s type-checked.

§Examples

This will sample allocations for every 10 megabytes allocated:

let opts = ProfilerOptionsBuilder::default().with_native_mem("10m".into()).build();
let profiler = ProfilerBuilder::default()
    .with_profiler_options(opts)
    .with_local_reporter("/tmp/profiles")
    .build();
profiler.spawn()?;
Source

pub fn with_native_mem_bytes(self, native_mem_interval: usize) -> Self

If set, the profiler will collect information about native memory allocations.

The argument passed is the profiling interval - the profiler will sample allocations every about that many bytes.

See ProfilingModes in the async-profiler docs for more details.

§Examples

This will sample allocations for every 10 megabytes allocated:

let opts = ProfilerOptionsBuilder::default().with_native_mem_bytes(10_000_000).build();
let profiler = ProfilerBuilder::default()
    .with_profiler_options(opts)
    .with_local_reporter("/tmp/profiles")
    .build();
profiler.spawn()?;

This will sample every allocation (potentially slow):

let opts = ProfilerOptionsBuilder::default().with_native_mem_bytes(0).build();
let profiler = ProfilerBuilder::default()
    .with_profiler_options(opts)
    .with_local_reporter("/tmp/profiles")
    .build();
profiler.spawn()?;
Source

pub fn with_cpu_interval(self, cpu_interval: Duration) -> Self

Sets the interval in which the profiler will collect CPU-time samples, via the async-profiler interval option.

CPU-time samples (JFR jdk.ExecutionSample) sample only threads that are currently running on a CPU, not threads that are sleeping.

It can use a higher frequency than wall-clock sampling since the number of the threads that are running on a CPU at a given time is naturally limited by the number of CPUs, while the number of sleeping threads can be much larger.

The default is to do a CPU-time sample every 100 milliseconds.

The async-profiler agent collects both CPU time and wall-clock time samples, so this function should normally be used along with ProfilerOptionsBuilder::with_wall_clock_interval.

§Examples

This will sample allocations for every 10 CPU milliseconds (when running) and 100 wall-clock milliseconds (running or sleeping):

let opts = ProfilerOptionsBuilder::default()
    .with_cpu_interval(Duration::from_millis(10))
    .with_wall_clock_interval(Duration::from_millis(100))
    .build();
let profiler = ProfilerBuilder::default()
    .with_profiler_options(opts)
    .with_local_reporter("/tmp/profiles")
    .build();
profiler.spawn()?;
Source

pub fn with_wall_clock_interval(self, wall_clock: Duration) -> Self

Sets the interval, in milliseconds, in which the profiler will collect wall-clock samples, via the async-profiler wall option.

Wall-clock samples (JFR profiler.WallClockSample) sample threads whether they are sleeping or running, and can therefore be very useful for finding threads that are blocked, for example on a synchronous lock or a slow system call.

When using Tokio, since tasks are not threads, tasks that are not currently running will not be sampled by a wall clock sample. However, a wall clock sample is still very useful in Tokio, since it is what you want to catch tasks that are blocking a thread by waiting on synchronous operations.

The default is to do a wall-clock sample every second.

The async-profiler agent collects both CPU time and wall-clock time samples, so this function should normally be used along with ProfilerOptionsBuilder::with_cpu_interval.

§Examples

This will sample allocations for every 10 CPU milliseconds (when running) and 100 wall-clock milliseconds (running or sleeping):

let opts = ProfilerOptionsBuilder::default()
    .with_cpu_interval(Duration::from_millis(10))
    .with_wall_clock_interval(Duration::from_millis(10))
    .build();
let profiler = ProfilerBuilder::default()
    .with_profiler_options(opts)
    .with_local_reporter("/tmp/profiles")
    .build();
profiler.spawn()?;
Source

pub fn build(self) -> ProfilerOptions

Build the ProfilerOptions from the builder.

Trait Implementations§

Source§

impl Debug for ProfilerOptionsBuilder

Source§

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

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

impl Default for ProfilerOptionsBuilder

Source§

fn default() -> ProfilerOptionsBuilder

Returns the “default value” for a type. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more