11use crate :: api:: github:: Issue ;
22use crate :: comparison:: {
3- deserves_attention_icount, deserves_attention_maxrss , write_summary_table ,
4- write_summary_table_footer , ArtifactComparisonSummary , Direction , Stat ,
3+ deserves_attention_icount, write_summary_table , write_summary_table_footer ,
4+ ArtifactComparisonSummary , Direction , Stat ,
55} ;
66use crate :: load:: { Config , SiteCtxt , TryCommit } ;
77
@@ -11,7 +11,9 @@ use reqwest::header::USER_AGENT;
1111use serde:: { Deserialize , Serialize } ;
1212
1313use collector:: category:: Category ;
14+
1415use std:: collections:: { HashMap , HashSet } ;
16+
1517use std:: { fmt:: Write , sync:: Arc , time:: Duration } ;
1618
1719type BoxedError = Box < dyn std:: error:: Error + Send + Sync > ;
@@ -578,6 +580,40 @@ fn make_comparison_url(commit: &QueuedCommit, stat: Stat) -> String {
578580}
579581
580582async fn summarize_run ( ctxt : & SiteCtxt , commit : QueuedCommit , is_master_commit : bool ) -> String {
583+ let benchmark_map = ctxt. get_benchmark_category_map ( ) . await ;
584+
585+ let mut message = format ! (
586+ "Finished benchmarking commit ({sha}): [comparison url]({comparison_url}).
587+
588+ **Summary**: " ,
589+ sha = commit. sha,
590+ comparison_url = make_comparison_url( & commit, Stat :: Instructions )
591+ ) ;
592+
593+ let mut table_written = false ;
594+ let stats = vec ! [
595+ ( "Instruction count" , Stat :: Instructions , false ) ,
596+ ( "Max RSS (memory usage)" , Stat :: MaxRSS , true ) ,
597+ ( "Cycles" , Stat :: Cycles , true ) ,
598+ ] ;
599+
600+ for ( title, stat, hidden) in stats {
601+ table_written |= write_stat_summary (
602+ & benchmark_map,
603+ & commit,
604+ ctxt,
605+ & title,
606+ stat,
607+ hidden,
608+ & mut message,
609+ )
610+ . await ;
611+ }
612+
613+ if table_written {
614+ write_summary_table_footer ( & mut message) ;
615+ }
616+
581617 let comparison = match crate :: comparison:: compare (
582618 collector:: Bound :: Commit ( commit. parent_sha . clone ( ) ) ,
583619 collector:: Bound :: Commit ( commit. sha . clone ( ) ) ,
@@ -589,7 +625,6 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
589625 Ok ( Some ( c) ) => c,
590626 _ => return String :: from ( "ERROR categorizing benchmark run!" ) ,
591627 } ;
592-
593628 let errors = if !comparison. newly_failed_benchmarks . is_empty ( ) {
594629 let benchmarks = comparison
595630 . newly_failed_benchmarks
@@ -601,93 +636,28 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
601636 } else {
602637 String :: new ( )
603638 } ;
604-
605- let benchmark_map = ctxt. get_benchmark_category_map ( ) . await ;
606639 let ( primary, secondary) = comparison. summarize_by_category ( & benchmark_map) ;
607640
608641 const DISAGREEMENT : & str = "If you disagree with this performance assessment, \
609642 please file an issue in [rust-lang/rustc-perf](https://github.com/rust-lang/rustc-perf/issues/new).";
610643 let footer = format ! ( "{DISAGREEMENT}{errors}" ) ;
611644
612- let inst_comparison_url = make_comparison_url ( & commit, Stat :: Instructions ) ;
613- let mut message = format ! (
614- "Finished benchmarking commit ({sha}): [comparison url]({inst_comparison_url}).
615-
616- **Summary**: " ,
617- sha = commit. sha,
618- ) ;
619-
620- let mut table_written = false ;
621-
622- write ! (
623- & mut message,
624- "## [Instruction count]({inst_comparison_url})"
625- )
626- . unwrap ( ) ;
627- if !primary. is_relevant ( ) && !secondary. is_relevant ( ) {
628- write ! (
629- & mut message,
630- "This benchmark run did not return any relevant results.\n "
631- )
632- . unwrap ( ) ;
633- } else {
634- let primary_short_summary = generate_short_summary ( & primary) ;
635- let secondary_short_summary = generate_short_summary ( & secondary) ;
636-
637- write ! (
638- & mut message,
639- r#"
640- - Primary benchmarks: {primary_short_summary}
641- - Secondary benchmarks: {secondary_short_summary}
642-
643- "#
644- )
645- . unwrap ( ) ;
646-
647- write_summary_table ( & primary, & secondary, true , & mut message) ;
648- table_written = true ;
649- }
650-
651- if let Some ( ( primary, secondary) ) = analyze_secondary_stat (
652- ctxt,
653- & commit,
654- Stat :: MaxRSS ,
655- & benchmark_map,
656- deserves_attention_maxrss,
657- )
658- . await
659- {
660- write ! (
661- & mut message,
662- "\n ## [Max RSS]({})" ,
663- make_comparison_url( & commit, Stat :: MaxRSS )
664- )
665- . unwrap ( ) ;
666- write_summary_table ( & primary, & secondary, true , & mut message) ;
667- table_written = true ;
668- }
669-
670- if table_written {
671- write_summary_table_footer ( & mut message) ;
672- }
673-
674645 let direction = primary. direction ( ) . or ( secondary. direction ( ) ) ;
675646 let next_steps = next_steps ( primary, secondary, direction, is_master_commit) ;
676647 write ! ( & mut message, "\n {footer}\n {next_steps}" ) . unwrap ( ) ;
677648
678649 message
679650}
680651
681- async fn analyze_secondary_stat < F > (
682- ctxt : & SiteCtxt ,
652+ async fn write_stat_summary (
653+ benchmark_map : & HashMap < Benchmark , Category > ,
683654 commit : & QueuedCommit ,
655+ ctxt : & SiteCtxt ,
656+ title : & str ,
684657 stat : Stat ,
685- benchmark_map : & HashMap < Benchmark , Category > ,
686- is_interesting : F ,
687- ) -> Option < ( ArtifactComparisonSummary , ArtifactComparisonSummary ) >
688- where
689- F : FnOnce ( & ArtifactComparisonSummary , & ArtifactComparisonSummary ) -> bool ,
690- {
658+ hidden : bool ,
659+ message : & mut String ,
660+ ) -> bool {
691661 let comparison = match crate :: comparison:: compare (
692662 collector:: Bound :: Commit ( commit. parent_sha . clone ( ) ) ,
693663 collector:: Bound :: Commit ( commit. sha . clone ( ) ) ,
@@ -697,18 +667,44 @@ where
697667 . await
698668 {
699669 Ok ( Some ( c) ) => c,
700- _ => return None ,
670+ _ => panic ! ( ) , // return Err("ERROR categorizing benchmark run!".to_owned()) ,
701671 } ;
702672
673+ message. push_str ( & format ! (
674+ "## [{title}]({})\n " ,
675+ make_comparison_url( commit, stat)
676+ ) ) ;
677+
703678 let ( primary, secondary) = comparison. summarize_by_category ( benchmark_map) ;
704679 if !primary. is_relevant ( ) && !secondary. is_relevant ( ) {
705- return None ;
706- }
707-
708- if is_interesting ( & primary, & secondary) {
709- Some ( ( primary, secondary) )
680+ message
681+ . push_str ( "This benchmark run did not return any relevant results for this metric.\n " ) ;
682+ false
710683 } else {
711- None
684+ let primary_short_summary = generate_short_summary ( & primary) ;
685+ let secondary_short_summary = generate_short_summary ( & secondary) ;
686+
687+ if hidden {
688+ message. push_str ( "<details>\n <summary>Results</summary>\n \n " ) ;
689+ }
690+
691+ write ! (
692+ message,
693+ r#"
694+ - Primary benchmarks: {primary_short_summary}
695+ - Secondary benchmarks: {secondary_short_summary}
696+
697+ "#
698+ )
699+ . unwrap ( ) ;
700+
701+ write_summary_table ( & primary, & secondary, true , message) ;
702+
703+ if hidden {
704+ message. push_str ( "</details>\n " ) ;
705+ }
706+
707+ true
712708 }
713709}
714710
0 commit comments