Skip to content

Commit 851b593

Browse files
committed
add tracing spans for parallel executor and system overhead (#3416)
This PR adds tracing spans for the parallel executor and system overhead. ![image](https://user-images.githubusercontent.com/2180432/147172747-b78026e3-1c30-4120-92c8-693c6f1564cd.png)
1 parent 0936f4c commit 851b593

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/bevy_ecs/src/schedule/executor_parallel.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{
66
};
77
use async_channel::{Receiver, Sender};
88
use bevy_tasks::{ComputeTaskPool, Scope, TaskPool};
9+
#[cfg(feature = "trace")]
10+
use bevy_utils::tracing::Instrument;
911
use fixedbitset::FixedBitSet;
1012

1113
#[cfg(test)]
@@ -119,7 +121,7 @@ impl ParallelSystemExecutor for ParallelExecutor {
119121
.clone();
120122
compute_pool.scope(|scope| {
121123
self.prepare_systems(scope, systems, world);
122-
scope.spawn(async {
124+
let parallel_executor = async {
123125
// All systems have been ran if there are no queued or running systems.
124126
while 0 != self.queued.count_ones(..) + self.running.count_ones(..) {
125127
self.process_queued_systems().await;
@@ -141,7 +143,12 @@ impl ParallelSystemExecutor for ParallelExecutor {
141143
}
142144
self.update_counters_and_queue_systems();
143145
}
144-
});
146+
};
147+
#[cfg(feature = "trace")]
148+
let span = bevy_utils::tracing::info_span!("parallel executor");
149+
#[cfg(feature = "trace")]
150+
let parallel_executor = parallel_executor.instrument(span);
151+
scope.spawn(parallel_executor);
145152
});
146153
}
147154
}
@@ -194,6 +201,9 @@ impl ParallelExecutor {
194201
let system = system.system_mut();
195202
#[cfg(feature = "trace")] // NB: outside the task to get the TLS current span
196203
let system_span = bevy_utils::tracing::info_span!("system", name = &*system.name());
204+
#[cfg(feature = "trace")]
205+
let overhead_span =
206+
bevy_utils::tracing::info_span!("system overhead", name = &*system.name());
197207
let task = async move {
198208
start_receiver
199209
.recv()
@@ -209,6 +219,9 @@ impl ParallelExecutor {
209219
.await
210220
.unwrap_or_else(|error| unreachable!(error));
211221
};
222+
223+
#[cfg(feature = "trace")]
224+
let task = task.instrument(overhead_span);
212225
if system_data.is_send {
213226
scope.spawn(task);
214227
} else {

0 commit comments

Comments
 (0)