@@ -142,7 +142,9 @@ impl CommandProfiler {
142
142
143
143
entries. sort_by ( |a, b| b. 2 . cmp ( & a. 2 ) ) ;
144
144
145
- let mut total_fingerprints = 0 ;
145
+ let total_bootstrap_duration = start_time. elapsed ( ) ;
146
+
147
+ let total_fingerprints = entries. len ( ) ;
146
148
let mut total_cache_hits = 0 ;
147
149
let mut total_execution_duration = Duration :: ZERO ;
148
150
let mut total_saved_duration = Duration :: ZERO ;
@@ -166,32 +168,43 @@ impl CommandProfiler {
166
168
}
167
169
}
168
170
169
- total_fingerprints += 1 ;
170
171
total_cache_hits += hits;
171
172
total_execution_duration += command_total_duration;
173
+ // This makes sense only in our current setup, where:
174
+ // - If caching is enabled, we record the timing for the initial execution,
175
+ // and all subsequent runs will be cache hits.
176
+ // - If caching is disabled or unused, there will be no cache hits,
177
+ // and we'll record timings for all executions.
172
178
total_saved_duration += command_total_duration * hits as u32 ;
173
179
180
+ let command_vs_bootstrap = if total_bootstrap_duration. as_secs_f64 ( ) > 0.0 {
181
+ 100.0 * command_total_duration. as_secs_f64 ( )
182
+ / total_bootstrap_duration. as_secs_f64 ( )
183
+ } else {
184
+ 0.0
185
+ } ;
186
+
174
187
let duration_str = match max_duration {
175
188
Some ( d) => format ! ( "{d:.2?}" ) ,
176
189
None => "-" . into ( ) ,
177
190
} ;
178
191
179
192
writeln ! (
180
193
writer,
181
- "Summary: {runs} run(s), {hits} hit(s), max_duration={duration_str}\n "
194
+ "Summary: {runs} run(s), {hits} hit(s), max_duration={duration_str} total_duration: {command_total_duration:.2?} ({command_vs_bootstrap:.2?}% of total) \n "
182
195
)
183
196
. unwrap ( ) ;
184
197
}
185
198
186
- let total_bootstrap_time = start_time . elapsed ( ) ;
187
- let overhead_time =
188
- total_bootstrap_time . checked_sub ( total_execution_duration ) . unwrap_or ( Duration :: ZERO ) ;
199
+ let overhead_time = total_bootstrap_duration
200
+ . checked_sub ( total_execution_duration )
201
+ . unwrap_or ( Duration :: ZERO ) ;
189
202
190
203
writeln ! ( writer, "\n === Aggregated Summary ===" ) . unwrap ( ) ;
191
204
writeln ! ( writer, "Total unique commands (fingerprints): {total_fingerprints}" ) . unwrap ( ) ;
192
205
writeln ! ( writer, "Total time spent in command executions: {total_execution_duration:.2?}" )
193
206
. unwrap ( ) ;
194
- writeln ! ( writer, "Total bootstrap time: {total_bootstrap_time :.2?}" ) . unwrap ( ) ;
207
+ writeln ! ( writer, "Total bootstrap time: {total_bootstrap_duration :.2?}" ) . unwrap ( ) ;
195
208
writeln ! ( writer, "Time spent outside command executions: {overhead_time:.2?}" ) . unwrap ( ) ;
196
209
writeln ! ( writer, "Total cache hits: {total_cache_hits}" ) . unwrap ( ) ;
197
210
writeln ! ( writer, "Estimated time saved due to cache hits: {total_saved_duration:.2?}" )
@@ -379,7 +392,7 @@ impl<'a> BootstrapCommand {
379
392
}
380
393
}
381
394
382
- pub fn cache_key ( & self ) -> CommandFingerprint {
395
+ pub fn fingerprint ( & self ) -> CommandFingerprint {
383
396
let command = & self . command ;
384
397
CommandFingerprint {
385
398
program : command. get_program ( ) . into ( ) ,
@@ -578,7 +591,7 @@ enum CommandState<'a> {
578
591
stdout : OutputMode ,
579
592
stderr : OutputMode ,
580
593
executed_at : & ' a Location < ' a > ,
581
- cache_key : CommandFingerprint ,
594
+ fingerprint : CommandFingerprint ,
582
595
start_time : Instant ,
583
596
} ,
584
597
}
@@ -587,7 +600,7 @@ pub struct StreamingCommand {
587
600
child : Child ,
588
601
pub stdout : Option < ChildStdout > ,
589
602
pub stderr : Option < ChildStderr > ,
590
- cache_key : CommandFingerprint ,
603
+ fingerprint : CommandFingerprint ,
591
604
start_time : Instant ,
592
605
}
593
606
@@ -678,12 +691,12 @@ impl ExecutionContext {
678
691
stdout : OutputMode ,
679
692
stderr : OutputMode ,
680
693
) -> DeferredCommand < ' a > {
681
- let cache_key = command. cache_key ( ) ;
694
+ let fingerprint = command. fingerprint ( ) ;
682
695
683
- if let Some ( cached_output) = self . command_cache . get ( & cache_key ) {
696
+ if let Some ( cached_output) = self . command_cache . get ( & fingerprint ) {
684
697
command. mark_as_executed ( ) ;
685
698
self . verbose ( || println ! ( "Cache hit: {command:?}" ) ) ;
686
- self . profiler . record_cache_hit ( cache_key ) ;
699
+ self . profiler . record_cache_hit ( fingerprint ) ;
687
700
return DeferredCommand { state : CommandState :: Cached ( cached_output) } ;
688
701
}
689
702
@@ -698,7 +711,7 @@ impl ExecutionContext {
698
711
stdout,
699
712
stderr,
700
713
executed_at,
701
- cache_key ,
714
+ fingerprint ,
702
715
start_time : Instant :: now ( ) ,
703
716
} ,
704
717
} ;
@@ -726,7 +739,7 @@ impl ExecutionContext {
726
739
stdout,
727
740
stderr,
728
741
executed_at,
729
- cache_key ,
742
+ fingerprint ,
730
743
start_time,
731
744
} ,
732
745
}
@@ -782,7 +795,7 @@ impl ExecutionContext {
782
795
return None ;
783
796
}
784
797
let start_time = Instant :: now ( ) ;
785
- let cache_key = command. cache_key ( ) ;
798
+ let fingerprint = command. fingerprint ( ) ;
786
799
let cmd = & mut command. command ;
787
800
cmd. stdout ( stdout. stdio ( ) ) ;
788
801
cmd. stderr ( stderr. stdio ( ) ) ;
@@ -794,7 +807,7 @@ impl ExecutionContext {
794
807
795
808
let stdout = child. stdout . take ( ) ;
796
809
let stderr = child. stderr . take ( ) ;
797
- Some ( StreamingCommand { child, stdout, stderr, cache_key , start_time } )
810
+ Some ( StreamingCommand { child, stdout, stderr, fingerprint , start_time } )
798
811
}
799
812
}
800
813
@@ -811,7 +824,7 @@ impl StreamingCommand {
811
824
) -> Result < ExitStatus , std:: io:: Error > {
812
825
let exec_ctx = exec_ctx. as_ref ( ) ;
813
826
let output = self . child . wait ( ) ;
814
- exec_ctx. profiler ( ) . record_execution ( self . cache_key , self . start_time ) ;
827
+ exec_ctx. profiler ( ) . record_execution ( self . fingerprint , self . start_time ) ;
815
828
output
816
829
}
817
830
}
@@ -826,7 +839,7 @@ impl<'a> DeferredCommand<'a> {
826
839
stdout,
827
840
stderr,
828
841
executed_at,
829
- cache_key ,
842
+ fingerprint ,
830
843
start_time,
831
844
} => {
832
845
let exec_ctx = exec_ctx. as_ref ( ) ;
@@ -838,8 +851,8 @@ impl<'a> DeferredCommand<'a> {
838
851
&& output. status ( ) . is_some ( )
839
852
&& command. should_cache
840
853
{
841
- exec_ctx. command_cache . insert ( cache_key . clone ( ) , output. clone ( ) ) ;
842
- exec_ctx. profiler . record_execution ( cache_key . clone ( ) , start_time) ;
854
+ exec_ctx. command_cache . insert ( fingerprint . clone ( ) , output. clone ( ) ) ;
855
+ exec_ctx. profiler . record_execution ( fingerprint . clone ( ) , start_time) ;
843
856
}
844
857
845
858
output
0 commit comments