async_profiler_agent/reporter/mod.rs
1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! This module contains [Reporter]s that upload profiling data to a destination.
5//!
6//! The following [Reporter]s are included:
7//! 1. [local::LocalReporter], which uploads profiling data to a local directory
8//! 2. [s3::S3Reporter], which uploads profiling data to an S3 bucket
9//! 3. [multi::MultiReporter], which allows combining multiple reporters.
10
11use std::fmt;
12use std::path::Path;
13
14use async_trait::async_trait;
15
16use crate::metadata::ReportMetadata;
17
18pub mod local;
19pub mod multi;
20#[cfg(feature = "s3-no-defaults")]
21pub mod s3;
22
23/// Abstraction around reporting profiler data.
24#[async_trait]
25pub trait Reporter: fmt::Debug {
26 /// Takes a profiling sample, including JFR data and sample metadata,
27 /// and uploads it towards a destination.
28 ///
29 /// If this function returns an error, the sample will be dropped
30 /// but profiling will continue, and this function will be called
31 /// again for the next sample (or theoretically, a future version
32 /// might have configuration that will an attempt to re-upload the
33 /// current sample will be made - but today's [`Profiler`] does
34 /// not make any such attempts).
35 ///
36 /// [`Profiler`]: crate::profiler::Profiler
37 async fn report(
38 &self,
39 jfr: Vec<u8>,
40 metadata: &ReportMetadata,
41 ) -> Result<(), Box<dyn std::error::Error + Send>>;
42
43 /// Synchronously report profiling data. Called during drop when the
44 /// async runtime is shutting down and async reporting is not possible.
45 ///
46 /// The default implementation does nothing. Reporters that can perform
47 /// synchronous I/O (like [`local::LocalReporter`]) should override this.
48 #[doc(hidden)]
49 fn report_blocking(
50 &self,
51 _jfr_path: &Path,
52 _metadata: &ReportMetadata,
53 ) -> Result<(), Box<dyn std::error::Error + Send>> {
54 tracing::info!(
55 "reporter does not support synchronous reporting, last sample will be lost. \
56 Call `RunningProfiler::stop().await` before shutdown to ensure all samples are uploaded."
57 );
58 Ok(())
59 }
60}