Skip to content

Commit ed3c773

Browse files
committed
implement usdt probes for task events
fix spellcheck fix inference errors caused by new serde dependency split task spawn details out vendor usdt impl implement aarch64 support for linux fix typos move poll measurements to somewhere that wont monomorphise, remove semaphores from most linux probes significant overhaul to reduce monomorphisation of probes, also expose task termination reason Revert "fix inference errors caused by new serde dependency" This reverts commit e3a7a09. fix disabled polyfill fix bad assembler expressions fix lints refactor stapsdt handling include usdt cfg in CI testing refactor macos provider document stapsdt format fix rt feature revert back to feature flag again fix CI fix probe names on linux and inline PollGuard drop add retained flag to notes, allowing us to inline and monomorphise again proper fix for stapsdt note and gc-sections interaction
1 parent d709df2 commit ed3c773

File tree

25 files changed

+771
-48
lines changed

25 files changed

+771
-48
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ jobs:
258258
# only Linux supports io_uring
259259
- { os: ubuntu-latest, extra_features: io-uring }
260260
- { os: macos-latest, extra_features: "" }
261+
# only Linux and macOS support usdt
262+
- { os: ubuntu-latest, extra_features: usdt }
263+
- { os: macos-latest, extra_features: usdt }
261264
steps:
262265
- uses: actions/checkout@v5
263266
- name: Install Rust ${{ env.rust_stable }}
@@ -527,7 +530,7 @@ jobs:
527530
os: ubuntu-24.04-arm
528531
- target: aarch64-unknown-linux-gnu
529532
os: ubuntu-24.04-arm
530-
extra_features: "io-uring,taskdump"
533+
extra_features: "io-uring,taskdump,usdt"
531534
- target: aarch64-pc-windows-msvc
532535
os: windows-11-arm
533536
steps:
@@ -577,7 +580,7 @@ jobs:
577580
os: ubuntu-24.04-arm
578581
- target: aarch64-unknown-linux-gnu
579582
os: ubuntu-24.04-arm
580-
extra_features: "io-uring,taskdump"
583+
extra_features: "io-uring,taskdump,usdt"
581584
- target: aarch64-pc-windows-msvc
582585
os: windows-11-arm
583586
steps:
@@ -671,7 +674,8 @@ jobs:
671674
# https://github.com/tokio-rs/tokio/issues/5373
672675
- name: Check
673676
# We use `--skip io-uring` since io-uring crate doesn't provide a binding for the i686 target.
674-
run: cargo hack check -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --feature-powerset --skip io-uring --depth 2 --keep-going
677+
# We use `--skip usdt` since usdt is not supported on the i686 target.
678+
run: cargo hack check -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --feature-powerset --skip io-uring --skip usdt --depth 2 --keep-going
675679
env:
676680
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
677681

@@ -684,11 +688,11 @@ jobs:
684688
include:
685689
- name: ""
686690
rustflags: ""
687-
exclude_features: "io-uring,taskdump"
691+
exclude_features: "io-uring,taskdump,usdt"
688692
- name: "--unstable"
689693
rustflags: "--cfg tokio_unstable -Dwarnings"
690-
exclude_features: "io-uring,taskdump"
691-
- name: "--unstable io-uring,taskdump"
694+
exclude_features: "io-uring,taskdump,usdt"
695+
- name: "--unstable io-uring,taskdump,usdt"
692696
rustflags: "--cfg tokio_unstable -Dwarnings"
693697
exclude_features: ""
694698
steps:
@@ -1091,11 +1095,11 @@ jobs:
10911095
matrix:
10921096
include:
10931097
- os: windows-latest
1094-
# Windows neither supports io-uring nor taskdump.
1098+
# Windows neither supports io-uring nor taskdump nor usdt.
10951099
extra_features: "tracing"
10961100
- os: ubuntu-latest
10971101
# includes all unstable features.
1098-
extra_features: "tracing,io-uring,taskdump"
1102+
extra_features: "tracing,io-uring,taskdump,usdt"
10991103
steps:
11001104
- uses: actions/checkout@v5
11011105
- name: Install Rust ${{ matrix.rust }}
@@ -1112,7 +1116,7 @@ jobs:
11121116
- name: check-external-types
11131117
env:
11141118
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
1115-
RUSTDOCFLAGS: --cfg tokio_unstable
1119+
RUSTDOCFLAGS: --cfg tokio_unstable ${{ matrix.extra_flags }}
11161120
run: cargo check-external-types --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }}
11171121
working-directory: tokio
11181122

spellcheck.dic

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
308
1+
310
22
&
33
+
44
<
@@ -293,6 +293,8 @@ Unsets
293293
unsynchronized
294294
untrusted
295295
uring
296+
usdt
297+
USDT
296298
usecases
297299
Valgrind
298300
Varghese

tokio/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ time = []
8888
io-uring = ["dep:io-uring", "libc", "mio/os-poll", "mio/os-ext", "dep:slab"]
8989
# Unstable feature. Requires `--cfg tokio_unstable` to enable.
9090
taskdump = ["dep:backtrace"]
91+
# Unstable feature. Requires `--cfg tokio_unstable` to enable.
92+
usdt = []
9193

9294
[dependencies]
9395
tokio-macros = { version = "~2.6.0", path = "../tokio-macros", optional = true }

tokio/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@
351351
//! Some feature flags are only available when specifying the `tokio_unstable` flag:
352352
//!
353353
//! - `tracing`: Enables tracing events.
354+
//! - `usdt`: Enables USDT probes.
354355
//!
355356
//! Likewise, some parts of the API are only available with the same flag:
356357
//!
@@ -499,6 +500,9 @@ compile_error!(
499500
linux, on `aarch64`, `x86` and `x86_64`."
500501
);
501502

503+
#[cfg(all(not(tokio_unstable), feature = "usdt"))]
504+
compile_error!("The `usdt` feature requires `--cfg tokio_unstable`.");
505+
502506
// Includes re-exports used by macros.
503507
//
504508
// This module is not intended to be part of the public API. In general, any

tokio/src/macros/cfg.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,35 @@ macro_rules! cfg_not_trace {
593593
}
594594
}
595595

596+
macro_rules! cfg_usdt {
597+
($($item:item)*) => {
598+
$(
599+
#[cfg(all(tokio_unstable, feature = "usdt"))]
600+
#[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "usdt"))))]
601+
$item
602+
)*
603+
};
604+
}
605+
606+
macro_rules! cfg_not_usdt {
607+
($($item:item)*) => {
608+
$(
609+
#[cfg(any(not(tokio_unstable), not(feature = "usdt")))]
610+
$item
611+
)*
612+
}
613+
}
614+
615+
macro_rules! cfg_trace_or_usdt {
616+
($($item:item)*) => {
617+
$(
618+
#[cfg(all(tokio_unstable, any(feature = "tracing", feature = "usdt")))]
619+
#[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, any(feature = "tracing", feature = "usdt")))))]
620+
$item
621+
)*
622+
};
623+
}
624+
596625
macro_rules! cfg_coop {
597626
($($item:item)*) => {
598627
$(

tokio/src/runtime/blocking/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cfg_fs! {
1010
pub(crate) use pool::spawn_mandatory_blocking;
1111
}
1212

13-
cfg_trace! {
13+
cfg_trace_or_usdt! {
1414
pub(crate) use pool::Mandatory;
1515
}
1616

tokio/src/runtime/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,8 @@ impl Builder {
940940
/// # }
941941
/// ```
942942
pub fn build(&mut self) -> io::Result<Runtime> {
943+
crate::util::usdt::register_probes()?;
944+
943945
match &self.kind {
944946
Kind::CurrentThread => self.build_current_thread_runtime(),
945947
#[cfg(feature = "rt-multi-thread")]

tokio/src/runtime/handle.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::runtime::task::JoinHandle;
1919
use crate::runtime::BOX_FUTURE_THRESHOLD;
2020
use crate::util::error::{CONTEXT_MISSING_ERROR, THREAD_LOCAL_DESTROYED_ERROR};
2121
use crate::util::trace::SpawnMeta;
22+
use crate::util::usdt;
2223

2324
use std::future::Future;
2425
use std::marker::PhantomData;
@@ -359,9 +360,12 @@ impl Handle {
359360
))]
360361
let future = super::task::trace::Trace::root(future);
361362

363+
#[cfg(all(tokio_unstable, any(feature = "tracing", feature = "usdt")))]
364+
let id = super::task::Id::next();
365+
#[cfg(all(tokio_unstable, feature = "usdt"))]
366+
let future = usdt::block_on(future, _meta, id);
362367
#[cfg(all(tokio_unstable, feature = "tracing"))]
363-
let future =
364-
crate::util::trace::task(future, "block_on", _meta, super::task::Id::next().as_u64());
368+
let future = crate::util::trace::task(future, "block_on", _meta, id.as_u64());
365369

366370
// Enter the runtime context. This sets the current driver handles and
367371
// prevents blocking an existing runtime.
@@ -385,6 +389,7 @@ impl Handle {
385389
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
386390
))]
387391
let future = super::task::trace::Trace::root(future);
392+
usdt::start_task(usdt::TaskKind::Spawn, meta, id, std::mem::size_of::<F>());
388393
#[cfg(all(tokio_unstable, feature = "tracing"))]
389394
let future = crate::util::trace::task(future, "task", meta, id.as_u64());
390395
self.inner.spawn(future, id, meta.spawned_at)
@@ -414,6 +419,12 @@ impl Handle {
414419
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
415420
))]
416421
let future = super::task::trace::Trace::root(future);
422+
usdt::start_task(
423+
usdt::TaskKind::SpawnLocal,
424+
meta,
425+
id,
426+
std::mem::size_of::<F>(),
427+
);
417428
#[cfg(all(tokio_unstable, feature = "tracing"))]
418429
let future = crate::util::trace::task(future, "task", meta, id.as_u64());
419430
unsafe { self.inner.spawn_local(future, id, meta.spawned_at) }

tokio/src/runtime/local_runtime/runtime.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::runtime::{context, Builder, EnterGuard, Handle, BOX_FUTURE_THRESHOLD}
66
use crate::task::JoinHandle;
77

88
use crate::util::trace::SpawnMeta;
9+
#[cfg(all(tokio_unstable, feature = "usdt"))]
10+
use crate::util::usdt;
911
use std::future::Future;
1012
use std::marker::PhantomData;
1113
use std::mem;
@@ -239,13 +241,12 @@ impl LocalRuntime {
239241
))]
240242
let future = crate::runtime::task::trace::Trace::root(future);
241243

244+
#[cfg(all(tokio_unstable, any(feature = "tracing", feature = "usdt")))]
245+
let id = crate::runtime::task::Id::next();
246+
#[cfg(all(tokio_unstable, feature = "usdt"))]
247+
let future = usdt::block_on(future, _meta, id);
242248
#[cfg(all(tokio_unstable, feature = "tracing"))]
243-
let future = crate::util::trace::task(
244-
future,
245-
"block_on",
246-
_meta,
247-
crate::runtime::task::Id::next().as_u64(),
248-
);
249+
let future = crate::util::trace::task(future, "block_on", _meta, id.as_u64());
249250

250251
let _enter = self.enter();
251252

tokio/src/runtime/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ cfg_rt! {
407407
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
408408
pub(crate) use blocking::spawn_blocking;
409409

410-
cfg_trace! {
410+
cfg_trace_or_usdt! {
411411
pub(crate) use blocking::Mandatory;
412412
}
413413

0 commit comments

Comments
 (0)