@@ -7,11 +7,12 @@ use crate::db::{ArtifactId, Benchmark, Lookup, Profile, Scenario};
77use crate :: github;
88use crate :: load:: SiteCtxt ;
99use crate :: selector:: { self , Tag } ;
10- use std:: cmp:: Ordering ;
1110
11+ use collector:: category:: Category ;
1212use collector:: Bound ;
1313use serde:: Serialize ;
1414
15+ use std:: cmp:: Ordering ;
1516use std:: collections:: { HashMap , HashSet } ;
1617use std:: error:: Error ;
1718use std:: hash:: Hash ;
@@ -71,7 +72,7 @@ pub async fn handle_triage(
7172 ) ;
7273
7374 // handle results of comparison
74- populate_report ( & comparison, & mut report) . await ;
75+ populate_report ( ctxt , & comparison, & mut report) . await ;
7576
7677 // Check that there is a next commit and that the
7778 // after commit is not equal to `end`
@@ -142,6 +143,7 @@ pub async fn handle_compare(
142143}
143144
144145async fn populate_report (
146+ ctxt : & SiteCtxt ,
145147 comparison : & Comparison ,
146148 report : & mut HashMap < Option < Direction > , Vec < String > > ,
147149) {
@@ -153,7 +155,7 @@ async fn populate_report(
153155 . entry ( confidence. is_definitely_relevant ( ) . then ( || direction) )
154156 . or_default ( ) ;
155157
156- entry. push ( summary . write ( comparison) . await )
158+ entry. push ( write_summary ( ctxt , comparison) . await )
157159 }
158160 }
159161 }
@@ -206,11 +208,7 @@ impl ComparisonSummary {
206208 } ;
207209 comparisons. sort_by ( cmp) ;
208210
209- let errors_in = comparison
210- . new_errors
211- . keys ( )
212- . map ( |k| k. as_str ( ) . to_owned ( ) )
213- . collect :: < Vec < _ > > ( ) ;
211+ let errors_in = comparison. new_errors . keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
214212
215213 Some ( ComparisonSummary {
216214 comparisons,
@@ -296,16 +294,6 @@ impl ComparisonSummary {
296294 self . num_regressions
297295 }
298296
299- /// The most relevant changes (based on size)
300- pub fn most_relevant_changes < ' a > ( & ' a self ) -> [ Option < & TestResultComparison > ; 2 ] {
301- match self . direction ( ) {
302- Some ( Direction :: Improvement ) => [ self . largest_improvement ( ) , None ] ,
303- Some ( Direction :: Regression ) => [ self . largest_regression ( ) , None ] ,
304- Some ( Direction :: Mixed ) => [ self . largest_improvement ( ) , self . largest_regression ( ) ] ,
305- None => [ None , None ] ,
306- }
307- }
308-
309297 /// Arithmetic mean of all improvements as a percent
310298 pub fn arithmetic_mean_of_improvements ( & self ) -> f64 {
311299 self . arithmetic_mean ( self . improvements ( ) )
@@ -382,66 +370,32 @@ impl ComparisonSummary {
382370 _ => ComparisonConfidence :: MaybeRelevant ,
383371 }
384372 }
373+ }
385374
386- async fn write ( & self , comparison : & Comparison ) -> String {
387- let mut result = if let Some ( pr ) = comparison . b . pr {
388- let title = github :: pr_title ( pr) . await ;
389- format ! (
390- "{} [#{}](https://github.com/rust-lang/rust/pull/{}) \n " ,
391- title , pr , pr
392- )
393- } else {
394- String :: from ( "<Unknown Change> \n " )
395- } ;
396- let start = & comparison . a . artifact ;
397- let end = & comparison. b . artifact ;
398- let link = & compare_link ( start , end ) ;
399-
400- self . write_summary_lines ( & mut result, Some ( link) ) ;
375+ async fn write_summary ( ctxt : & SiteCtxt , comparison : & Comparison ) -> String {
376+ use std :: fmt :: Write ;
377+ let mut result = if let Some ( pr) = comparison . b . pr {
378+ let title = github :: pr_title ( pr ) . await ;
379+ format ! (
380+ "{} [#{}](https://github.com/rust-lang/rust/pull/{})" ,
381+ title , pr , pr
382+ )
383+ } else {
384+ String :: from ( "<Unknown Change>" )
385+ } ;
386+ let start = & comparison. a . artifact ;
387+ let end = & comparison . b . artifact ;
388+ let link = & compare_link ( start , end ) ;
389+ write ! ( & mut result, " [(Comparison Link)]({}) \n " , link) . unwrap ( ) ;
401390
402- result
403- }
391+ let benchmark_map = ctxt. get_benchmark_category_map ( ) . await ;
392+ let ( primary, secondary) = comparison. clone ( ) . summarize_by_category ( benchmark_map) ;
393+ let primary = primary. unwrap_or_else ( ComparisonSummary :: empty) ;
394+ let secondary = secondary. unwrap_or_else ( ComparisonSummary :: empty) ;
404395
405- pub fn write_summary_lines ( & self , result : & mut String , link : Option < & str > ) {
406- use std:: fmt:: Write ;
407- if self . num_regressions > 1 {
408- writeln ! (
409- result,
410- "- Arithmetic mean of relevant regressions: {:.1}%" ,
411- self . arithmetic_mean_of_regressions( )
412- )
413- . unwrap ( ) ;
414- }
415- if self . num_improvements > 1 {
416- writeln ! (
417- result,
418- "- Arithmetic mean of relevant improvements: {:.1}%" ,
419- self . arithmetic_mean_of_improvements( )
420- )
421- . unwrap ( ) ;
422- }
423- if self . num_improvements > 0 && self . num_regressions > 0 {
424- writeln ! (
425- result,
426- "- Arithmetic mean of all relevant changes: {:.1}%" ,
427- self . arithmetic_mean_of_changes( )
428- )
429- . unwrap ( ) ;
430- }
431- for change in self . most_relevant_changes ( ) . iter ( ) . filter_map ( |s| * s) {
432- write ! ( result, "- " ) . unwrap ( ) ;
433- change. summary_line ( result, link)
434- }
396+ write_summary_table ( & primary, & secondary, & mut result) ;
435397
436- if !self . errors_in . is_empty ( ) {
437- write ! (
438- result,
439- "- Benchmark(s) {} started failing to build" ,
440- self . errors_in. join( ", " )
441- )
442- . unwrap ( ) ;
443- }
444- }
398+ result
445399}
446400
447401/// Writes a Markdown table containing summary of relevant results.
@@ -800,6 +754,7 @@ impl From<ArtifactDescription> for api::comparison::ArtifactDescription {
800754}
801755
802756// A comparison of two artifacts
757+ #[ derive( Clone ) ]
803758pub struct Comparison {
804759 pub a : ArtifactDescription ,
805760 pub b : ArtifactDescription ,
@@ -836,6 +791,34 @@ impl Comparison {
836791 pub fn next ( & self , master_commits : & [ collector:: MasterCommit ] ) -> Option < String > {
837792 next_commit ( & self . b . artifact , master_commits) . map ( |c| c. sha . clone ( ) )
838793 }
794+
795+ /// Splits comparison into primary and secondary summaries based on benchmark category
796+ pub fn summarize_by_category (
797+ self ,
798+ map : HashMap < Benchmark , Category > ,
799+ ) -> ( Option < ComparisonSummary > , Option < ComparisonSummary > ) {
800+ let ( primary, secondary) = self
801+ . statistics
802+ . into_iter ( )
803+ . partition ( |s| map. get ( & s. benchmark ( ) ) == Some ( & Category :: Primary ) ) ;
804+
805+ let primary = Comparison {
806+ a : self . a . clone ( ) ,
807+ b : self . b . clone ( ) ,
808+ statistics : primary,
809+ new_errors : self . new_errors . clone ( ) ,
810+ } ;
811+ let secondary = Comparison {
812+ a : self . a ,
813+ b : self . b ,
814+ statistics : secondary,
815+ new_errors : self . new_errors ,
816+ } ;
817+ (
818+ ComparisonSummary :: summarize_comparison ( & primary) ,
819+ ComparisonSummary :: summarize_comparison ( & secondary) ,
820+ )
821+ }
839822}
840823
841824/// The historical data for a certain benchmark
@@ -1111,33 +1094,6 @@ impl TestResultComparison {
11111094 let ( a, b) = self . results ;
11121095 ( b - a) / a
11131096 }
1114-
1115- fn direction ( & self ) -> Direction {
1116- if self . relative_change ( ) > 0.0 {
1117- Direction :: Regression
1118- } else {
1119- Direction :: Improvement
1120- }
1121- }
1122-
1123- pub fn summary_line ( & self , summary : & mut String , link : Option < & str > ) {
1124- use std:: fmt:: Write ;
1125- let percent = self . relative_change ( ) * 100.0 ;
1126- writeln ! (
1127- summary,
1128- "Largest {} in {}: {:.1}% on `{}` builds of `{} {}`" ,
1129- self . direction( ) ,
1130- match link {
1131- Some ( l) => format!( "[instruction counts]({})" , l) ,
1132- None => "instruction counts" . into( ) ,
1133- } ,
1134- percent,
1135- self . scenario,
1136- self . benchmark,
1137- self . profile
1138- )
1139- . unwrap ( ) ;
1140- }
11411097}
11421098
11431099impl std:: cmp:: PartialEq for TestResultComparison {
0 commit comments