@@ -48,7 +48,10 @@ use std::path::Path;
48
48
use std:: process:: { self , Stdio } ;
49
49
use std:: str;
50
50
use std:: thread;
51
- use std:: time:: Duration ;
51
+ use std:: time:: {
52
+ Duration ,
53
+ Instant ,
54
+ } ;
52
55
use tempdir:: TempDir ;
53
56
54
57
/// Supported compilers.
@@ -171,12 +174,12 @@ pub enum CompileResult {
171
174
/// An error made the compilation not possible.
172
175
Error ,
173
176
/// Result was found in cache.
174
- CacheHit ,
177
+ CacheHit ( Duration ) ,
175
178
/// Result was not found in cache.
176
179
///
177
180
/// The `CacheWriteFuture` will resolve when the result is finished
178
181
/// being stored in the cache.
179
- CacheMiss ( MissType , CacheWriteFuture ) ,
182
+ CacheMiss ( MissType , Duration , CacheWriteFuture ) ,
180
183
/// Not in cache, but the compilation result was determined to be not cacheable.
181
184
NotCacheable ,
182
185
/// Not in cache, but compilation failed.
@@ -189,8 +192,8 @@ impl fmt::Debug for CompileResult {
189
192
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
190
193
match self {
191
194
& CompileResult :: Error => write ! ( f, "CompileResult::Error" ) ,
192
- & CompileResult :: CacheHit => write ! ( f, "CompileResult::CacheHit" ) ,
193
- & CompileResult :: CacheMiss ( ref m, _) => write ! ( f, "CompileResult::CacheMiss({:?}, _)" , m) ,
195
+ & CompileResult :: CacheHit ( ref d ) => write ! ( f, "CompileResult::CacheHit({:?})" , d ) ,
196
+ & CompileResult :: CacheMiss ( ref m, ref d , _) => write ! ( f, "CompileResult::CacheMiss({:?}, {:?}, _)" , d , m) ,
194
197
& CompileResult :: NotCacheable => write ! ( f, "CompileResult::NotCacheable" ) ,
195
198
& CompileResult :: CompileFailed => write ! ( f, "CompileResult::CompileFailed" ) ,
196
199
}
@@ -202,8 +205,8 @@ impl PartialEq<CompileResult> for CompileResult {
202
205
fn eq ( & self , other : & CompileResult ) -> bool {
203
206
match ( self , other) {
204
207
( & CompileResult :: Error , & CompileResult :: Error ) => true ,
205
- ( & CompileResult :: CacheHit , & CompileResult :: CacheHit ) => true ,
206
- ( & CompileResult :: CacheMiss ( ref m, _) , & CompileResult :: CacheMiss ( ref n, _) ) => m == n,
208
+ ( & CompileResult :: CacheHit ( _ ) , & CompileResult :: CacheHit ( _ ) ) => true ,
209
+ ( & CompileResult :: CacheMiss ( ref m, _, _ ) , & CompileResult :: CacheMiss ( ref n, _ , _) ) => m == n,
207
210
( & CompileResult :: NotCacheable , & CompileResult :: NotCacheable ) => true ,
208
211
( & CompileResult :: CompileFailed , & CompileResult :: CompileFailed ) => true ,
209
212
_ => false ,
@@ -294,11 +297,13 @@ impl Compiler {
294
297
. map ( |( key, path) | ( key, pwd. join ( path) ) )
295
298
. collect :: < HashMap < _ , _ > > ( ) ;
296
299
// If `ForceRecache` is enabled, we won't check the cache.
300
+ let start = Instant :: now ( ) ;
297
301
let cache_status = if cache_control == CacheControl :: ForceRecache {
298
302
Cache :: Recache
299
303
} else {
300
304
storage. get ( & key)
301
305
} ;
306
+ let duration = start. elapsed ( ) ;
302
307
match cache_status {
303
308
Cache :: Hit ( mut entry) => {
304
309
debug ! ( "[{}]: Cache hit!" , out_file) ;
@@ -310,7 +315,7 @@ impl Compiler {
310
315
let mut stderr = io:: Cursor :: new ( vec ! ( ) ) ;
311
316
entry. get_object ( "stdout" , & mut stdout) . unwrap_or ( ( ) ) ;
312
317
entry. get_object ( "stderr" , & mut stderr) . unwrap_or ( ( ) ) ;
313
- Ok ( ( CompileResult :: CacheHit ,
318
+ Ok ( ( CompileResult :: CacheHit ( duration ) ,
314
319
process:: Output {
315
320
status : exit_status ( 0 ) ,
316
321
stdout : stdout. into_inner ( ) ,
@@ -330,7 +335,9 @@ impl Compiler {
330
335
Cache :: Hit ( _) => MissType :: Normal ,
331
336
} ;
332
337
let process:: Output { stdout, .. } = preprocessor_result;
338
+ let start = Instant :: now ( ) ;
333
339
let ( cacheable, compiler_result) = try!( self . kind . compile ( creator, self , stdout, parsed_args, cwd) ) ;
340
+ let duration = start. elapsed ( ) ;
334
341
if compiler_result. status . success ( ) {
335
342
if cacheable == Cacheable :: Yes {
336
343
debug ! ( "[{}]: Compiled, storing in cache" , out_file) ;
@@ -363,7 +370,7 @@ impl Compiler {
363
370
duration : duration,
364
371
} )
365
372
} ) . boxed ( ) ;
366
- Ok ( ( CompileResult :: CacheMiss ( miss_type, future) , compiler_result) )
373
+ Ok ( ( CompileResult :: CacheMiss ( miss_type, duration , future) , compiler_result) )
367
374
} else {
368
375
// Not cacheable
369
376
debug ! ( "[{}]: Compiled but not cacheable" , out_file) ;
@@ -507,6 +514,7 @@ mod test {
507
514
use mock_command:: * ;
508
515
use std:: fs:: { self , File } ;
509
516
use std:: io:: Write ;
517
+ use std:: time:: Duration ;
510
518
use std:: usize;
511
519
use test:: utils:: * ;
512
520
@@ -614,7 +622,7 @@ mod test {
614
622
// Ensure that the object file was created.
615
623
assert_eq ! ( true , fs:: metadata( & obj) . and_then( |m| Ok ( m. len( ) > 0 ) ) . unwrap( ) ) ;
616
624
match cached {
617
- CompileResult :: CacheMiss ( MissType :: Normal , f) => {
625
+ CompileResult :: CacheMiss ( MissType :: Normal , _ , f) => {
618
626
// wait on cache write future so we don't race with it!
619
627
f. wait ( ) . unwrap ( ) . unwrap ( ) ;
620
628
}
@@ -631,7 +639,7 @@ mod test {
631
639
let ( cached, res) = c. get_cached_or_compile ( creator. clone ( ) , & storage, & arguments, & parsed_args, cwd, CacheControl :: Default ) . unwrap ( ) ;
632
640
// Ensure that the object file was created.
633
641
assert_eq ! ( true , fs:: metadata( & obj) . and_then( |m| Ok ( m. len( ) > 0 ) ) . unwrap( ) ) ;
634
- assert_eq ! ( CompileResult :: CacheHit , cached) ;
642
+ assert_eq ! ( CompileResult :: CacheHit ( Duration :: new ( 0 , 0 ) ) , cached) ;
635
643
assert_eq ! ( exit_status( 0 ) , res. status) ;
636
644
assert_eq ! ( COMPILER_STDOUT , res. stdout. as_slice( ) ) ;
637
645
assert_eq ! ( COMPILER_STDERR , res. stderr. as_slice( ) ) ;
@@ -676,7 +684,7 @@ mod test {
676
684
// Ensure that the object file was created.
677
685
assert_eq ! ( true , fs:: metadata( & obj) . and_then( |m| Ok ( m. len( ) > 0 ) ) . unwrap( ) ) ;
678
686
match cached {
679
- CompileResult :: CacheMiss ( MissType :: Normal , f) => {
687
+ CompileResult :: CacheMiss ( MissType :: Normal , _ , f) => {
680
688
// wait on cache write future so we don't race with it!
681
689
f. wait ( ) . unwrap ( ) . unwrap ( ) ;
682
690
}
@@ -694,7 +702,7 @@ mod test {
694
702
let ( cached, res) = c. get_cached_or_compile ( creator. clone ( ) , & storage, & arguments, & parsed_args, cwd, CacheControl :: Default ) . unwrap ( ) ;
695
703
// Ensure that the object file was created.
696
704
assert_eq ! ( true , fs:: metadata( & obj) . and_then( |m| Ok ( m. len( ) > 0 ) ) . unwrap( ) ) ;
697
- assert_eq ! ( CompileResult :: CacheHit , cached) ;
705
+ assert_eq ! ( CompileResult :: CacheHit ( Duration :: new ( 0 , 0 ) ) , cached) ;
698
706
assert_eq ! ( exit_status( 0 ) , res. status) ;
699
707
assert_eq ! ( COMPILER_STDOUT , res. stdout. as_slice( ) ) ;
700
708
assert_eq ! ( COMPILER_STDERR , res. stderr. as_slice( ) ) ;
@@ -743,7 +751,7 @@ mod test {
743
751
// Ensure that the object file was created.
744
752
assert_eq ! ( true , fs:: metadata( & obj) . and_then( |m| Ok ( m. len( ) > 0 ) ) . unwrap( ) ) ;
745
753
match cached {
746
- CompileResult :: CacheMiss ( MissType :: Normal , f) => {
754
+ CompileResult :: CacheMiss ( MissType :: Normal , _ , f) => {
747
755
// wait on cache write future so we don't race with it!
748
756
f. wait ( ) . unwrap ( ) . unwrap ( ) ;
749
757
}
@@ -758,7 +766,7 @@ mod test {
758
766
// Ensure that the object file was created.
759
767
assert_eq ! ( true , fs:: metadata( & obj) . and_then( |m| Ok ( m. len( ) > 0 ) ) . unwrap( ) ) ;
760
768
match cached {
761
- CompileResult :: CacheMiss ( MissType :: ForcedRecache , f) => {
769
+ CompileResult :: CacheMiss ( MissType :: ForcedRecache , _ , f) => {
762
770
// wait on cache write future so we don't race with it!
763
771
f. wait ( ) . unwrap ( ) . unwrap ( ) ;
764
772
}
0 commit comments