mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 22:50:19 +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 async_channel::{Receiver, Sender};
|
||||||
use bevy_tasks::{ComputeTaskPool, Scope, TaskPool};
|
use bevy_tasks::{ComputeTaskPool, Scope, TaskPool};
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
use bevy_utils::tracing::Instrument;
|
||||||
use fixedbitset::FixedBitSet;
|
use fixedbitset::FixedBitSet;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -119,7 +121,7 @@ impl ParallelSystemExecutor for ParallelExecutor {
|
||||||
.clone();
|
.clone();
|
||||||
compute_pool.scope(|scope| {
|
compute_pool.scope(|scope| {
|
||||||
self.prepare_systems(scope, systems, world);
|
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.
|
// All systems have been ran if there are no queued or running systems.
|
||||||
while 0 != self.queued.count_ones(..) + self.running.count_ones(..) {
|
while 0 != self.queued.count_ones(..) + self.running.count_ones(..) {
|
||||||
self.process_queued_systems().await;
|
self.process_queued_systems().await;
|
||||||
|
@ -141,7 +143,12 @@ impl ParallelSystemExecutor for ParallelExecutor {
|
||||||
}
|
}
|
||||||
self.update_counters_and_queue_systems();
|
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();
|
let system = system.system_mut();
|
||||||
#[cfg(feature = "trace")] // NB: outside the task to get the TLS current span
|
#[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());
|
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 {
|
let task = async move {
|
||||||
start_receiver
|
start_receiver
|
||||||
.recv()
|
.recv()
|
||||||
|
@ -209,6 +219,9 @@ impl ParallelExecutor {
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|error| unreachable!(error));
|
.unwrap_or_else(|error| unreachable!(error));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "trace")]
|
||||||
|
let task = task.instrument(overhead_span);
|
||||||
if system_data.is_send {
|
if system_data.is_send {
|
||||||
scope.spawn(task);
|
scope.spawn(task);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue