From cef4efdd4760b09db0dcec61198e46e4ed21f9b6 Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Wed, 22 Dec 2021 15:07:21 -0800 Subject: [PATCH 1/2] add tracing spans for executor and system overhead --- .../bevy_ecs/src/schedule/executor_parallel.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/executor_parallel.rs b/crates/bevy_ecs/src/schedule/executor_parallel.rs index 3311a45118a04..a4d5292f2b706 100644 --- a/crates/bevy_ecs/src/schedule/executor_parallel.rs +++ b/crates/bevy_ecs/src/schedule/executor_parallel.rs @@ -7,6 +7,8 @@ use crate::{ use async_channel::{Receiver, Sender}; use bevy_tasks::{ComputeTaskPool, Scope, TaskPool}; use fixedbitset::FixedBitSet; +#[cfg(feature = "trace")] +use bevy_utils::tracing::Instrument; #[cfg(test)] use SchedulingEvent::*; @@ -119,7 +121,7 @@ impl ParallelSystemExecutor for ParallelExecutor { .clone(); compute_pool.scope(|scope| { self.prepare_systems(scope, systems, world); - scope.spawn(async { + let parallel_executor = async { // All systems have been ran if there are no queued or running systems. while 0 != self.queued.count_ones(..) + self.running.count_ones(..) { self.process_queued_systems().await; @@ -141,7 +143,12 @@ impl ParallelSystemExecutor for ParallelExecutor { } self.update_counters_and_queue_systems(); } - }); + }; + #[cfg(feature = "trace")] + let span = bevy_utils::tracing::info_span!("parallel executor"); + #[cfg(feature = "trace")] + let parallel_executor = parallel_executor.instrument(span); + scope.spawn(parallel_executor); }); } } @@ -194,6 +201,8 @@ impl ParallelExecutor { let system = system.system_mut(); #[cfg(feature = "trace")] // NB: outside the task to get the TLS current span let system_span = bevy_utils::tracing::info_span!("system", name = &*system.name()); + #[cfg(feature = "trace")] + let overhead_span = bevy_utils::tracing::info_span!("system overhead", name = &*system.name()); let task = async move { start_receiver .recv() @@ -209,6 +218,9 @@ impl ParallelExecutor { .await .unwrap_or_else(|error| unreachable!(error)); }; + + #[cfg(feature = "trace")] + let task = task.instrument(overhead_span); if system_data.is_send { scope.spawn(task); } else { From 90cb515705bcb8422c19d3cdbc07c15b7c527b05 Mon Sep 17 00:00:00 2001 From: Mike Hsu Date: Wed, 22 Dec 2021 18:06:16 -0800 Subject: [PATCH 2/2] run cargo fmt --- crates/bevy_ecs/src/schedule/executor_parallel.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/executor_parallel.rs b/crates/bevy_ecs/src/schedule/executor_parallel.rs index a4d5292f2b706..43e8a6f4ddc4d 100644 --- a/crates/bevy_ecs/src/schedule/executor_parallel.rs +++ b/crates/bevy_ecs/src/schedule/executor_parallel.rs @@ -6,9 +6,9 @@ use crate::{ }; use async_channel::{Receiver, Sender}; use bevy_tasks::{ComputeTaskPool, Scope, TaskPool}; -use fixedbitset::FixedBitSet; #[cfg(feature = "trace")] use bevy_utils::tracing::Instrument; +use fixedbitset::FixedBitSet; #[cfg(test)] use SchedulingEvent::*; @@ -202,7 +202,8 @@ impl ParallelExecutor { #[cfg(feature = "trace")] // NB: outside the task to get the TLS current span let system_span = bevy_utils::tracing::info_span!("system", name = &*system.name()); #[cfg(feature = "trace")] - let overhead_span = bevy_utils::tracing::info_span!("system overhead", name = &*system.name()); + let overhead_span = + bevy_utils::tracing::info_span!("system overhead", name = &*system.name()); let task = async move { start_receiver .recv()