@@ -28,6 +28,8 @@ use std::{env, fs, io, str};
2828use build_helper:: ci:: gha;
2929use build_helper:: exit;
3030use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
31+ #[ cfg( feature = "tracing" ) ]
32+ use tracing:: { debug, instrument, span, trace} ;
3133use utils:: build_stamp:: BuildStamp ;
3234use utils:: channel:: GitInfo ;
3335
@@ -537,14 +539,25 @@ impl Build {
537539 }
538540
539541 /// Executes the entire build, as configured by the flags and configuration.
542+ #[ cfg_attr( feature = "tracing" , instrument( level = "debug" , name = "Build::build" , skip_all) ) ]
540543 pub fn build ( & mut self ) {
544+ #[ cfg( feature = "tracing" ) ]
545+ trace ! ( "setting up job management" ) ;
541546 unsafe {
542547 crate :: utils:: job:: setup ( self ) ;
543548 }
544549
550+ #[ cfg( feature = "tracing" ) ]
551+ trace ! ( "downloading rustfmt early" ) ;
552+
545553 // Download rustfmt early so that it can be used in rust-analyzer configs.
546554 let _ = & builder:: Builder :: new ( self ) . initial_rustfmt ( ) ;
547555
556+ #[ cfg( feature = "tracing" ) ]
557+ let hardcoded_span =
558+ span ! ( tracing:: Level :: DEBUG , "handling hardcoded subcommands (Format, Suggest, Perf)" )
559+ . entered ( ) ;
560+
548561 // hardcoded subcommands
549562 match & self . config . cmd {
550563 Subcommand :: Format { check, all } => {
@@ -561,25 +574,50 @@ impl Build {
561574 Subcommand :: Perf { .. } => {
562575 return core:: build_steps:: perf:: perf ( & builder:: Builder :: new ( self ) ) ;
563576 }
564- _ => ( ) ,
577+ _cmd => {
578+ #[ cfg( feature = "tracing" ) ]
579+ debug ! ( cmd = ?_cmd, "not a hardcoded subcommand; returning to normal handling" ) ;
580+ }
565581 }
566582
583+ #[ cfg( feature = "tracing" ) ]
584+ drop ( hardcoded_span) ;
585+ #[ cfg( feature = "tracing" ) ]
586+ debug ! ( "handling subcommand normally" ) ;
587+
567588 if !self . config . dry_run ( ) {
589+ #[ cfg( feature = "tracing" ) ]
590+ let _real_run_span = span ! ( tracing:: Level :: DEBUG , "executing real run" ) . entered ( ) ;
591+
568592 {
593+ #[ cfg( feature = "tracing" ) ]
594+ let _sanity_check_span =
595+ span ! ( tracing:: Level :: DEBUG , "(1) executing dry-run sanity-check" ) . entered ( ) ;
596+
569597 // We first do a dry-run. This is a sanity-check to ensure that
570598 // steps don't do anything expensive in the dry-run.
571599 self . config . dry_run = DryRun :: SelfCheck ;
572600 let builder = builder:: Builder :: new ( self ) ;
573601 builder. execute_cli ( ) ;
574602 }
603+
604+ #[ cfg( feature = "tracing" ) ]
605+ let _actual_run_span =
606+ span ! ( tracing:: Level :: DEBUG , "(2) executing actual run" ) . entered ( ) ;
575607 self . config . dry_run = DryRun :: Disabled ;
576608 let builder = builder:: Builder :: new ( self ) ;
577609 builder. execute_cli ( ) ;
578610 } else {
611+ #[ cfg( feature = "tracing" ) ]
612+ let _dry_run_span = span ! ( tracing:: Level :: DEBUG , "executing dry run" ) . entered ( ) ;
613+
579614 let builder = builder:: Builder :: new ( self ) ;
580615 builder. execute_cli ( ) ;
581616 }
582617
618+ #[ cfg( feature = "tracing" ) ]
619+ debug ! ( "checking for postponed test failures from `test --no-fail-fast`" ) ;
620+
583621 // Check for postponed failures from `test --no-fail-fast`.
584622 let failures = self . delayed_failures . borrow ( ) ;
585623 if failures. len ( ) > 0 {
0 commit comments