@@ -29,7 +29,7 @@ use std::path::Path;
2929use std:: sync:: Arc ;
3030use std:: time:: Instant ;
3131use tokio:: runtime:: Runtime ;
32- use tracing:: { debug, info, warn} ;
32+ use tracing:: { debug, info, info_span , instrument , warn} ;
3333
3434const USER_AGENT : & str = "docs.rs builder (https://github.com/rust-lang/docs.rs)" ;
3535const COMPONENTS : & [ & str ] = & [ "llvm-tools-preview" , "rustc-dev" , "rustfmt" ] ;
@@ -75,6 +75,7 @@ fn build_workspace(context: &dyn Context) -> Result<Workspace> {
7575 Ok ( workspace)
7676}
7777
78+ #[ derive( Debug ) ]
7879pub enum PackageKind < ' a > {
7980 Local ( & ' a Path ) ,
8081 CratesIo ,
@@ -130,6 +131,7 @@ impl RustwideBuilder {
130131 Ok ( ( ) )
131132 }
132133
134+ #[ instrument( skip( self ) ) ]
133135 fn prepare_sandbox ( & self , limits : & Limits ) -> SandboxBuilder {
134136 SandboxBuilder :: new ( )
135137 . cpu_limit ( self . config . build_cpu_limit . map ( |limit| limit as f32 ) )
@@ -257,6 +259,7 @@ impl RustwideBuilder {
257259 }
258260 }
259261
262+ #[ instrument( skip( self ) ) ]
260263 fn get_limits ( & self , krate : & str ) -> Result < Limits > {
261264 self . runtime . block_on ( {
262265 let db = self . db . clone ( ) ;
@@ -358,6 +361,7 @@ impl RustwideBuilder {
358361 self . build_package ( & package. name , & package. version , PackageKind :: Local ( path) )
359362 }
360363
364+ #[ instrument( name = "docbuilder.build_package" , parent = None , skip( self ) ) ]
361365 pub fn build_package (
362366 & mut self ,
363367 name : & str ,
@@ -403,21 +407,29 @@ impl RustwideBuilder {
403407 // fill up disk space.
404408 // This also prevents having multiple builders using the same rustwide workspace,
405409 // which we don't do. Currently our separate builders use a separate rustwide workspace.
406- self . workspace
407- . purge_all_build_dirs ( )
408- . map_err ( FailureError :: compat) ?;
410+ {
411+ let _span = info_span ! ( "purge_all_build_dirs" ) . entered ( ) ;
412+ self . workspace
413+ . purge_all_build_dirs ( )
414+ . map_err ( FailureError :: compat) ?;
415+ }
409416
410417 let mut build_dir = self . workspace . build_dir ( & format ! ( "{name}-{version}" ) ) ;
411418
412419 let is_local = matches ! ( kind, PackageKind :: Local ( _) ) ;
413- let krate = match kind {
414- PackageKind :: Local ( path) => Crate :: local ( path) ,
415- PackageKind :: CratesIo => Crate :: crates_io ( name, version) ,
416- PackageKind :: Registry ( registry) => {
417- Crate :: registry ( AlternativeRegistry :: new ( registry) , name, version)
418- }
420+ let krate = {
421+ let _span = info_span ! ( "krate.fetch" ) . entered ( ) ;
422+
423+ let krate = match kind {
424+ PackageKind :: Local ( path) => Crate :: local ( path) ,
425+ PackageKind :: CratesIo => Crate :: crates_io ( name, version) ,
426+ PackageKind :: Registry ( registry) => {
427+ Crate :: registry ( AlternativeRegistry :: new ( registry) , name, version)
428+ }
429+ } ;
430+ krate. fetch ( & self . workspace ) . map_err ( FailureError :: compat) ?;
431+ krate
419432 } ;
420- krate. fetch ( & self . workspace ) . map_err ( FailureError :: compat) ?;
421433
422434 fs:: create_dir_all ( & self . config . temp_dir ) ?;
423435 let local_storage = tempfile:: tempdir_in ( & self . config . temp_dir ) ?;
@@ -432,8 +444,12 @@ impl RustwideBuilder {
432444 } = metadata. targets ( self . config . include_default_targets ) ;
433445 let mut targets = vec ! [ default_target] ;
434446 targets. extend ( & other_targets) ;
435- // Fetch this before we enter the sandbox, so networking isn't blocked.
436- build. fetch_build_std_dependencies ( & targets) ?;
447+
448+ {
449+ let _span = info_span ! ( "fetch_build_std_dependencies" ) . entered ( ) ;
450+ // Fetch this before we enter the sandbox, so networking isn't blocked.
451+ build. fetch_build_std_dependencies ( & targets) ?;
452+ }
437453
438454 ( || -> Result < bool > {
439455 let mut has_docs = false ;
@@ -448,14 +464,20 @@ impl RustwideBuilder {
448464 if !res. result . successful && cargo_lock. exists ( ) {
449465 info ! ( "removing lockfile and reattempting build" ) ;
450466 std:: fs:: remove_file ( cargo_lock) ?;
451- Command :: new ( & self . workspace , self . toolchain . cargo ( ) )
452- . cd ( build. host_source_dir ( ) )
453- . args ( & [ "generate-lockfile" ] )
454- . run ( ) ?;
455- Command :: new ( & self . workspace , self . toolchain . cargo ( ) )
456- . cd ( build. host_source_dir ( ) )
457- . args ( & [ "fetch" , "--locked" ] )
458- . run ( ) ?;
467+ {
468+ let _span = info_span ! ( "cargo_generate_lockfile" ) . entered ( ) ;
469+ Command :: new ( & self . workspace , self . toolchain . cargo ( ) )
470+ . cd ( build. host_source_dir ( ) )
471+ . args ( & [ "generate-lockfile" ] )
472+ . run ( ) ?;
473+ }
474+ {
475+ let _span = info_span ! ( "cargo fetch --locked" ) . entered ( ) ;
476+ Command :: new ( & self . workspace , self . toolchain . cargo ( ) )
477+ . cd ( build. host_source_dir ( ) )
478+ . args ( & [ "fetch" , "--locked" ] )
479+ . run ( ) ?;
480+ }
459481 res = self . execute_build (
460482 default_target,
461483 true ,
@@ -595,11 +617,14 @@ impl RustwideBuilder {
595617 build_status,
596618 ) ) ?;
597619
598- let build_log_path = format ! ( "build-logs/{build_id}/{default_target}.txt" ) ;
599- self . storage . store_one ( build_log_path, res. build_log ) ?;
600- for ( target, log) in target_build_logs {
601- let build_log_path = format ! ( "build-logs/{build_id}/{target}.txt" ) ;
602- self . storage . store_one ( build_log_path, log) ?;
620+ {
621+ let _span = info_span ! ( "store_build_logs" ) . entered ( ) ;
622+ let build_log_path = format ! ( "build-logs/{build_id}/{default_target}.txt" ) ;
623+ self . storage . store_one ( build_log_path, res. build_log ) ?;
624+ for ( target, log) in target_build_logs {
625+ let build_log_path = format ! ( "build-logs/{build_id}/{target}.txt" ) ;
626+ self . storage . store_one ( build_log_path, log) ?;
627+ }
603628 }
604629
605630 // Some crates.io crate data is mutable, so we proactively update it during a release
@@ -638,13 +663,17 @@ impl RustwideBuilder {
638663 } )
639664 . map_err ( |e| e. compat ( ) ) ?;
640665
641- krate
642- . purge_from_cache ( & self . workspace )
643- . map_err ( FailureError :: compat) ?;
644- local_storage. close ( ) ?;
666+ {
667+ let _span = info_span ! ( "purge_from_cache" ) . entered ( ) ;
668+ krate
669+ . purge_from_cache ( & self . workspace )
670+ . map_err ( FailureError :: compat) ?;
671+ local_storage. close ( ) ?;
672+ }
645673 Ok ( successful)
646674 }
647675
676+ #[ instrument( skip( self , build) ) ]
648677 fn build_target (
649678 & self ,
650679 target : & str ,
@@ -668,6 +697,7 @@ impl RustwideBuilder {
668697 Ok ( target_res)
669698 }
670699
700+ #[ instrument( skip( self , build) ) ]
671701 fn get_coverage (
672702 & self ,
673703 target : & str ,
@@ -723,6 +753,7 @@ impl RustwideBuilder {
723753 )
724754 }
725755
756+ #[ instrument( skip( self , build) ) ]
726757 fn execute_build (
727758 & self ,
728759 target : & str ,
@@ -764,11 +795,14 @@ impl RustwideBuilder {
764795 }
765796 } ;
766797
767- let successful = logging:: capture ( & storage, || {
768- self . prepare_command ( build, target, metadata, limits, rustdoc_flags)
769- . and_then ( |command| command. run ( ) . map_err ( Error :: from) )
770- . is_ok ( )
771- } ) ;
798+ let successful = {
799+ let _span = info_span ! ( "cargo_build" , target = %target, is_default_target) . entered ( ) ;
800+ logging:: capture ( & storage, || {
801+ self . prepare_command ( build, target, metadata, limits, rustdoc_flags)
802+ . and_then ( |command| command. run ( ) . map_err ( Error :: from) )
803+ . is_ok ( )
804+ } )
805+ } ;
772806
773807 // For proc-macros, cargo will put the output in `target/doc`.
774808 // Move it to the target-specific directory for consistency with other builds.
@@ -879,6 +913,7 @@ impl RustwideBuilder {
879913 Ok ( command. args ( & cargo_args) )
880914 }
881915
916+ #[ instrument( skip( self ) ) ]
882917 fn copy_docs (
883918 & self ,
884919 target_dir : & Path ,
@@ -917,7 +952,7 @@ struct FullBuildResult {
917952 build_log : String ,
918953}
919954
920- #[ derive( Clone , Copy ) ]
955+ #[ derive( Debug , Clone , Copy ) ]
921956pub ( crate ) struct DocCoverage {
922957 /// The total items that could be documented in the current crate, used to calculate
923958 /// documentation coverage.
@@ -931,6 +966,7 @@ pub(crate) struct DocCoverage {
931966 pub ( crate ) items_with_examples : i32 ,
932967}
933968
969+ #[ derive( Debug ) ]
934970pub ( crate ) struct BuildResult {
935971 pub ( crate ) rustc_version : String ,
936972 pub ( crate ) docsrs_version : String ,
0 commit comments