@@ -6,6 +6,8 @@ use crate::{
6
6
} ;
7
7
use async_channel:: { Receiver , Sender } ;
8
8
use bevy_tasks:: { ComputeTaskPool , Scope , TaskPool } ;
9
+ #[ cfg( feature = "trace" ) ]
10
+ use bevy_utils:: tracing:: Instrument ;
9
11
use fixedbitset:: FixedBitSet ;
10
12
11
13
#[ cfg( test) ]
@@ -119,7 +121,7 @@ impl ParallelSystemExecutor for ParallelExecutor {
119
121
. clone ( ) ;
120
122
compute_pool. scope ( |scope| {
121
123
self . prepare_systems ( scope, systems, world) ;
122
- scope . spawn ( async {
124
+ let parallel_executor = async {
123
125
// All systems have been ran if there are no queued or running systems.
124
126
while 0 != self . queued . count_ones ( ..) + self . running . count_ones ( ..) {
125
127
self . process_queued_systems ( ) . await ;
@@ -141,7 +143,12 @@ impl ParallelSystemExecutor for ParallelExecutor {
141
143
}
142
144
self . update_counters_and_queue_systems ( ) ;
143
145
}
144
- } ) ;
146
+ } ;
147
+ #[ cfg( feature = "trace" ) ]
148
+ let span = bevy_utils:: tracing:: info_span!( "parallel executor" ) ;
149
+ #[ cfg( feature = "trace" ) ]
150
+ let parallel_executor = parallel_executor. instrument ( span) ;
151
+ scope. spawn ( parallel_executor) ;
145
152
} ) ;
146
153
}
147
154
}
@@ -194,6 +201,9 @@ impl ParallelExecutor {
194
201
let system = system. system_mut ( ) ;
195
202
#[ cfg( feature = "trace" ) ] // NB: outside the task to get the TLS current span
196
203
let system_span = bevy_utils:: tracing:: info_span!( "system" , name = & * system. name( ) ) ;
204
+ #[ cfg( feature = "trace" ) ]
205
+ let overhead_span =
206
+ bevy_utils:: tracing:: info_span!( "system overhead" , name = & * system. name( ) ) ;
197
207
let task = async move {
198
208
start_receiver
199
209
. recv ( )
@@ -209,6 +219,9 @@ impl ParallelExecutor {
209
219
. await
210
220
. unwrap_or_else ( |error| unreachable ! ( error) ) ;
211
221
} ;
222
+
223
+ #[ cfg( feature = "trace" ) ]
224
+ let task = task. instrument ( overhead_span) ;
212
225
if system_data. is_send {
213
226
scope. spawn ( task) ;
214
227
} else {
0 commit comments