mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
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)
This commit is contained in:
parent
0936f4ca9d
commit
851b5939ce
1 changed files with 15 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue