-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Implement task dumps for current-thread runtime. #5608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 37 commits
1222dfb
d9aa093
66cd9c9
206b3d4
b998f74
8a727a1
80dbaf7
c132b33
9c86604
306a547
725bf3f
c20af63
52c8ca9
fdc01e1
144f378
c824389
0c655bb
578c3c4
ac7fa6b
a246b11
a62f9ee
f695499
bb6990f
51d15f0
178bf74
0a8d240
b6d093a
1ff355b
9e0dd91
9a5e7fa
f536db5
d3cda94
a29974d
51f970f
8a8dceb
b0b1160
8318d93
0dc4b68
04bd5e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,10 +186,10 @@ jobs: | |
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: | ||
| - windows-latest | ||
| - ubuntu-latest | ||
| - macos-latest | ||
| include: | ||
| - os: windows-latest | ||
| - os: ubuntu-latest | ||
| - os: macos-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Install Rust ${{ env.rust_stable }} | ||
|
|
@@ -206,6 +206,31 @@ jobs: | |
| # in order to run doctests for unstable features, we must also pass | ||
| # the unstable cfg to RustDoc | ||
| RUSTDOCFLAGS: --cfg tokio_unstable | ||
|
|
||
| test-unstable-taskdump: | ||
| name: test tokio full --unstable --taskdump | ||
| needs: basics | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - os: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Install Rust ${{ env.rust_stable }} | ||
| uses: dtolnay/rust-toolchain@master | ||
| with: | ||
| toolchain: ${{ env.rust_stable }} | ||
| - uses: Swatinem/rust-cache@v2 | ||
| # Run `tokio` with "unstable" and "taskdump" cfg flags. | ||
| - name: test tokio full --cfg unstable --cfg taskdump | ||
| run: cargo test --all-features | ||
| working-directory: tokio | ||
| env: | ||
| RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings | ||
| # in order to run doctests for unstable features, we must also pass | ||
| # the unstable cfg to RustDoc | ||
| RUSTDOCFLAGS: --cfg tokio_unstable --cfg tokio_taskdump | ||
|
|
||
| miri: | ||
| name: miri | ||
|
|
@@ -299,9 +324,11 @@ jobs: | |
| matrix: | ||
| include: | ||
| - target: i686-unknown-linux-gnu | ||
| rustflags: --cfg tokio_taskdump | ||
| - target: arm-unknown-linux-gnueabihf | ||
| - target: armv7-unknown-linux-gnueabihf | ||
| - target: aarch64-unknown-linux-gnu | ||
| rustflags: --cfg tokio_taskdump | ||
|
|
||
| # Run a platform without AtomicU64 and no const Mutex::new | ||
| - target: arm-unknown-linux-gnueabihf | ||
|
|
@@ -347,15 +374,15 @@ jobs: | |
| target: i686-unknown-linux-gnu | ||
| - run: cargo test -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --all-features | ||
| env: | ||
| RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_atomic_u64 | ||
| RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings --cfg tokio_no_atomic_u64 | ||
| # https://github.com/tokio-rs/tokio/pull/5356 | ||
| # https://github.com/tokio-rs/tokio/issues/5373 | ||
| - run: cargo hack build -p tokio --feature-powerset --depth 2 -Z avoid-dev-deps --keep-going | ||
| env: | ||
| RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_atomic_u64 --cfg tokio_no_const_mutex_new | ||
| RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings --cfg tokio_no_atomic_u64 --cfg tokio_no_const_mutex_new | ||
| - run: cargo hack build -p tokio --feature-powerset --depth 2 -Z avoid-dev-deps --keep-going | ||
| env: | ||
| RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_atomic_u64 | ||
| RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings --cfg tokio_no_atomic_u64 | ||
|
|
||
| features: | ||
| name: features | ||
|
|
@@ -377,7 +404,7 @@ jobs: | |
| - name: check --feature-powerset --unstable | ||
| run: cargo hack check --all --feature-powerset --depth 2 -Z avoid-dev-deps --keep-going | ||
| env: | ||
| RUSTFLAGS: --cfg tokio_unstable -Dwarnings | ||
| RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is the test designed to test various combinations of flags, I suggest we also try with just # Try with unstable feature flags
- name: check --feature-powerset --unstable
run: cargo hack check --all --feature-powerset --depth 2 -Z avoid-dev-deps --keep-going
env:
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
# Try with unstable and taskdump feature flags
- name: check --feature-powerset --unstable --taskdump
run: cargo hack check --all --feature-powerset --depth 2 -Z avoid-dev-deps --keep-going
env:
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings |
||
|
|
||
| minrust: | ||
| name: minrust | ||
|
|
@@ -430,7 +457,7 @@ jobs: | |
| cargo hack check --all-features --ignore-private | ||
| - name: "check --all-features --unstable -Z minimal-versions" | ||
| env: | ||
| RUSTFLAGS: --cfg tokio_unstable -Dwarnings | ||
| RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings | ||
| run: | | ||
| # Remove dev-dependencies from Cargo.toml to prevent the next `cargo update` | ||
| # from determining minimal versions based on dev-dependencies. | ||
|
|
@@ -487,8 +514,8 @@ jobs: | |
| - name: "doc --lib --all-features" | ||
| run: cargo doc --lib --no-deps --all-features --document-private-items | ||
| env: | ||
| RUSTFLAGS: --cfg docsrs --cfg tokio_unstable | ||
| RUSTDOCFLAGS: --cfg docsrs --cfg tokio_unstable -Dwarnings | ||
| RUSTFLAGS: --cfg docsrs --cfg tokio_unstable --cfg tokio_taskdump | ||
| RUSTDOCFLAGS: --cfg docsrs --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings | ||
|
|
||
| loom-compile: | ||
| name: build loom tests | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //! This example demonstrates tokio's experimental taskdumping functionality. | ||
|
|
||
| #[cfg(all( | ||
| tokio_unstable, | ||
| tokio_taskdump, | ||
| target_os = "linux", | ||
| any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64") | ||
| ))] | ||
| #[tokio::main(flavor = "current_thread")] | ||
| async fn main() { | ||
| use std::hint::black_box; | ||
|
|
||
| #[inline(never)] | ||
| async fn a() { | ||
| black_box(b()).await | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| async fn b() { | ||
| black_box(c()).await | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| async fn c() { | ||
| black_box(tokio::task::yield_now()).await | ||
| } | ||
|
|
||
| tokio::spawn(a()); | ||
| tokio::spawn(b()); | ||
| tokio::spawn(c()); | ||
|
|
||
| let handle = tokio::runtime::Handle::current(); | ||
| let dump = handle.dump(); | ||
|
|
||
| for (i, task) in dump.tasks().iter().enumerate() { | ||
| let trace = task.trace(); | ||
| println!("task {i} trace:"); | ||
| println!("{trace}"); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(all( | ||
| tokio_unstable, | ||
| tokio_taskdump, | ||
| target_os = "linux", | ||
| any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64") | ||
| )))] | ||
| fn main() { | ||
| println!("task dumps are not available") | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||
| //! Snapshots of runtime state. | ||||||
| use std::fmt; | ||||||
|
|
||||||
| /// A snapshot of a runtime's state. | ||||||
| #[derive(Debug)] | ||||||
| pub struct Dump { | ||||||
| tasks: Tasks, | ||||||
| } | ||||||
|
|
||||||
| /// Snapshots of tasks. | ||||||
| #[derive(Debug)] | ||||||
| pub struct Tasks { | ||||||
| tasks: Vec<Task>, | ||||||
| } | ||||||
|
|
||||||
| /// A snapshot of a task. | ||||||
| #[derive(Debug)] | ||||||
| pub struct Task { | ||||||
| trace: Trace, | ||||||
| } | ||||||
|
|
||||||
| /// An execution trace of a task's last poll. | ||||||
| #[derive(Debug)] | ||||||
| pub struct Trace { | ||||||
| inner: super::task::trace::Trace, | ||||||
| } | ||||||
|
|
||||||
| impl Dump { | ||||||
| pub(crate) fn new(tasks: Vec<Task>) -> Self { | ||||||
| Self { | ||||||
| tasks: Tasks { tasks }, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Tasks in this snapshot. | ||||||
| pub fn tasks(&self) -> &Tasks { | ||||||
| &self.tasks | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl Tasks { | ||||||
| /// Iterate over tasks. | ||||||
| pub fn iter(&self) -> impl Iterator<Item = &Task> { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One possible improvement here is to use impl Trait to simplify the definition of methods that return iterators. For example:
Suggested change
'_ means that the lifetime of the returned iterator is bound to the lifetime of the Tasks object |
||||||
| self.tasks.iter() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl Task { | ||||||
| pub(crate) fn new(trace: super::task::trace::Trace) -> Self { | ||||||
| Self { | ||||||
| trace: Trace { inner: trace }, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// A trace of this task's state. | ||||||
| pub fn trace(&self) -> &Trace { | ||||||
| &self.trace | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl fmt::Display for Trace { | ||||||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
| self.inner.fmt(f) | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.