-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathdebug_timing.rs
More file actions
55 lines (47 loc) · 1.78 KB
/
debug_timing.rs
File metadata and controls
55 lines (47 loc) · 1.78 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use dial9_tokio_telemetry::task_dump::{DetectLongWait, LongPollTracker, SentinelStatus};
use tokio::time::Duration;
#[tokio::main]
async fn main() {
let (tracker, mut handle) = LongPollTracker::new();
tracker.spawn();
println!("Starting sleep future...");
let sleep_future = tokio::time::sleep(Duration::from_secs(20));
let wrapped = DetectLongWait::new(sleep_future, handle.sentinel_tx.clone());
let task = tokio::spawn(async move {
wrapped.await;
println!("Sleep completed");
});
println!("Waiting for long poll detection...");
for i in 1..=10 {
tokio::time::sleep(Duration::from_secs(1)).await;
println!("{}s elapsed...", i);
if let Ok(event) = handle.rx.try_recv() {
println!("\n=== LONG POLL DETECTED at {}s ===", i);
println!(
"Status: {:?}",
match &event.status {
SentinelStatus::Pending(_) => "Pending",
SentinelStatus::Completed => "Completed",
SentinelStatus::Cancelled => "Cancelled",
}
);
println!("Send count: {}", event.send_count.0);
if let SentinelStatus::Pending(traces) = &event.status {
println!("\nNumber of traces captured: {}", traces.len());
if let Some((_, trace)) = traces.last() {
println!(
"\nTrace (first 8 lines):\n{}",
trace
.to_string()
.lines()
.take(8)
.collect::<Vec<_>>()
.join("\n")
);
}
}
break;
}
}
task.abort();
}