Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - add tracing spans for parallel executor and system overhead #3416

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions crates/bevy_ecs/src/schedule/executor_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
});
}
}
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down