@@ -75,8 +75,7 @@ pub struct CommandCacheKey {
7575
7676#[ derive( Default , Clone ) ]
7777pub struct CommandProfile {
78- pub count : usize ,
79- pub durations : Vec < Duration > ,
78+ pub exec_traces : Vec < ExecutionTrace > ,
8079}
8180
8281#[ derive( Default ) ]
@@ -85,14 +84,19 @@ pub struct CommandProfiler {
8584}
8685
8786impl CommandProfiler {
88- pub fn record ( & self , key : CommandCacheKey , duration : Duration ) {
87+ pub fn record ( & self , key : CommandCacheKey , exec_trace : ExecutionTrace ) {
8988 let mut stats = self . stats . lock ( ) . unwrap ( ) ;
9089 let entry = stats. entry ( key) . or_default ( ) ;
91- entry. count += 1 ;
92- entry. durations . push ( duration) ;
90+ entry. exec_traces . push ( exec_trace) ;
9391 }
9492}
9593
94+ #[ derive( Clone ) ]
95+ pub enum ExecutionTrace {
96+ CacheHit { timestamp : Instant } ,
97+ Executed { timestamp : Instant , duration : Duration } ,
98+ }
99+
96100/// Wrapper around `std::process::Command`.
97101///
98102/// By default, the command will exit bootstrap if it fails.
@@ -568,7 +572,7 @@ impl ExecutionContext {
568572 if let Some ( cached_output) = self . command_cache . get ( & cache_key) {
569573 command. mark_as_executed ( ) ;
570574 self . verbose ( || println ! ( "Cache hit: {command:?}" ) ) ;
571- self . profiler . record ( cache_key, Duration :: from_secs ( 0 ) ) ;
575+ self . profiler . record ( cache_key, ExecutionTrace :: CacheHit { timestamp : Instant :: now ( ) } ) ;
572576 return DeferredCommand { state : CommandState :: Cached ( cached_output) } ;
573577 }
574578
@@ -716,8 +720,13 @@ impl<'a> DeferredCommand<'a> {
716720 && command. should_cache
717721 {
718722 exec_ctx. command_cache . insert ( cache_key. clone ( ) , output. clone ( ) ) ;
719- let duration = start_time. elapsed ( ) ;
720- exec_ctx. profiler . record ( cache_key. clone ( ) , duration) ;
723+ exec_ctx. profiler . record (
724+ cache_key. clone ( ) ,
725+ ExecutionTrace :: Executed {
726+ timestamp : start_time,
727+ duration : start_time. elapsed ( ) ,
728+ } ,
729+ ) ;
721730 }
722731
723732 output
0 commit comments