Skip to content

runtime: expose schedule latency in TaskMeta / Task Hooks - #8282

Merged
Darksonn merged 2 commits into
tokio-rs:masterfrom
rcoh:taskmeta-scheduling-delay
Aug 9, 2026
Merged

runtime: expose schedule latency in TaskMeta / Task Hooks#8282
Darksonn merged 2 commits into
tokio-rs:masterfrom
rcoh:taskmeta-scheduling-delay

Conversation

@rcoh

@rcoh rcoh commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Motivation

#7986 exposes a task-schedule-latency histogram and metric. For tools like dial9, it is very helpful to have this statistic available on a per-poll basis.

Solution

Expose schedule_latency() -> Option<Duration> on TaskMeta.

This is off by default. When disabled, schedule_latency returns None. It is enabled by calling track_task_schedule_latency(); happy to workshop the name. It can be enabled separately from the histogram: if you are tracking the individual latencies there's no specific need to also put them in a histogram. Enabling the histogram also exposes it to TaskMeta.

Assisted by GPT 5.6 Sol

Add an explicit tracking knob and expose the sampled task schedule
latency through TaskMeta. Reuse the histogram poll timestamp where
possible and preserve grouped histogram accounting for LIFO polls.

Document activation and interval semantics and cover current-thread,
multi-thread, LIFO, disabled, and non-poll callback behavior.
@github-actions github-actions Bot added R-loom-current-thread Run loom current-thread tests on this PR R-loom-multi-thread Run loom multi-thread tests on this PR labels Jul 15, 2026
@mattiapitossi mattiapitossi added A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime labels Jul 15, 2026
@rcoh
rcoh requested a review from Darksonn July 16, 2026 14:14

@Darksonn Darksonn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@Darksonn
Darksonn enabled auto-merge (squash) August 9, 2026 14:19
@Darksonn
Darksonn merged commit 6b62ac4 into tokio-rs:master Aug 9, 2026
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime R-loom-current-thread Run loom current-thread tests on this PR R-loom-multi-thread Run loom multi-thread tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants