Skip to content

Commit

Permalink
Move executor tracing span inside lock guard, and cache it.
Browse files Browse the repository at this point in the history
  • Loading branch information
chescock committed Feb 19, 2024
1 parent 7cb8505 commit 543215c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crates/bevy_ecs/src/schedule/executor/multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub struct MultiThreadedExecutor {
system_completion: ConcurrentQueue<SystemResult>,
/// When set, tells the executor that a thread has panicked.
panic_payload: Mutex<Option<Box<dyn Any + Send>>>,
/// Cached tracing span
#[cfg(feature = "trace")]
executor_span: Span,
}

/// The state of the executor while running.
Expand Down Expand Up @@ -318,8 +321,6 @@ impl<'scope, 'env: 'scope> Context<'scope, 'env> {
}

fn tick_executor(&self) {
#[cfg(feature = "trace")]
let _span = info_span!("multithreaded executor").entered();
// Ensure that the executor handles any events pushed to the system_completion queue by this thread.
// If this thread acquires the lock, the exector runs after the push() and they are processed.
// If this thread does not acquire the lock, then the is_empty() check on the other thread runs
Expand Down Expand Up @@ -348,6 +349,8 @@ impl MultiThreadedExecutor {
state: Mutex::new(ExecutorState::new()),
system_completion: ConcurrentQueue::unbounded(),
panic_payload: Mutex::new(None),
#[cfg(feature = "trace")]
executor_span: info_span!("multithreaded executor"),
}
}
}
Expand Down Expand Up @@ -376,6 +379,9 @@ impl ExecutorState {
}

fn tick(&mut self, context: &Context<'_, '_>) {
#[cfg(feature = "trace")]
let _span = context.executor.executor_span.enter();

for result in context.executor.system_completion.try_iter() {
self.finish_system_and_handle_dependents(result);
}
Expand Down

0 comments on commit 543215c

Please sign in to comment.