1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Publicly exported `tokio`-related methods of [`LatencyTrace`].
//! Present only when the **"tokio"** feature flag is enabled.
use crate::{
lt_refine_g::Timings, lt_report_g::ActivationError, probed_trace::ProbedTrace, LatencyTrace,
};
use std::future::Future;
impl LatencyTrace {
/// Executes the instrumented async function `f`, running on the `tokio` runtime; after `f` completes,
/// returns the observed latencies.
/// Present only when the **"tokio"** feature flag is enabled.
pub fn measure_latencies_tokio<F>(&self, f: impl FnOnce() -> F) -> Timings
where
F: Future<Output = ()> + Send,
{
self.0.measure_latencies_tokio(f)
}
/// Executes the instrumented async function `f`, running on the `tokio` runtime; returns a [`ProbedTrace`]
/// that allows partial latencies to be reported before `f` completes.
/// Present only when the **"tokio"** feature flag is enabled.
pub fn measure_latencies_probed_tokio<F>(
self,
f: impl FnOnce() -> F + Send + 'static,
) -> Result<ProbedTrace, ActivationError>
where
F: Future<Output = ()> + Send,
{
self.measure_latencies_probed(|| {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("Tokio runtime error")
.block_on(f());
})
}
}