@@ -16,6 +16,7 @@ use super::job::{
1616 Freshness :: { self , Dirty , Fresh } ,
1717 Job ,
1818} ;
19+ use super :: timings:: Timings ;
1920use super :: { BuildContext , BuildPlan , CompileMode , Context , Unit } ;
2021use crate :: core:: { PackageId , TargetKind } ;
2122use crate :: handle_error;
@@ -41,6 +42,7 @@ pub struct JobQueue<'a, 'cfg> {
4142 is_release : bool ,
4243 progress : Progress < ' cfg > ,
4344 next_id : u32 ,
45+ timings : Timings < ' a , ' cfg > ,
4446}
4547
4648pub struct JobState < ' a > {
@@ -82,7 +84,7 @@ enum Artifact {
8284}
8385
8486enum Message {
85- Run ( String ) ,
87+ Run ( u32 , String ) ,
8688 BuildPlanMsg ( String , ProcessBuilder , Arc < Vec < OutputFile > > ) ,
8789 Stdout ( String ) ,
8890 Stderr ( String ) ,
@@ -93,7 +95,7 @@ enum Message {
9395
9496impl < ' a > JobState < ' a > {
9597 pub fn running ( & self , cmd : & ProcessBuilder ) {
96- let _ = self . tx . send ( Message :: Run ( cmd. to_string ( ) ) ) ;
98+ let _ = self . tx . send ( Message :: Run ( self . id , cmd. to_string ( ) ) ) ;
9799 }
98100
99101 pub fn build_plan (
@@ -121,7 +123,6 @@ impl<'a> JobState<'a> {
121123 /// This should only be called once because a metadata file can only be
122124 /// produced once!
123125 pub fn rmeta_produced ( & self ) {
124- assert ! ( self . rmeta_required. get( ) ) ;
125126 self . rmeta_required . set ( false ) ;
126127 let _ = self
127128 . tx
@@ -130,9 +131,10 @@ impl<'a> JobState<'a> {
130131}
131132
132133impl < ' a , ' cfg > JobQueue < ' a , ' cfg > {
133- pub fn new ( bcx : & BuildContext < ' a , ' cfg > ) -> JobQueue < ' a , ' cfg > {
134+ pub fn new ( bcx : & BuildContext < ' a , ' cfg > , root_units : & [ Unit < ' a > ] ) -> JobQueue < ' a , ' cfg > {
134135 let ( tx, rx) = channel ( ) ;
135136 let progress = Progress :: with_style ( "Building" , ProgressStyle :: Ratio , bcx. config ) ;
137+ let timings = Timings :: new ( bcx, root_units) ;
136138 JobQueue {
137139 queue : DependencyQueue :: new ( ) ,
138140 tx,
@@ -144,6 +146,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
144146 is_release : bcx. build_config . release ,
145147 progress,
146148 next_id : 0 ,
149+ timings,
147150 }
148151 }
149152
@@ -318,6 +321,9 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
318321 // to the jobserver itself.
319322 tokens. truncate ( self . active . len ( ) - 1 ) ;
320323
324+ self . timings
325+ . mark_concurrency ( self . active . len ( ) , queue. len ( ) , self . queue . len ( ) ) ;
326+
321327 // Drain all events at once to avoid displaying the progress bar
322328 // unnecessarily.
323329 let events: Vec < _ > = self . rx . try_iter ( ) . collect ( ) ;
@@ -330,18 +336,18 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
330336
331337 for event in events {
332338 match event {
333- Message :: Run ( cmd) => {
339+ Message :: Run ( id , cmd) => {
334340 cx. bcx
335341 . config
336342 . shell ( )
337343 . verbose ( |c| c. status ( "Running" , & cmd) ) ?;
344+ self . timings . unit_start ( id, self . active [ & id] ) ;
338345 }
339346 Message :: BuildPlanMsg ( module_name, cmd, filenames) => {
340347 plan. update ( & module_name, & cmd, & filenames) ?;
341348 }
342349 Message :: Stdout ( out) => {
343- self . progress . clear ( ) ;
344- println ! ( "{}" , out) ;
350+ cx. bcx . config . shell ( ) . stdout_println ( out) ;
345351 }
346352 Message :: Stderr ( err) => {
347353 let mut shell = cx. bcx . config . shell ( ) ;
@@ -369,7 +375,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
369375 } ;
370376 info ! ( "end ({:?}): {:?}" , unit, result) ;
371377 match result {
372- Ok ( ( ) ) => self . finish ( & unit, artifact, cx) ?,
378+ Ok ( ( ) ) => self . finish ( id , & unit, artifact, cx) ?,
373379 Err ( e) => {
374380 let msg = "The following warnings were emitted during compilation:" ;
375381 self . emit_warnings ( Some ( msg) , & unit, cx) ?;
@@ -427,6 +433,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
427433 if !cx. bcx . build_config . build_plan {
428434 cx. bcx . config . shell ( ) . status ( "Finished" , message) ?;
429435 }
436+ self . timings . finished ( ) ?;
430437 Ok ( ( ) )
431438 } else {
432439 debug ! ( "queue: {:#?}" , self . queue) ;
@@ -542,8 +549,12 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
542549 }
543550
544551 match fresh {
545- Freshness :: Fresh => doit ( ) ,
552+ Freshness :: Fresh => {
553+ self . timings . add_fresh ( ) ;
554+ doit ( )
555+ }
546556 Freshness :: Dirty => {
557+ self . timings . add_dirty ( ) ;
547558 scope. spawn ( move |_| doit ( ) ) ;
548559 }
549560 }
@@ -581,14 +592,19 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
581592
582593 fn finish (
583594 & mut self ,
595+ id : u32 ,
584596 unit : & Unit < ' a > ,
585597 artifact : Artifact ,
586598 cx : & mut Context < ' _ , ' _ > ,
587599 ) -> CargoResult < ( ) > {
588600 if unit. mode . is_run_custom_build ( ) && cx. bcx . show_warnings ( unit. pkg . package_id ( ) ) {
589601 self . emit_warnings ( None , unit, cx) ?;
590602 }
591- self . queue . finish ( unit, & artifact) ;
603+ let unlocked = self . queue . finish ( unit, & artifact) ;
604+ match artifact {
605+ Artifact :: All => self . timings . unit_finished ( id, unlocked) ,
606+ Artifact :: Metadata => self . timings . unit_rmeta_finished ( id, unlocked) ,
607+ }
592608 Ok ( ( ) )
593609 }
594610
0 commit comments