add tracing spans for parallel executor and system overhead (#3416)
This PR adds tracing spans for the parallel executor and system overhead. 
This commit is contained in:
		
							parent
							
								
									0936f4ca9d
								
							
						
					
					
						commit
						851b5939ce
					
				@ -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 New Issue
	
	Block a user