diff --git a/crates/bevy_ecs/src/schedule/executor_parallel.rs b/crates/bevy_ecs/src/schedule/executor_parallel.rs index 3311a45118a04..43e8a6f4ddc4d 100644 --- a/crates/bevy_ecs/src/schedule/executor_parallel.rs +++ b/crates/bevy_ecs/src/schedule/executor_parallel.rs @@ -6,6 +6,8 @@ use crate::{ }; use async_channel::{Receiver, Sender}; use bevy_tasks::{ComputeTaskPool, Scope, TaskPool}; +#[cfg(feature = "trace")] +use bevy_utils::tracing::Instrument; use fixedbitset::FixedBitSet; #[cfg(test)] @@ -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,9 @@ 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 +219,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 {