doc_sync_probed/
doc_sync_probed.rs1use latency_trace::{summary_stats, LatencyTrace};
2use std::{thread, time::Duration};
3use tracing::{info, instrument, trace, trace_span};
4
5#[instrument(level = "info")]
6fn f() {
7 trace!("in f");
8 for _ in 0..10 {
9 trace_span!("loop_body").in_scope(|| {
10 info!("in loop body");
11 thread::sleep(Duration::from_micros(1200));
13
14 g();
15 });
16 }
17}
18
19#[instrument(level = "info")]
20fn g() {
21 trace!("in g");
22 thread::sleep(Duration::from_micros(800));
24}
25
26fn main() {
27 let probed = LatencyTrace::activated_default()
28 .unwrap()
29 .measure_latencies_probed(f)
30 .unwrap();
31
32 thread::sleep(Duration::from_micros(16000));
34
35 let latencies1 = probed.probe_latencies();
36 let latencies2 = probed.wait_and_report();
37
38 println!("\nlatencies1 in microseconds");
39 for (span_group, stats) in latencies1.map_values(summary_stats) {
40 println!(" * {:?}, {:?}", span_group, stats);
41 }
42
43 println!("\nlatencies2 in microseconds");
44 for (span_group, stats) in latencies2.map_values(summary_stats) {
45 println!(" * {:?}, {:?}", span_group, stats);
46 }
47}