Skip to content

Commit 611a1d5

Browse files
authored
Merge pull request #1273 from rylev/use-tables-in-triage
Use the summary tables in triage report
2 parents 9636d7a + df9b2d3 commit 611a1d5

File tree

3 files changed

+79
-168
lines changed

3 files changed

+79
-168
lines changed

site/src/comparison.rs

Lines changed: 57 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use crate::db::{ArtifactId, Benchmark, Lookup, Profile, Scenario};
77
use crate::github;
88
use crate::load::SiteCtxt;
99
use crate::selector::{self, Tag};
10-
use std::cmp::Ordering;
1110

11+
use collector::category::Category;
1212
use collector::Bound;
1313
use serde::Serialize;
1414

15+
use std::cmp::Ordering;
1516
use std::collections::{HashMap, HashSet};
1617
use std::error::Error;
1718
use 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

144145
async 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)]
803758
pub 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

11431099
impl std::cmp::PartialEq for TestResultComparison {

site/src/github.rs

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
use crate::api::github::Issue;
2-
use crate::comparison::{
3-
write_summary_table, Comparison, ComparisonConfidence, ComparisonSummary, Direction,
4-
};
2+
use crate::comparison::{write_summary_table, ComparisonConfidence, ComparisonSummary, Direction};
53
use crate::load::{Config, SiteCtxt, TryCommit};
64

75
use anyhow::Context as _;
8-
use database::{ArtifactId, Benchmark, QueuedCommit};
6+
use database::{ArtifactId, QueuedCommit};
97
use reqwest::header::USER_AGENT;
108
use serde::{Deserialize, Serialize};
119

12-
use collector::category::Category;
13-
use std::collections::{HashMap, HashSet};
10+
use std::collections::HashSet;
1411
use std::{fmt::Write, sync::Arc, time::Duration};
1512

1613
type BoxedError = Box<dyn std::error::Error + Send + Sync>;
@@ -651,21 +648,6 @@ compiler perf.{next_steps}
651648
)
652649
}
653650

654-
pub type BenchmarkMap = HashMap<Benchmark, Category>;
655-
656-
async fn get_benchmark_map(ctxt: &SiteCtxt) -> BenchmarkMap {
657-
let benchmarks = ctxt.pool.connection().await.get_benchmarks().await;
658-
benchmarks
659-
.into_iter()
660-
.map(|bench| {
661-
(
662-
bench.name.as_str().into(),
663-
Category::from_db_representation(&bench.category).unwrap(),
664-
)
665-
})
666-
.collect()
667-
}
668-
669651
async fn categorize_benchmark(
670652
ctxt: &SiteCtxt,
671653
commit_sha: String,
@@ -684,8 +666,8 @@ async fn categorize_benchmark(
684666
_ => return (String::from("ERROR categorizing benchmark run!"), None),
685667
};
686668

687-
let benchmark_map = get_benchmark_map(ctxt).await;
688-
let (primary, secondary) = split_comparison(comparison, benchmark_map);
669+
let benchmark_map = ctxt.get_benchmark_category_map().await;
670+
let (primary, secondary) = comparison.summarize_by_category(benchmark_map);
689671

690672
const DISAGREEMENT: &str = "If you disagree with this performance assessment, \
691673
please file an issue in [rust-lang/rustc-perf](https://github.com/rust-lang/rustc-perf/issues/new).";
@@ -772,44 +754,6 @@ fn generate_short_summary(
772754
}
773755
}
774756

775-
/// Splits comparison into primary and secondary summaries based on benchmark category
776-
fn split_comparison(
777-
comparison: Comparison,
778-
map: BenchmarkMap,
779-
) -> (Option<ComparisonSummary>, Option<ComparisonSummary>) {
780-
let mut primary = HashSet::new();
781-
let mut secondary = HashSet::new();
782-
783-
for statistic in comparison.statistics {
784-
let category: Category = map
785-
.get(&statistic.benchmark())
786-
.copied()
787-
.unwrap_or_else(|| Category::Secondary);
788-
if let Category::Primary = category {
789-
primary.insert(statistic);
790-
} else {
791-
secondary.insert(statistic);
792-
}
793-
}
794-
795-
let primary = Comparison {
796-
a: comparison.a.clone(),
797-
b: comparison.b.clone(),
798-
statistics: primary,
799-
new_errors: comparison.new_errors.clone(),
800-
};
801-
let secondary = Comparison {
802-
a: comparison.a,
803-
b: comparison.b,
804-
statistics: secondary,
805-
new_errors: comparison.new_errors,
806-
};
807-
(
808-
ComparisonSummary::summarize_comparison(&primary),
809-
ComparisonSummary::summarize_comparison(&secondary),
810-
)
811-
}
812-
813757
/// Whether a comparison is relevant enough to show
814758
fn comparison_is_relevant(confidence: ComparisonConfidence, is_master_commit: bool) -> bool {
815759
if is_master_commit {

site/src/load.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
use arc_swap::{ArcSwap, Guard};
2-
use std::collections::HashSet;
1+
use std::collections::{HashMap, HashSet};
32
use std::fs;
43
use std::ops::RangeInclusive;
54
use std::path::Path;
65
use std::sync::Arc;
76
use std::time::Instant;
87

8+
use arc_swap::{ArcSwap, Guard};
99
use chrono::{Duration, Utc};
1010
use log::error;
1111
use serde::{Deserialize, Serialize};
1212

13+
use crate::api::github;
1314
use crate::db;
14-
use collector::{Bound, MasterCommit};
15+
use collector::{category::Category, Bound, MasterCommit};
1516
use database::Date;
16-
17-
use crate::api::github;
18-
use collector;
1917
use database::Pool;
2018
pub use database::{ArtifactId, Benchmark, Commit};
2119

@@ -217,6 +215,19 @@ impl SiteCtxt {
217215
)
218216
}
219217

218+
pub async fn get_benchmark_category_map(&self) -> HashMap<Benchmark, Category> {
219+
let benchmarks = self.pool.connection().await.get_benchmarks().await;
220+
benchmarks
221+
.into_iter()
222+
.map(|bench| {
223+
(
224+
bench.name.as_str().into(),
225+
Category::from_db_representation(&bench.category).unwrap(),
226+
)
227+
})
228+
.collect()
229+
}
230+
220231
/// Get cached master-branch Rust commits.
221232
/// Returns cached results immediately, but if the cached value is older than one minute,
222233
/// updates in a background task for next time.

0 commit comments

Comments
 (0)