@@ -75,8 +75,7 @@ pub struct CommandCacheKey {
75
75
76
76
#[ derive( Default , Clone ) ]
77
77
pub struct CommandProfile {
78
- pub count : usize ,
79
- pub durations : Vec < Duration > ,
78
+ pub exec_traces : Vec < ExecutionTrace > ,
80
79
}
81
80
82
81
#[ derive( Default ) ]
@@ -85,14 +84,19 @@ pub struct CommandProfiler {
85
84
}
86
85
87
86
impl CommandProfiler {
88
- pub fn record ( & self , key : CommandCacheKey , duration : Duration ) {
87
+ pub fn record ( & self , key : CommandCacheKey , exec_trace : ExecutionTrace ) {
89
88
let mut stats = self . stats . lock ( ) . unwrap ( ) ;
90
89
let entry = stats. entry ( key) . or_default ( ) ;
91
- entry. count += 1 ;
92
- entry. durations . push ( duration) ;
90
+ entry. exec_traces . push ( exec_trace) ;
93
91
}
94
92
}
95
93
94
+ #[ derive( Clone ) ]
95
+ pub enum ExecutionTrace {
96
+ CacheHit { timestamp : Instant } ,
97
+ Executed { timestamp : Instant , duration : Duration } ,
98
+ }
99
+
96
100
/// Wrapper around `std::process::Command`.
97
101
///
98
102
/// By default, the command will exit bootstrap if it fails.
@@ -568,7 +572,7 @@ impl ExecutionContext {
568
572
if let Some ( cached_output) = self . command_cache . get ( & cache_key) {
569
573
command. mark_as_executed ( ) ;
570
574
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 ( ) } ) ;
572
576
return DeferredCommand { state : CommandState :: Cached ( cached_output) } ;
573
577
}
574
578
@@ -716,8 +720,13 @@ impl<'a> DeferredCommand<'a> {
716
720
&& command. should_cache
717
721
{
718
722
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
+ ) ;
721
730
}
722
731
723
732
output
0 commit comments