@@ -5,7 +5,7 @@ mod jobs;
55mod metrics;
66mod utils;
77
8- use std:: collections:: BTreeMap ;
8+ use std:: collections:: { BTreeMap , HashMap } ;
99use std:: path:: { Path , PathBuf } ;
1010use std:: process:: Command ;
1111
@@ -18,7 +18,7 @@ use crate::analysis::output_test_diffs;
1818use crate :: cpu_usage:: load_cpu_usage;
1919use crate :: datadog:: upload_datadog_metric;
2020use 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} ;
2222use crate :: utils:: load_env_var;
2323use analysis:: output_bootstrap_stats;
2424
@@ -138,6 +138,27 @@ fn upload_ci_metrics(cpu_usage_csv: &Path) -> anyhow::Result<()> {
138138 Ok ( ( ) )
139139}
140140
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+
141162#[ derive( clap:: Parser ) ]
142163enum Args {
143164 /// Calculate a list of jobs that should be executed on CI.
@@ -155,10 +176,19 @@ enum Args {
155176 #[ clap( long = "type" , default_value = "auto" ) ]
156177 job_type : JobType ,
157178 } ,
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.
159183 PostprocessMetrics {
160184 /// Path to the metrics.json file
161185 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 > ,
162192 } ,
163193 /// Upload CI metrics to Datadog.
164194 UploadBuildMetrics {
@@ -209,9 +239,8 @@ fn main() -> anyhow::Result<()> {
209239 Args :: UploadBuildMetrics { cpu_usage_csv } => {
210240 upload_ci_metrics ( & cpu_usage_csv) ?;
211241 }
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) ?;
215244 }
216245 Args :: PostMergeReport { current, parent } => {
217246 let db = load_db ( default_jobs_file) ?;
0 commit comments