kuniga.me > NP-Incompleteness > Tokio: Dial9
25 Nov 2026
Dial9 is a Tokio runtime tracer. It can be used to record events related to Tokio operations and display them in a Gantt chart to help make sense of the execution. Russell Cohen created Dial9 at AWS and released it in March 2026, so it’s pretty recent!
This post is part of a series of posts on Tokio. We’ll study Dial9’s UI and how it works behind the scenes at a high level.
The other posts in the series are:
It’s important to know the basics of how Tokio works to understand the UI. Make sure to check the first two posts.
To enable Dial9, we need to construct the Dial9 recorder and then wrap the Tokio runtime, the application needs to use
#[dial9::main(config = recording)]
async fn main() {
// ... normal execution
}Where recording() is a function where we need to initialize Dial9’s recorder and Tokio. The collapsed code below shows a possible example.
fn recording() -> io::Result<AttachedRuntime> {
// Configure output files
let writer = DiskBuffer::builder()
.base_path("traces/01-sleep")
.max_total_size(5 * 1024 * 1024)
.max_file_size(1024 * 1024)
.build()?;
let recorder = dial9::recorder(writer)
.with_cpu_profiling(dial9::cpu::CpuProfilingConfig::default())
.build();
// Normal tokio runtime
let mut builder = tokio::runtime::Builder::new_multi_thread();
builder.enable_all().worker_threads(2);
// Dial9 runtime wrapper
let runtime = recorder.handle().attach_tokio_runtime(
builder,
TokioAttachOptions::builder()
.runtime_name("toy-example")
.task_tracking_enabled(true)
.build(),
)?;
Ok((recorder, runtime))
}Because Dial9 relies on unstable Tokio features, we need to run it with:
RUSTFLAGS="--cfg tokio_unstable" cargo run
Dial9 has a companion UI called the trace viewer. Let’s explore it before covering specific examples. Expand Figure 1 by clicking on it to see the details.
At the very top, as shown in Figure C, starting from the left we have the identifier for the trace (object in the image), then some metadata: how many events were captured, how many workers were traced, and the duration of the capture.
Then we have some high-level metrics to pay attention to: long poll is a metric corresponding to the time it takes for a worker to run the poll of a task (see poll_task() in Tokio: Scheduling). The worst long poll is the maximum value observed. A large value indicates the async worker is blocked on CPU, which hints at using spawn_blocking().
The wake delay metric measures the time it took between a task being awakened and being polled by the worker. If the task ended up being in the LIFO slot, this should be low, but if the task ended up being queued at the end of the worker’s queue, this might be high.
The metric spawn delay measures the time it took between a task being created via spawn() and being polled by some worker. This accounts for the time it spent in the global queue before being picked up by a worker.
Off-CPU active is the amount of time spent doing non-CPU work while active. We define active_time as the time elapsed from an unpark to the next park (see Tokio: Scheduling), i.e. when it wasn’t idle. During that period we can measure how much time it spent on CPU, which we define as cpu_time. One way to compute it is via clock_gettime(CLOCK_THREAD_CPUTIME_ID), which gives the cumulative amount of time that thread has spent on CPU at that moment. If we compute this value at the unpark and the next park and subtract them, we get cpu_time. Finally, off-CPU time is active_time - cpu_time.
There’s a Blocking Calls button which brings up the side panel with a flame chart:
When the worker is polling a task and the OS thread goes off-CPU, Dial9 captures the stack trace for that call. This indicates we’re blocking on non-CPU work without awaiting. In our contrived example we added a non-async sleep and a wait on a condition variable, so they show up in the stack trace. This shows opportunities where we can replace them with async APIs such as tokio::time::sleep() and tokio::sync::Notify().
Continuing with the second row, we see a minimap of the timeline. This is useful because you can zoom in on a period of time so the selection underneath changes but this one stays fixed. For example:
In the next row, center panel, we finally see per-worker information. This example shows 2 workers and when they were busy with CPU, depicted as red blocks (there’s a color gradient for the duration, and since 80ms is relatively high for I/O work, it’s shown in bright red). It also shows the worker queue as an orange line. For example, at the +903ms mark, each worker was busy executing a task and there was a third in the queue of W1.
We can also click one of the blocks to highlight which task was being executed. We can see from Figure G that the selected task was bouncing between the two workers.
If we enable CPU tracking, it can also show the CPU profiling for the task on the side panel, as shown in Figure H.
Spans are intervals with start and end times plus a name and metadata. Dial9 has a row to show manually created spans.
We can create a span by wrapping a function call with info_span!(<name>, <metadata>, callback). We can also integrate with a future by passing it to .instrument(info_span!(<name>, <metadata>)), in which case the span will correspond to the poll execution.
// Function that does CPU work for duration_ms
fn cpu_work(duration_ms: u64) {...}
async fn request(client: u64, round: u64) {
async {
info_span!("decode", bytes = 4096).in_scope(|| cpu_work(30));
tokio::time::sleep(Duration::from_millis(100))
.instrument(info_span!("wait_for_io"))
.await;
info_span!("compute", items = 1000).in_scope(|| cpu_work(50));
}
.instrument(info_span!("request", client, round))
.await;
}Here we create 3 spans, 2 of them on futures. We can see them in Figure A:
A nice feature is that spans are associated with specific tasks, so when we dive into a span by clicking on it, the whole UI filters for the selected task as well.
An event is similar to a span except that it’s a point in time. Dial9 has an API for creating events, dial9::record_event(), but it requires the schema to be provided explicitly:
use dial9::core::clock_monotonic_ns;
use dial9::format::TraceEvent;
#[derive(TraceEvent)]
#[traceevent(name = "request_completed")]
struct RequestCompleted {
#[traceevent(timestamp)]
timestamp_ns: u64,
request_id: u64,
items: u64,
}
fn my_function() {
// ...
dial9::record_event(RequestCompleted {
timestamp_ns: clock_monotonic_ns(),
request_id,
items,
});
// ...
}This will create an event with the name request_completed and metadata corresponding to the rest of the structure. The problem is that for each event type, we need a dedicated struct. It is possible to write a macro that allows us to simply do:
fn my_function() {
dial9_event!("request_completed",
request_id = request_id,
items = items,
);
}Here we assume the timestamp matches the log time, so we use timestamp_ns: clock_monotonic_ns() behind the scenes.
Now that we have covered the basics of Dial9, let’s study how it integrates with Tokio. Tokio unstable has hooks which take in callbacks that are called whenever that particular event happens. For example, if we want to count how many times we poll, we can do:
let polls = Arc::new(AtomicUsize::new(0));
let counter = Arc::clone(&polls);
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(2)
.enable_all()
.on_before_task_poll(move |_task_meta| {
counter.fetch_add(1, Ordering::Relaxed);
})
.build()
.unwrap();Note that this needs to be thread-safe because it might be called by multiple threads at any given time.
The hook executes the callback in the running thread. Dial9 has per-thread buffers (Vec<u8>) that accumulate relevant events, which have an associated timestamp. For example: task spawn, poll start, poll end, etc.
When the buffer reaches around 1MB, it creates a Batch which contains the buffer plus the event count, and it gets queued to the global queue.
Dial9 also has a flush thread which periodically forces the per-thread buffers to flush a batch (e.g. every 30s). For this reason, each per-thread buffer must have a mutex, but contention is low because most of the time, only its own thread is changing it.
The flush thread reads batches from the global queue and constructs segments, which are sequences of batches with metadata. By default, the flush thread writes the batch data to disk as it processes them. For example, it might be writing to a file named trace.0.bin.active.
Once one of several conditions is met, it seals the segment, which means we cannot append more batches to it. The conditions include: an empty queue, a timeout (60s by default), or a size limit (100 MiB), whichever happens first.
It then closes the file writer and atomically renames the file to trace.0.bin.
After writing the segments, Dial9 has a feature to post-process them, including uploading to S3 (if configured). For our examples, since we enable CPU profiling, it will run two stages: symbolization, to attach function names to the stack traces, and then compression using gzip.
For this post-processing, Dial9 loads the entire segment into memory.
A few of the statistics are computed by the front end based on the raw data. This includes the top-level metrics we described in the beginning.
In this post, we learned about Dial9 and explored its UI. In the age of AI doing most of the debugging, the value of human-friendly UIs is diminishing since we can throw all the data at agents and they often can figure things out better than us, but capturing the data is still very important.
In bpftrace in C++ we discussed trace points which are a lot like Dial9 events.
The books BPF Performance Tools and Systems Performance are also relevant. While Dial9 doesn’t use eBPF for the CPU stack traces, the idea is essentially the same as described by Gregg’s books: periodic stacktrace collection and building a flamecharts.
The rich visualization reminds me of those from Chrome, as covered in Browser Performance. It has flame charts, call trees, and custom timing intervals using performance.mark() and performance.measure().