pub struct ProfilerOptionsBuilder { /* private fields */ }Expand description
Builder for ProfilerOptions.
Implementations§
Source§impl ProfilerOptionsBuilder
impl ProfilerOptionsBuilder
Sourcepub fn with_native_mem(self, native_mem_interval: String) -> Self
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()?;Sourcepub fn with_native_mem_bytes(self, native_mem_interval: usize) -> Self
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()?;Sourcepub fn with_cpu_interval(self, cpu_interval: Duration) -> Self
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()?;Sourcepub fn with_wall_clock_interval(self, wall_clock: Duration) -> Self
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()?;Sourcepub fn build(self) -> ProfilerOptions
pub fn build(self) -> ProfilerOptions
Build the ProfilerOptions from the builder.
Trait Implementations§
Source§impl Debug for ProfilerOptionsBuilder
impl Debug for ProfilerOptionsBuilder
Source§impl Default for ProfilerOptionsBuilder
impl Default for ProfilerOptionsBuilder
Source§fn default() -> ProfilerOptionsBuilder
fn default() -> ProfilerOptionsBuilder
Auto Trait Implementations§
impl Freeze for ProfilerOptionsBuilder
impl RefUnwindSafe for ProfilerOptionsBuilder
impl Send for ProfilerOptionsBuilder
impl Sync for ProfilerOptionsBuilder
impl Unpin for ProfilerOptionsBuilder
impl UnwindSafe for ProfilerOptionsBuilder
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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