ProfilerBuilder

Struct ProfilerBuilder 

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

Builds a Profiler, panicking if any required fields were not set by the time build is called.

Implementations§

Source§

impl ProfilerBuilder

Source

pub fn with_reporting_interval(self, i: Duration) -> ProfilerBuilder

Sets the reporting interval (default: 30 seconds).

This is the interval that samples are reported to the backend, and is unrelated to the interval at which the application is sampled by async profiler, which is controlled by ProfilerOptionsBuilder::with_cpu_interval and ProfilerOptionsBuilder::with_wall_clock_interval.

Most users should not change this setting.

§Example
let agent = ProfilerBuilder::default()
    .with_local_reporter(path)
    .with_reporting_interval(Duration::from_secs(15))
    .build()
    .spawn()?;
Source

pub fn with_reporter( self, r: impl Reporter + Send + Sync + 'static, ) -> ProfilerBuilder

Sets the Reporter, which is used to upload the collected profiling data. Common reporters are LocalReporter, and, with the s3-no-defaults feature enabled, S3Reporter. It is also possible to write your own Reporter.

It’s normally easier to use LocalReporter directly via ProfilerBuilder::with_local_reporter.

If you want to output to multiple reporters, you can use MultiReporter.

§Example
let bucket_owner = "<your account id>";
let bucket_name = "<your bucket name>";
let profiling_group = "a-name-to-give-the-uploaded-data";
let sdk_config = aws_config::defaults(BehaviorVersion::latest()).load().await;
let agent = ProfilerBuilder::default()
    .with_reporter(S3Reporter::new(S3ReporterConfig {
        sdk_config: &sdk_config,
        bucket_owner: bucket_owner.into(),
        bucket_name: bucket_name.into(),
        profiling_group_name: profiling_group.into(),
    }))
    .build()
    .spawn()?;
Source

pub fn with_local_reporter(self, path: impl Into<PathBuf>) -> ProfilerBuilder

Sets the profiler to ues LocalReporter, which will write .jfr files to path, and disables metadata auto-detection (see ProfilerBuilder::with_custom_agent_metadata) since the LocalReporter does not need that.

This is useful for testing, since metadata auto-detection currently only works on Amazon EC2 or Amazon Fargate instances.

The local reporter should normally not be used in production, since it will not clean up JFR files. Instead, you can use a pre-existing Reporter or write your own (see ProfilerBuilder::with_reporter).

§Example

This will write profiles as .jfr files to ./path-to-profiles:

let path = PathBuf::from("./path-to-profiles");
let agent = ProfilerBuilder::default()
    .with_local_reporter(path)
    .build()
    .spawn()?;
Source

pub fn with_custom_agent_metadata(self, j: AgentMetadata) -> ProfilerBuilder

Provide custom agent metadata.

The async-profiler Rust agent sends metadata to the Reporter with the identity of the current host and process, which is normally transmitted as metadata.json within the generated .zip file, using the schema format reporter::s3::MetadataJson.

That metadata can later be used by tooling to be able to sort profiling reports by host.

async-profiler Rust agent will by default try to fetch the metadata using IMDS when running on Amazon EC2 or Amazon Fargate, and will error if it’s unable to find it. If you are running the async-profiler agent on any other form of compute, you will need to create and attach your own metadata by calling this function.

Source

pub fn with_profiler_options(self, c: ProfilerOptions) -> ProfilerBuilder

Provide custom profiler options.

§Example

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 build(self) -> Profiler

Turn this builder into a profiler!

Trait Implementations§

Source§

impl Debug for ProfilerBuilder

Source§

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

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

impl Default for ProfilerBuilder

Source§

fn default() -> ProfilerBuilder

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