@@ -5,7 +5,7 @@ mod jobs;
5
5
mod metrics;
6
6
mod utils;
7
7
8
- use std:: collections:: BTreeMap ;
8
+ use std:: collections:: { BTreeMap , HashMap } ;
9
9
use std:: path:: { Path , PathBuf } ;
10
10
use std:: process:: Command ;
11
11
@@ -18,7 +18,7 @@ use crate::analysis::output_test_diffs;
18
18
use crate :: cpu_usage:: load_cpu_usage;
19
19
use crate :: datadog:: upload_datadog_metric;
20
20
use crate :: jobs:: RunType ;
21
- use crate :: metrics:: { download_auto_job_metrics, load_metrics} ;
21
+ use crate :: metrics:: { JobMetrics , download_auto_job_metrics, download_job_metrics , load_metrics} ;
22
22
use crate :: utils:: load_env_var;
23
23
use analysis:: output_bootstrap_stats;
24
24
@@ -138,6 +138,27 @@ fn upload_ci_metrics(cpu_usage_csv: &Path) -> anyhow::Result<()> {
138
138
Ok ( ( ) )
139
139
}
140
140
141
+ fn postprocess_metrics (
142
+ metrics_path : PathBuf ,
143
+ parent : Option < String > ,
144
+ job_name : Option < String > ,
145
+ ) -> anyhow:: Result < ( ) > {
146
+ let metrics = load_metrics ( & metrics_path) ?;
147
+ output_bootstrap_stats ( & metrics) ;
148
+
149
+ let ( Some ( parent) , Some ( job_name) ) = ( parent, job_name) else {
150
+ return Ok ( ( ) ) ;
151
+ } ;
152
+
153
+ let parent_metrics =
154
+ download_job_metrics ( & job_name, & parent) . context ( "cannot download parent metrics" ) ?;
155
+ let job_metrics =
156
+ HashMap :: from ( [ ( job_name, JobMetrics { parent : Some ( parent_metrics) , current : metrics } ) ] ) ;
157
+ output_test_diffs ( job_metrics) ;
158
+
159
+ Ok ( ( ) )
160
+ }
161
+
141
162
#[ derive( clap:: Parser ) ]
142
163
enum Args {
143
164
/// Calculate a list of jobs that should be executed on CI.
@@ -155,10 +176,19 @@ enum Args {
155
176
#[ clap( long = "type" , default_value = "auto" ) ]
156
177
job_type : JobType ,
157
178
} ,
158
- /// Postprocess the metrics.json file generated by bootstrap.
179
+ /// Postprocess the metrics.json file generated by bootstrap and output
180
+ /// various statistics.
181
+ /// If `--parent` and `--job-name` are provided, also display a diff
182
+ /// against previous metrics that are downloaded from CI.
159
183
PostprocessMetrics {
160
184
/// Path to the metrics.json file
161
185
metrics_path : PathBuf ,
186
+ /// A parent SHA against which to compare.
187
+ #[ clap( long, requires( "job_name" ) ) ]
188
+ parent : Option < String > ,
189
+ /// The name of the current job.
190
+ #[ clap( long, requires( "parent" ) ) ]
191
+ job_name : Option < String > ,
162
192
} ,
163
193
/// Upload CI metrics to Datadog.
164
194
UploadBuildMetrics {
@@ -209,9 +239,8 @@ fn main() -> anyhow::Result<()> {
209
239
Args :: UploadBuildMetrics { cpu_usage_csv } => {
210
240
upload_ci_metrics ( & cpu_usage_csv) ?;
211
241
}
212
- Args :: PostprocessMetrics { metrics_path } => {
213
- let metrics = load_metrics ( & metrics_path) ?;
214
- output_bootstrap_stats ( & metrics) ;
242
+ Args :: PostprocessMetrics { metrics_path, parent, job_name } => {
243
+ postprocess_metrics ( metrics_path, parent, job_name) ?;
215
244
}
216
245
Args :: PostMergeReport { current, parent } => {
217
246
let db = load_db ( default_jobs_file) ?;
0 commit comments