1
1
use crate :: api:: github:: Issue ;
2
2
use crate :: comparison:: {
3
- deserves_attention_icount, write_summary_table, write_summary_table_footer,
3
+ deserves_attention_icount, write_summary_table, write_summary_table_footer, ArtifactComparison ,
4
4
ArtifactComparisonSummary , Direction , Stat ,
5
5
} ;
6
6
use crate :: load:: { Config , SiteCtxt , TryCommit } ;
7
7
8
8
use anyhow:: Context as _;
9
- use database:: { ArtifactId , Benchmark , QueuedCommit } ;
9
+ use database:: { ArtifactId , QueuedCommit } ;
10
10
use reqwest:: header:: USER_AGENT ;
11
11
use serde:: { Deserialize , Serialize } ;
12
12
13
- use collector:: category:: Category ;
14
-
15
- use std:: collections:: { HashMap , HashSet } ;
13
+ use std:: collections:: HashSet ;
16
14
17
15
use std:: { fmt:: Write , sync:: Arc , time:: Duration } ;
18
16
@@ -565,7 +563,10 @@ pub async fn post_finished(ctxt: &SiteCtxt) {
565
563
/// `is_master_commit` is used to differentiate messages for try runs and post-merge runs.
566
564
async fn post_comparison_comment ( ctxt : & SiteCtxt , commit : QueuedCommit , is_master_commit : bool ) {
567
565
let pr = commit. pr ;
568
- let body = summarize_run ( ctxt, commit, is_master_commit) . await ;
566
+ let body = match summarize_run ( ctxt, commit, is_master_commit) . await {
567
+ Ok ( message) => message,
568
+ Err ( error) => error,
569
+ } ;
569
570
570
571
post_comment ( & ctxt. config , pr, body) . await ;
571
572
}
@@ -579,54 +580,43 @@ fn make_comparison_url(commit: &QueuedCommit, stat: Stat) -> String {
579
580
)
580
581
}
581
582
582
- async fn summarize_run ( ctxt : & SiteCtxt , commit : QueuedCommit , is_master_commit : bool ) -> String {
583
+ async fn calculate_stat_comparison (
584
+ ctxt : & SiteCtxt ,
585
+ commit : & QueuedCommit ,
586
+ stat : Stat ,
587
+ ) -> Result < ArtifactComparison , String > {
588
+ match crate :: comparison:: compare (
589
+ collector:: Bound :: Commit ( commit. parent_sha . clone ( ) ) ,
590
+ collector:: Bound :: Commit ( commit. sha . clone ( ) ) ,
591
+ stat,
592
+ ctxt,
593
+ )
594
+ . await
595
+ {
596
+ Ok ( Some ( c) ) => Ok ( c) ,
597
+ _ => Err ( "ERROR categorizing benchmark run!" . to_owned ( ) ) ,
598
+ }
599
+ }
600
+
601
+ async fn summarize_run (
602
+ ctxt : & SiteCtxt ,
603
+ commit : QueuedCommit ,
604
+ is_master_commit : bool ,
605
+ ) -> Result < String , String > {
583
606
let benchmark_map = ctxt. get_benchmark_category_map ( ) . await ;
584
607
585
608
let mut message = format ! (
586
609
"Finished benchmarking commit ({sha}): [comparison url]({comparison_url}).
587
610
588
- **Summary**: " ,
611
+ **Summary**:\n \n " ,
589
612
sha = commit. sha,
590
613
comparison_url = make_comparison_url( & commit, Stat :: Instructions )
591
614
) ;
592
615
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
- ] ;
616
+ let inst_comparison = calculate_stat_comparison ( ctxt, & commit, Stat :: Instructions ) . await ?;
599
617
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
-
617
- let comparison = match crate :: comparison:: compare (
618
- collector:: Bound :: Commit ( commit. parent_sha . clone ( ) ) ,
619
- collector:: Bound :: Commit ( commit. sha . clone ( ) ) ,
620
- Stat :: Instructions ,
621
- ctxt,
622
- )
623
- . await
624
- {
625
- Ok ( Some ( c) ) => c,
626
- _ => return String :: from ( "ERROR categorizing benchmark run!" ) ,
627
- } ;
628
- let errors = if !comparison. newly_failed_benchmarks . is_empty ( ) {
629
- let benchmarks = comparison
618
+ let errors = if !inst_comparison. newly_failed_benchmarks . is_empty ( ) {
619
+ let benchmarks = inst_comparison
630
620
. newly_failed_benchmarks
631
621
. iter ( )
632
622
. map ( |( benchmark, _) | format ! ( "- {benchmark}" ) )
@@ -636,46 +626,65 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
636
626
} else {
637
627
String :: new ( )
638
628
} ;
639
- let ( primary, secondary) = comparison. summarize_by_category ( & benchmark_map) ;
629
+ let ( inst_primary, inst_secondary) = inst_comparison
630
+ . clone ( )
631
+ . summarize_by_category ( & benchmark_map) ;
632
+
633
+ let mut table_written = false ;
634
+ let stats = vec ! [
635
+ (
636
+ "Instruction count" ,
637
+ Stat :: Instructions ,
638
+ false ,
639
+ inst_comparison,
640
+ ) ,
641
+ (
642
+ "Max RSS (memory usage)" ,
643
+ Stat :: MaxRSS ,
644
+ true ,
645
+ calculate_stat_comparison( ctxt, & commit, Stat :: MaxRSS ) . await ?,
646
+ ) ,
647
+ (
648
+ "Cycles" ,
649
+ Stat :: Cycles ,
650
+ true ,
651
+ calculate_stat_comparison( ctxt, & commit, Stat :: Cycles ) . await ?,
652
+ ) ,
653
+ ] ;
654
+
655
+ for ( title, stat, hidden, comparison) in stats {
656
+ message. push_str ( & format ! (
657
+ "## [{title}]({})\n " ,
658
+ make_comparison_url( & commit, stat)
659
+ ) ) ;
660
+
661
+ let ( primary, secondary) = comparison. summarize_by_category ( & benchmark_map) ;
662
+ table_written |= write_stat_summary ( primary, secondary, hidden, & mut message) . await ;
663
+ }
664
+
665
+ if table_written {
666
+ write_summary_table_footer ( & mut message) ;
667
+ }
640
668
641
669
const DISAGREEMENT : & str = "If you disagree with this performance assessment, \
642
670
please file an issue in [rust-lang/rustc-perf](https://github.com/rust-lang/rustc-perf/issues/new).";
643
671
let footer = format ! ( "{DISAGREEMENT}{errors}" ) ;
644
672
645
- let direction = primary. direction ( ) . or ( secondary. direction ( ) ) ;
646
- let next_steps = next_steps ( primary, secondary, direction, is_master_commit) ;
673
+ let direction = inst_primary. direction ( ) . or ( inst_secondary. direction ( ) ) ;
674
+ let next_steps = next_steps ( inst_primary, inst_secondary, direction, is_master_commit) ;
675
+
647
676
write ! ( & mut message, "\n {footer}\n {next_steps}" ) . unwrap ( ) ;
648
677
649
- message
678
+ Ok ( message)
650
679
}
651
680
681
+ /// Returns true if a summary table was written to `message`.
652
682
async fn write_stat_summary (
653
- benchmark_map : & HashMap < Benchmark , Category > ,
654
- commit : & QueuedCommit ,
655
- ctxt : & SiteCtxt ,
656
- title : & str ,
657
- stat : Stat ,
683
+ primary : ArtifactComparisonSummary ,
684
+ secondary : ArtifactComparisonSummary ,
658
685
hidden : bool ,
659
686
message : & mut String ,
660
687
) -> bool {
661
- let comparison = match crate :: comparison:: compare (
662
- collector:: Bound :: Commit ( commit. parent_sha . clone ( ) ) ,
663
- collector:: Bound :: Commit ( commit. sha . clone ( ) ) ,
664
- stat,
665
- ctxt,
666
- )
667
- . await
668
- {
669
- Ok ( Some ( c) ) => c,
670
- _ => panic ! ( ) , //return Err("ERROR categorizing benchmark run!".to_owned()),
671
- } ;
672
-
673
- message. push_str ( & format ! (
674
- "## [{title}]({})\n " ,
675
- make_comparison_url( commit, stat)
676
- ) ) ;
677
-
678
- let ( primary, secondary) = comparison. summarize_by_category ( benchmark_map) ;
679
688
if !primary. is_relevant ( ) && !secondary. is_relevant ( ) {
680
689
message
681
690
. push_str ( "This benchmark run did not return any relevant results for this metric.\n " ) ;
0 commit comments