Skip to content

Commit c5270d2

Browse files
authored
Merge pull request #1274 from rylev/improve-table
Improve summary table and GitHub messaging
2 parents 611a1d5 + fdd2059 commit c5270d2

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

site/src/comparison.rs

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async fn populate_report(
155155
.entry(confidence.is_definitely_relevant().then(|| direction))
156156
.or_default();
157157

158-
entry.push(write_summary(ctxt, comparison).await)
158+
entry.push(write_triage_summary(ctxt, comparison).await)
159159
}
160160
}
161161
}
@@ -320,6 +320,10 @@ impl ComparisonSummary {
320320
self.comparisons.is_empty()
321321
}
322322

323+
pub fn errors_in(&self) -> &[String] {
324+
&self.errors_in
325+
}
326+
323327
fn arithmetic_mean<'a>(
324328
&'a self,
325329
changes: impl Iterator<Item = &'a TestResultComparison>,
@@ -372,7 +376,7 @@ impl ComparisonSummary {
372376
}
373377
}
374378

375-
async fn write_summary(ctxt: &SiteCtxt, comparison: &Comparison) -> String {
379+
async fn write_triage_summary(ctxt: &SiteCtxt, comparison: &Comparison) -> String {
376380
use std::fmt::Write;
377381
let mut result = if let Some(pr) = comparison.b.pr {
378382
let title = github::pr_title(pr).await;
@@ -393,7 +397,7 @@ async fn write_summary(ctxt: &SiteCtxt, comparison: &Comparison) -> String {
393397
let primary = primary.unwrap_or_else(ComparisonSummary::empty);
394398
let secondary = secondary.unwrap_or_else(ComparisonSummary::empty);
395399

396-
write_summary_table(&primary, &secondary, &mut result);
400+
write_summary_table(&primary, &secondary, false, &mut result);
397401

398402
result
399403
}
@@ -402,6 +406,7 @@ async fn write_summary(ctxt: &SiteCtxt, comparison: &Comparison) -> String {
402406
pub fn write_summary_table(
403407
primary: &ComparisonSummary,
404408
secondary: &ComparisonSummary,
409+
with_footnotes: bool,
405410
result: &mut String,
406411
) {
407412
use std::fmt::Write;
@@ -421,7 +426,8 @@ pub fn write_summary_table(
421426
.unwrap();
422427
writeln!(
423428
result,
424-
"| count[^1] | {} | {} | {} | {} | {} |",
429+
"| count{} | {} | {} | {} | {} | {} |",
430+
if with_footnotes { "[^1]" } else { "" },
425431
primary.num_regressions,
426432
secondary.num_regressions,
427433
primary.num_improvements,
@@ -432,7 +438,8 @@ pub fn write_summary_table(
432438

433439
writeln!(
434440
result,
435-
"| mean[^2] | {} | {} | {} | {} | {} |",
441+
"| mean{} | {} | {} | {} | {} | {} |",
442+
if with_footnotes { "[^2]" } else { "" },
436443
render_stat(primary.num_regressions, || Some(
437444
primary.arithmetic_mean_of_regressions()
438445
)),
@@ -497,27 +504,15 @@ pub fn write_summary_table(
497504
)
498505
.unwrap();
499506

500-
if !primary.errors_in.is_empty() {
501-
write!(
507+
if with_footnotes {
508+
writeln!(
502509
result,
503-
"\nThe following benchmark(s) failed to build:\n{}\n",
504-
primary
505-
.errors_in
506-
.iter()
507-
.map(|benchmark| format!("- {benchmark}"))
508-
.collect::<Vec<_>>()
509-
.join("\n")
510+
r#"
511+
[^1]: *number of relevant changes*
512+
[^2]: *the arithmetic mean of the percent change*"#
510513
)
511514
.unwrap();
512515
}
513-
514-
writeln!(
515-
result,
516-
r#"
517-
[^1]: *number of relevant changes*
518-
[^2]: *the arithmetic mean of the percent change*"#
519-
)
520-
.unwrap();
521516
}
522517

523518
/// The amount of confidence we have that a comparison actually represents a real
@@ -760,6 +755,7 @@ pub struct Comparison {
760755
pub b: ArtifactDescription,
761756
/// Statistics based on test case
762757
pub statistics: HashSet<TestResultComparison>,
758+
/// A map from benchmark name to an error which occured when building `b` but not `a`.
763759
pub new_errors: HashMap<String, String>,
764760
}
765761

@@ -795,24 +791,29 @@ impl Comparison {
795791
/// Splits comparison into primary and secondary summaries based on benchmark category
796792
pub fn summarize_by_category(
797793
self,
798-
map: HashMap<Benchmark, Category>,
794+
category_map: HashMap<Benchmark, Category>,
799795
) -> (Option<ComparisonSummary>, Option<ComparisonSummary>) {
800796
let (primary, secondary) = self
801797
.statistics
802798
.into_iter()
803-
.partition(|s| map.get(&s.benchmark()) == Some(&Category::Primary));
799+
.partition(|s| category_map.get(&s.benchmark()) == Some(&Category::Primary));
800+
801+
let (primary_errors, secondary_errors) = self
802+
.new_errors
803+
.into_iter()
804+
.partition(|(b, _)| category_map.get(&b.as_str().into()) == Some(&Category::Primary));
804805

805806
let primary = Comparison {
806807
a: self.a.clone(),
807808
b: self.b.clone(),
808809
statistics: primary,
809-
new_errors: self.new_errors.clone(),
810+
new_errors: primary_errors,
810811
};
811812
let secondary = Comparison {
812813
a: self.a,
813814
b: self.b,
814815
statistics: secondary,
815-
new_errors: self.new_errors,
816+
new_errors: secondary_errors,
816817
};
817818
(
818819
ComparisonSummary::summarize_comparison(&primary),
@@ -1275,16 +1276,13 @@ fn compare_link(start: &ArtifactId, end: &ArtifactId) -> String {
12751276

12761277
#[cfg(test)]
12771278
mod tests {
1279+
use super::*;
1280+
12781281
use collector::category::Category;
12791282
use std::collections::HashSet;
12801283

12811284
use database::{ArtifactId, Profile, Scenario};
12821285

1283-
use crate::comparison::{
1284-
write_summary_table, ArtifactDescription, Comparison, ComparisonSummary,
1285-
TestResultComparison,
1286-
};
1287-
12881286
#[test]
12891287
fn summary_table_only_regressions_primary() {
12901288
check_table(
@@ -1487,7 +1485,7 @@ mod tests {
14871485
let secondary = create_summary(secondary_statistics);
14881486

14891487
let mut result = String::new();
1490-
write_summary_table(&primary, &secondary, &mut result);
1488+
write_summary_table(&primary, &secondary, true, &mut result);
14911489
assert_eq!(result, expected);
14921490
}
14931491

site/src/github.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,25 @@ async fn categorize_benchmark(
700700
primary.unwrap_or_else(|| ComparisonSummary::empty()),
701701
secondary.unwrap_or_else(|| ComparisonSummary::empty()),
702702
);
703-
write_summary_table(&primary, &secondary, &mut result);
703+
write_summary_table(&primary, &secondary, true, &mut result);
704+
705+
if !primary.errors_in().is_empty() || !secondary.errors_in().is_empty() {
706+
let list_errored_benchmarks = |summary: ComparisonSummary| {
707+
summary
708+
.errors_in()
709+
.iter()
710+
.map(|benchmark| format!("- {benchmark}"))
711+
.collect::<Vec<_>>()
712+
.join("\n")
713+
};
714+
write!(
715+
result,
716+
"\nThe following benchmark(s) failed to build:\n{}{}\n",
717+
list_errored_benchmarks(primary),
718+
list_errored_benchmarks(secondary)
719+
)
720+
.unwrap();
721+
}
704722
}
705723

706724
write!(result, "\n{}", DISAGREEMENT).unwrap();
@@ -743,7 +761,7 @@ fn generate_short_summary(
743761
} else {
744762
(
745763
format!(
746-
"no relevant changes found. {} results were found to be statistically significant but too small to be relevant.",
764+
"changes not relevant. {} results were found to be statistically significant but the changes were too small to be relevant.",
747765
summary.num_significant_changes(),
748766
),
749767
None

0 commit comments

Comments
 (0)