@@ -16,6 +16,7 @@ use super::job::{
16
16
Freshness :: { self , Dirty , Fresh } ,
17
17
Job ,
18
18
} ;
19
+ use super :: timings:: Timings ;
19
20
use super :: { BuildContext , BuildPlan , CompileMode , Context , Unit } ;
20
21
use crate :: core:: { PackageId , TargetKind } ;
21
22
use crate :: handle_error;
@@ -41,6 +42,7 @@ pub struct JobQueue<'a, 'cfg> {
41
42
is_release : bool ,
42
43
progress : Progress < ' cfg > ,
43
44
next_id : u32 ,
45
+ timings : Timings < ' a , ' cfg > ,
44
46
}
45
47
46
48
pub struct JobState < ' a > {
@@ -82,7 +84,7 @@ enum Artifact {
82
84
}
83
85
84
86
enum Message {
85
- Run ( String ) ,
87
+ Run ( u32 , String ) ,
86
88
BuildPlanMsg ( String , ProcessBuilder , Arc < Vec < OutputFile > > ) ,
87
89
Stdout ( String ) ,
88
90
Stderr ( String ) ,
@@ -93,7 +95,7 @@ enum Message {
93
95
94
96
impl < ' a > JobState < ' a > {
95
97
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 ( ) ) ) ;
97
99
}
98
100
99
101
pub fn build_plan (
@@ -121,7 +123,6 @@ impl<'a> JobState<'a> {
121
123
/// This should only be called once because a metadata file can only be
122
124
/// produced once!
123
125
pub fn rmeta_produced ( & self ) {
124
- assert ! ( self . rmeta_required. get( ) ) ;
125
126
self . rmeta_required . set ( false ) ;
126
127
let _ = self
127
128
. tx
@@ -130,9 +131,10 @@ impl<'a> JobState<'a> {
130
131
}
131
132
132
133
impl < ' 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 > {
134
135
let ( tx, rx) = channel ( ) ;
135
136
let progress = Progress :: with_style ( "Building" , ProgressStyle :: Ratio , bcx. config ) ;
137
+ let timings = Timings :: new ( bcx, root_units) ;
136
138
JobQueue {
137
139
queue : DependencyQueue :: new ( ) ,
138
140
tx,
@@ -144,6 +146,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
144
146
is_release : bcx. build_config . release ,
145
147
progress,
146
148
next_id : 0 ,
149
+ timings,
147
150
}
148
151
}
149
152
@@ -318,6 +321,9 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
318
321
// to the jobserver itself.
319
322
tokens. truncate ( self . active . len ( ) - 1 ) ;
320
323
324
+ self . timings
325
+ . mark_concurrency ( self . active . len ( ) , queue. len ( ) , self . queue . len ( ) ) ;
326
+
321
327
// Drain all events at once to avoid displaying the progress bar
322
328
// unnecessarily.
323
329
let events: Vec < _ > = self . rx . try_iter ( ) . collect ( ) ;
@@ -330,18 +336,18 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
330
336
331
337
for event in events {
332
338
match event {
333
- Message :: Run ( cmd) => {
339
+ Message :: Run ( id , cmd) => {
334
340
cx. bcx
335
341
. config
336
342
. shell ( )
337
343
. verbose ( |c| c. status ( "Running" , & cmd) ) ?;
344
+ self . timings . unit_start ( id, self . active [ & id] ) ;
338
345
}
339
346
Message :: BuildPlanMsg ( module_name, cmd, filenames) => {
340
347
plan. update ( & module_name, & cmd, & filenames) ?;
341
348
}
342
349
Message :: Stdout ( out) => {
343
- self . progress . clear ( ) ;
344
- println ! ( "{}" , out) ;
350
+ cx. bcx . config . shell ( ) . stdout_println ( out) ;
345
351
}
346
352
Message :: Stderr ( err) => {
347
353
let mut shell = cx. bcx . config . shell ( ) ;
@@ -369,7 +375,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
369
375
} ;
370
376
info ! ( "end ({:?}): {:?}" , unit, result) ;
371
377
match result {
372
- Ok ( ( ) ) => self . finish ( & unit, artifact, cx) ?,
378
+ Ok ( ( ) ) => self . finish ( id , & unit, artifact, cx) ?,
373
379
Err ( e) => {
374
380
let msg = "The following warnings were emitted during compilation:" ;
375
381
self . emit_warnings ( Some ( msg) , & unit, cx) ?;
@@ -427,6 +433,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
427
433
if !cx. bcx . build_config . build_plan {
428
434
cx. bcx . config . shell ( ) . status ( "Finished" , message) ?;
429
435
}
436
+ self . timings . finished ( ) ?;
430
437
Ok ( ( ) )
431
438
} else {
432
439
debug ! ( "queue: {:#?}" , self . queue) ;
@@ -542,8 +549,12 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
542
549
}
543
550
544
551
match fresh {
545
- Freshness :: Fresh => doit ( ) ,
552
+ Freshness :: Fresh => {
553
+ self . timings . add_fresh ( ) ;
554
+ doit ( )
555
+ }
546
556
Freshness :: Dirty => {
557
+ self . timings . add_dirty ( ) ;
547
558
scope. spawn ( move |_| doit ( ) ) ;
548
559
}
549
560
}
@@ -581,14 +592,19 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
581
592
582
593
fn finish (
583
594
& mut self ,
595
+ id : u32 ,
584
596
unit : & Unit < ' a > ,
585
597
artifact : Artifact ,
586
598
cx : & mut Context < ' _ , ' _ > ,
587
599
) -> CargoResult < ( ) > {
588
600
if unit. mode . is_run_custom_build ( ) && cx. bcx . show_warnings ( unit. pkg . package_id ( ) ) {
589
601
self . emit_warnings ( None , unit, cx) ?;
590
602
}
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
+ }
592
608
Ok ( ( ) )
593
609
}
594
610
0 commit comments