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
impl ProfilerBuilder
Sourcepub fn with_reporting_interval(self, i: Duration) -> ProfilerBuilder
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()?;Sourcepub fn with_reporter(
self,
r: impl Reporter + Send + Sync + 'static,
) -> ProfilerBuilder
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()?;Sourcepub fn with_local_reporter(self, path: impl Into<PathBuf>) -> ProfilerBuilder
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()?;Sourcepub fn with_custom_agent_metadata(self, j: AgentMetadata) -> ProfilerBuilder
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.
Sourcepub fn with_profiler_options(self, c: ProfilerOptions) -> ProfilerBuilder
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()?;Trait Implementations§
Source§impl Debug for ProfilerBuilder
impl Debug for ProfilerBuilder
Source§impl Default for ProfilerBuilder
impl Default for ProfilerBuilder
Source§fn default() -> ProfilerBuilder
fn default() -> ProfilerBuilder
Auto Trait Implementations§
impl Freeze for ProfilerBuilder
impl !RefUnwindSafe for ProfilerBuilder
impl Send for ProfilerBuilder
impl Sync for ProfilerBuilder
impl Unpin for ProfilerBuilder
impl !UnwindSafe for ProfilerBuilder
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