@@ -20,7 +20,7 @@ use std::process::{
20
20
Child , ChildStderr , ChildStdout , Command , CommandArgs , CommandEnvs , ExitStatus , Output , Stdio ,
21
21
} ;
22
22
use std:: sync:: { Arc , Mutex } ;
23
- use std:: time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
23
+ use std:: time:: { Duration , Instant } ;
24
24
25
25
use build_helper:: ci:: CiEnv ;
26
26
use build_helper:: drop_bomb:: DropBomb ;
@@ -100,19 +100,16 @@ impl CommandProfiler {
100
100
pub fn record_execution ( & self , key : CommandFingerprint , start_time : Instant ) {
101
101
let mut stats = self . stats . lock ( ) . unwrap ( ) ;
102
102
let entry = stats. entry ( key) . or_default ( ) ;
103
- entry. traces . push ( ExecutionTrace :: Executed {
104
- timestamp : SystemTime :: now ( ) ,
105
- duration : start_time. elapsed ( ) ,
106
- } ) ;
103
+ entry. traces . push ( ExecutionTrace :: Executed { duration : start_time. elapsed ( ) } ) ;
107
104
}
108
105
109
106
pub fn record_cache_hit ( & self , key : CommandFingerprint ) {
110
107
let mut stats = self . stats . lock ( ) . unwrap ( ) ;
111
108
let entry = stats. entry ( key) . or_default ( ) ;
112
- entry. traces . push ( ExecutionTrace :: CacheHit { timestamp : SystemTime :: now ( ) } ) ;
109
+ entry. traces . push ( ExecutionTrace :: CacheHit ) ;
113
110
}
114
111
115
- pub fn report_summary ( & self ) {
112
+ pub fn report_summary ( & self , start_time : Instant ) {
116
113
let pid = process:: id ( ) ;
117
114
let filename = format ! ( "bootstrap-profile-{pid}.txt" ) ;
118
115
@@ -145,28 +142,35 @@ impl CommandProfiler {
145
142
146
143
entries. sort_by ( |a, b| b. 2 . cmp ( & a. 2 ) ) ;
147
144
148
- for ( key, profile, max_duration) in entries {
145
+ let mut total_fingerprints = 0 ;
146
+ let mut total_cache_hits = 0 ;
147
+ let mut total_execution_duration = Duration :: ZERO ;
148
+ let mut total_saved_duration = Duration :: ZERO ;
149
+
150
+ for ( key, profile, max_duration) in & entries {
149
151
writeln ! ( writer, "Command: {:?}" , key. format_short_cmd( ) ) . unwrap ( ) ;
150
152
151
153
let mut hits = 0 ;
152
154
let mut runs = 0 ;
155
+ let mut command_total_duration = Duration :: ZERO ;
153
156
154
157
for trace in & profile. traces {
155
158
match trace {
156
- ExecutionTrace :: CacheHit { timestamp } => {
159
+ ExecutionTrace :: CacheHit => {
157
160
hits += 1 ;
158
- let time = timestamp. duration_since ( UNIX_EPOCH ) . unwrap ( ) ;
159
- writeln ! ( writer, " - Cache hit at: {time:?}" ) . unwrap ( ) ;
160
161
}
161
- ExecutionTrace :: Executed { duration, timestamp } => {
162
+ ExecutionTrace :: Executed { duration, .. } => {
162
163
runs += 1 ;
163
- let time = timestamp. duration_since ( UNIX_EPOCH ) . unwrap ( ) ;
164
- writeln ! ( writer, " - Executed at: {time:?}, duration: {duration:.2?}" )
165
- . unwrap ( ) ;
164
+ command_total_duration += * duration;
166
165
}
167
166
}
168
167
}
169
168
169
+ total_fingerprints += 1 ;
170
+ total_cache_hits += hits;
171
+ total_execution_duration += command_total_duration;
172
+ total_saved_duration += command_total_duration * hits as u32 ;
173
+
170
174
let duration_str = match max_duration {
171
175
Some ( d) => format ! ( "{d:.2?}" ) ,
172
176
None => "-" . into ( ) ,
@@ -179,14 +183,29 @@ impl CommandProfiler {
179
183
. unwrap ( ) ;
180
184
}
181
185
186
+ // Add aggregated summary
187
+ let total_bootstrap_time = start_time. elapsed ( ) ;
188
+ let overhead_time =
189
+ total_bootstrap_time. checked_sub ( total_execution_duration) . unwrap_or ( Duration :: ZERO ) ;
190
+
191
+ writeln ! ( writer, "\n === Aggregated Summary ===" ) . unwrap ( ) ;
192
+ writeln ! ( writer, "Total unique commands (fingerprints): {total_fingerprints}" ) . unwrap ( ) ;
193
+ writeln ! ( writer, "Total time spent in command executions: {total_execution_duration:.2?}" )
194
+ . unwrap ( ) ;
195
+ writeln ! ( writer, "Total bootstrap time: {total_bootstrap_time:.2?}" ) . unwrap ( ) ;
196
+ writeln ! ( writer, "Time spent outside command executions: {overhead_time:.2?}" ) . unwrap ( ) ;
197
+ writeln ! ( writer, "Total cache hits: {total_cache_hits}" ) . unwrap ( ) ;
198
+ writeln ! ( writer, "Estimated time saved due to cache hits: {total_saved_duration:.2?}" )
199
+ . unwrap ( ) ;
200
+
182
201
println ! ( "Command profiler report saved to {filename}" ) ;
183
202
}
184
203
}
185
204
186
205
#[ derive( Clone ) ]
187
206
pub enum ExecutionTrace {
188
- CacheHit { timestamp : SystemTime } ,
189
- Executed { timestamp : SystemTime , duration : Duration } ,
207
+ CacheHit ,
208
+ Executed { duration : Duration } ,
190
209
}
191
210
192
211
/// Wrapper around `std::process::Command`.
0 commit comments