Skip to content

Commit 85364da

Browse files
committed
Categorize perf runs when posting to GitHub
1 parent 59ec9ca commit 85364da

File tree

2 files changed

+89
-45
lines changed

2 files changed

+89
-45
lines changed

site/src/comparison.rs

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub async fn handle_triage(
2525
let end = body.end;
2626
// Compare against self to get next
2727
let master_commits = rustc_artifacts::master_commits().await?;
28-
let comparison = compare(
28+
let comparison = compare_given_commits(
2929
start.clone(),
3030
start.clone(),
3131
"instructions:u".to_owned(),
@@ -39,7 +39,7 @@ pub async fn handle_triage(
3939
let mut before = start.clone();
4040

4141
loop {
42-
let comparison = compare(
42+
let comparison = compare_given_commits(
4343
before,
4444
after.clone(),
4545
"instructions:u".to_owned(),
@@ -76,14 +76,14 @@ pub async fn handle_compare(
7676
body: api::days::Request,
7777
data: &InputData,
7878
) -> Result<api::days::Response, BoxedError> {
79-
let commits = rustc_artifacts::master_commits().await?;
79+
let master_commits = rustc_artifacts::master_commits().await?;
8080
let comparison =
81-
crate::comparison::compare(body.start, body.end, body.stat, data, &commits).await?;
81+
compare_given_commits(body.start, body.end, body.stat, data, &master_commits).await?;
8282

8383
let conn = data.conn().await;
84-
let prev = comparison.prev(&commits);
85-
let next = comparison.next(&commits);
86-
let is_contiguous = comparison.is_contiguous(&*conn, &commits).await;
84+
let prev = comparison.prev(&master_commits);
85+
let next = comparison.next(&master_commits);
86+
let is_contiguous = comparison.is_contiguous(&*conn, &master_commits).await;
8787

8888
Ok(api::days::Response {
8989
prev,
@@ -95,7 +95,7 @@ pub async fn handle_compare(
9595
}
9696

9797
async fn populate_report(comparison: &Comparison, report: &mut HashMap<Direction, Vec<String>>) {
98-
if let Some(summary) = summarize_comparison(comparison) {
98+
if let Some(summary) = ComparisonSummary::summarize_comparison(comparison) {
9999
if let Some(direction) = summary.direction() {
100100
let entry = report.entry(direction).or_default();
101101

@@ -104,42 +104,43 @@ async fn populate_report(comparison: &Comparison, report: &mut HashMap<Direction
104104
}
105105
}
106106

107-
fn summarize_comparison<'a>(comparison: &'a Comparison) -> Option<ComparisonSummary<'a>> {
108-
let mut benchmarks = comparison.get_benchmarks();
109-
// Skip empty commits, sometimes happens if there's a compiler bug or so.
110-
if benchmarks.len() == 0 {
111-
return None;
112-
}
113-
114-
let cmp = |b1: &BenchmarkComparison, b2: &BenchmarkComparison| {
115-
b1.log_change()
116-
.partial_cmp(&b2.log_change())
117-
.unwrap_or(std::cmp::Ordering::Equal)
118-
};
119-
let lo = benchmarks
120-
.iter()
121-
.enumerate()
122-
.min_by(|&(_, b1), &(_, b2)| cmp(b1, b2))
123-
.filter(|(_, c)| c.is_significant() && !c.is_increase())
124-
.map(|(i, _)| i);
125-
let lo = lo.map(|lo| benchmarks.remove(lo));
126-
let hi = benchmarks
127-
.iter()
128-
.enumerate()
129-
.max_by(|&(_, b1), &(_, b2)| cmp(b1, b2))
130-
.filter(|(_, c)| c.is_significant() && c.is_increase())
131-
.map(|(i, _)| i);
132-
let hi = hi.map(|hi| benchmarks.remove(hi));
133-
134-
Some(ComparisonSummary { hi, lo })
135-
}
136-
137-
struct ComparisonSummary<'a> {
107+
pub struct ComparisonSummary<'a> {
138108
hi: Option<BenchmarkComparison<'a>>,
139109
lo: Option<BenchmarkComparison<'a>>,
140110
}
141111

142112
impl ComparisonSummary<'_> {
113+
pub fn summarize_comparison<'a>(comparison: &'a Comparison) -> Option<ComparisonSummary<'a>> {
114+
let mut benchmarks = comparison.get_benchmarks();
115+
// Skip empty commits, sometimes happens if there's a compiler bug or so.
116+
if benchmarks.len() == 0 {
117+
return None;
118+
}
119+
120+
let cmp = |b1: &BenchmarkComparison, b2: &BenchmarkComparison| {
121+
b1.log_change()
122+
.partial_cmp(&b2.log_change())
123+
.unwrap_or(std::cmp::Ordering::Equal)
124+
};
125+
let lo = benchmarks
126+
.iter()
127+
.enumerate()
128+
.min_by(|&(_, b1), &(_, b2)| cmp(b1, b2))
129+
.filter(|(_, c)| c.is_significant() && !c.is_increase())
130+
.map(|(i, _)| i);
131+
let lo = lo.map(|lo| benchmarks.remove(lo));
132+
let hi = benchmarks
133+
.iter()
134+
.enumerate()
135+
.max_by(|&(_, b1), &(_, b2)| cmp(b1, b2))
136+
.filter(|(_, c)| c.is_significant() && c.is_increase())
137+
.map(|(i, _)| i);
138+
let hi = hi.map(|hi| benchmarks.remove(hi));
139+
140+
benchmarks.clear();
141+
142+
Some(ComparisonSummary { hi, lo })
143+
}
143144
/// The direction of the changes
144145
fn direction(&self) -> Option<Direction> {
145146
let d = match (&self.hi, &self.lo) {
@@ -153,7 +154,7 @@ impl ComparisonSummary<'_> {
153154
}
154155

155156
/// The changes ordered by their signficance (most significant first)
156-
fn ordered_changes(&self) -> Vec<&BenchmarkComparison<'_>> {
157+
pub fn ordered_changes(&self) -> Vec<&BenchmarkComparison<'_>> {
157158
match (&self.hi, &self.lo) {
158159
(None, None) => Vec::new(),
159160
(Some(b), None) => vec![b],
@@ -189,7 +190,7 @@ impl ComparisonSummary<'_> {
189190

190191
for change in self.ordered_changes() {
191192
write!(result, "- ").unwrap();
192-
change.summary_line(&mut result, link)
193+
change.summary_line(&mut result, Some(link))
193194
}
194195
result
195196
}
@@ -201,6 +202,17 @@ pub async fn compare(
201202
end: Bound,
202203
stat: String,
203204
data: &InputData,
205+
) -> Result<Comparison, BoxedError> {
206+
let master_commits = rustc_artifacts::master_commits().await?;
207+
compare_given_commits(start, end, stat, data, &master_commits).await
208+
}
209+
210+
/// Compare two bounds on a given stat
211+
pub async fn compare_given_commits(
212+
start: Bound,
213+
end: Bound,
214+
stat: String,
215+
data: &InputData,
204216
master_commits: &[rustc_artifacts::Commit],
205217
) -> Result<Comparison, BoxedError> {
206218
let a = data
@@ -388,7 +400,7 @@ impl Comparison {
388400

389401
// A single comparison based on benchmark and cache state
390402
#[derive(Debug)]
391-
struct BenchmarkComparison<'a> {
403+
pub struct BenchmarkComparison<'a> {
392404
bench_name: &'a str,
393405
cache_state: &'a str,
394406
results: (f64, f64),
@@ -430,7 +442,7 @@ impl BenchmarkComparison<'_> {
430442
}
431443
}
432444

433-
fn summary_line(&self, summary: &mut String, link: &str) {
445+
pub fn summary_line(&self, summary: &mut String, link: Option<&str>) {
434446
use std::fmt::Write;
435447
let magnitude = self.log_change().abs();
436448
let size = if magnitude > 0.10 {
@@ -451,7 +463,10 @@ impl BenchmarkComparison<'_> {
451463
"{} {} in [instruction counts]({})",
452464
size,
453465
self.direction(),
454-
link
466+
match link {
467+
Some(l) => l,
468+
None => "",
469+
}
455470
)
456471
.unwrap();
457472
writeln!(

site/src/github.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,15 @@ pub async fn post_finished(data: &InputData) {
631631
"https://perf.rust-lang.org/compare.html?start={}&end={}",
632632
commit.parent_sha, commit.sha
633633
);
634+
let summary = categorize_benchmark(&commit, data).await;
634635
post_comment(
635636
&data.config,
636637
commit.pr,
637638
format!(
638639
"Finished benchmarking try commit ({}): [comparison url]({}).
639640
641+
Summary: {}
642+
640643
Benchmarking this pull request likely means that it is \
641644
perf-sensitive, so we're automatically marking it as not fit \
642645
for rolling up. Please note that if the perf results are \
@@ -649,10 +652,36 @@ regressions or improvements in the roll up.
649652
650653
@bors rollup=never
651654
@rustbot label: +S-waiting-on-review -S-waiting-on-perf",
652-
commit.sha, comparison_url
655+
commit.sha, comparison_url, summary
653656
),
654657
)
655658
.await;
656659
}
657660
}
658661
}
662+
663+
async fn categorize_benchmark(commit: &database::QueuedCommit, data: &InputData) -> String {
664+
let comparison = match crate::comparison::compare(
665+
collector::Bound::Commit(commit.parent_sha.clone()),
666+
collector::Bound::Commit(commit.sha.clone()),
667+
"instructions:u".to_owned(),
668+
data,
669+
)
670+
.await
671+
{
672+
Ok(c) => c,
673+
Err(_) => return String::from("ERROR categorizing benchmark run!"),
674+
};
675+
let summary = match crate::comparison::ComparisonSummary::summarize_comparison(&comparison) {
676+
Some(s) => s,
677+
None => return String::from("This benchmark run did not return any significant changes"),
678+
};
679+
680+
let mut result = format!("This change led to significant changes in compiler performance.\n");
681+
for change in summary.ordered_changes() {
682+
use std::fmt::Write;
683+
write!(result, "- ").unwrap();
684+
change.summary_line(&mut result, None)
685+
}
686+
result
687+
}

0 commit comments

Comments
 (0)