@@ -39,7 +39,7 @@ use std::{
3939 } ,
4040 time:: Instant ,
4141} ;
42- use tracing:: { debug, trace, warn} ;
42+ use tracing:: { debug, debug_span , instrument , trace, warn} ;
4343
4444/// A wrapper for transactions that includes their index in the block.
4545#[ derive( Clone ) ]
@@ -139,8 +139,11 @@ where
139139 let ctx = self . ctx . clone ( ) ;
140140 let max_concurrency = self . max_concurrency ;
141141 let transaction_count_hint = self . transaction_count_hint ;
142+ let span = tracing:: Span :: current ( ) ;
142143
143144 self . executor . spawn_blocking ( move || {
145+ let _enter = debug_span ! ( target: "engine::tree::payload_processor::prewarm" , parent: span, "spawn_all" ) . entered ( ) ;
146+
144147 let ( done_tx, done_rx) = mpsc:: channel ( ) ;
145148 let mut executing = 0usize ;
146149
@@ -157,8 +160,8 @@ where
157160 } ;
158161
159162 // Only spawn initial workers as needed
160- for _ in 0 ..workers_needed {
161- handles. push ( ctx. spawn_worker ( & executor, actions_tx. clone ( ) , done_tx. clone ( ) ) ) ;
163+ for i in 0 ..workers_needed {
164+ handles. push ( ctx. spawn_worker ( i , & executor, actions_tx. clone ( ) , done_tx. clone ( ) ) ) ;
162165 }
163166
164167 let mut tx_index = 0usize ;
@@ -248,6 +251,7 @@ where
248251 /// the new, warmed cache to be inserted.
249252 ///
250253 /// This method is called from `run()` only after all execution tasks are complete.
254+ #[ instrument( level = "debug" , target = "engine::tree::payload_processor::prewarm" , skip_all) ]
251255 fn save_cache ( self , state : BundleState ) {
252256 let start = Instant :: now ( ) ;
253257
@@ -284,6 +288,12 @@ where
284288 ///
285289 /// This will execute the transactions until all transactions have been processed or the task
286290 /// was cancelled.
291+ #[ instrument(
292+ level = "debug" ,
293+ target = "engine::tree::payload_processor::prewarm" ,
294+ name = "prewarm" ,
295+ skip_all
296+ ) ]
287297 pub ( super ) fn run (
288298 self ,
289299 pending : mpsc:: Receiver < impl ExecutableTxFor < Evm > + Clone + Send + ' static > ,
@@ -364,6 +374,7 @@ where
364374{
365375 /// Splits this context into an evm, an evm config, metrics, and the atomic bool for terminating
366376 /// execution.
377+ #[ instrument( level = "debug" , target = "engine::tree::payload_processor::prewarm" , skip_all) ]
367378 fn evm_for_ctx ( self ) -> Option < ( EvmFor < Evm , impl Database > , PrewarmMetrics , Arc < AtomicBool > ) > {
368379 let Self {
369380 env,
@@ -380,7 +391,7 @@ where
380391 Ok ( provider) => provider,
381392 Err ( err) => {
382393 trace ! (
383- target: "engine::tree" ,
394+ target: "engine::tree::payload_processor::prewarm " ,
384395 %err,
385396 "Failed to build state provider in prewarm thread"
386397 ) ;
@@ -429,6 +440,7 @@ where
429440 ///
430441 /// Note: There are no ordering guarantees; this does not reflect the state produced by
431442 /// sequential execution.
443+ #[ instrument( level = "debug" , target = "engine::tree::payload_processor::prewarm" , skip_all) ]
432444 fn transact_batch < Tx > (
433445 self ,
434446 txs : mpsc:: Receiver < IndexedTransaction < Tx > > ,
@@ -439,7 +451,15 @@ where
439451 {
440452 let Some ( ( mut evm, metrics, terminate_execution) ) = self . evm_for_ctx ( ) else { return } ;
441453
442- while let Ok ( IndexedTransaction { index, tx } ) = txs. recv ( ) {
454+ while let Ok ( IndexedTransaction { index, tx } ) = {
455+ let _enter = debug_span ! ( target: "engine::tree::payload_processor::prewarm" , "recv tx" )
456+ . entered ( ) ;
457+ txs. recv ( )
458+ } {
459+ let _enter =
460+ debug_span ! ( target: "engine::tree::payload_processor::prewarm" , "prewarm tx" , index, tx_hash=%tx. tx( ) . tx_hash( ) )
461+ . entered ( ) ;
462+
443463 // If the task was cancelled, stop execution, send an empty result to notify the task,
444464 // and exit.
445465 if terminate_execution. load ( Ordering :: Relaxed ) {
@@ -467,12 +487,18 @@ where
467487 } ;
468488 metrics. execution_duration . record ( start. elapsed ( ) ) ;
469489
490+ drop ( _enter) ;
491+
470492 // Only send outcome for transactions after the first txn
471493 // as the main execution will be just as fast
472494 if index > 0 {
495+ let _enter =
496+ debug_span ! ( target: "engine::tree::payload_processor::prewarm" , "prewarm outcome" , index, tx_hash=%tx. tx( ) . tx_hash( ) )
497+ . entered ( ) ;
473498 let ( targets, storage_targets) = multiproof_targets_from_state ( res. state ) ;
474499 metrics. prefetch_storage_targets . record ( storage_targets as f64 ) ;
475500 let _ = sender. send ( PrewarmTaskEvent :: Outcome { proof_targets : Some ( targets) } ) ;
501+ drop ( _enter) ;
476502 }
477503
478504 metrics. total_runtime . record ( start. elapsed ( ) ) ;
@@ -485,6 +511,7 @@ where
485511 /// Spawns a worker task for transaction execution and returns its sender channel.
486512 fn spawn_worker < Tx > (
487513 & self ,
514+ idx : usize ,
488515 executor : & WorkloadExecutor ,
489516 actions_tx : Sender < PrewarmTaskEvent > ,
490517 done_tx : Sender < ( ) > ,
@@ -494,8 +521,11 @@ where
494521 {
495522 let ( tx, rx) = mpsc:: channel ( ) ;
496523 let ctx = self . clone ( ) ;
524+ let span =
525+ debug_span ! ( target: "engine::tree::payload_processor::prewarm" , "prewarm worker" , idx) ;
497526
498527 executor. spawn_blocking ( move || {
528+ let _enter = span. entered ( ) ;
499529 ctx. transact_batch ( rx, actions_tx, done_tx) ;
500530 } ) ;
501531
0 commit comments