Skip to content

Commit 33a3461

Browse files
committed
Include more stats in GH summary table
1 parent e1087d2 commit 33a3461

File tree

2 files changed

+99
-9
lines changed

2 files changed

+99
-9
lines changed

site/src/comparison.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use serde::Serialize;
1515
use std::cmp::Ordering;
1616
use std::collections::{HashMap, HashSet};
1717
use std::error::Error;
18+
use std::fmt::Write;
1819
use std::hash::Hash;
1920
use std::sync::Arc;
20-
use std::fmt::Write;
2121

2222
type BoxedError = Box<dyn Error + Send + Sync>;
2323

@@ -545,7 +545,7 @@ pub fn write_summary_table_footer(result: &mut String) {
545545
[^1]: *number of relevant changes*
546546
[^2]: *the arithmetic mean of the percent change*"#
547547
)
548-
.unwrap();
548+
.unwrap();
549549
}
550550

551551
/// Compare two bounds on a given stat

site/src/github.rs

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
use crate::api::github::Issue;
22
use crate::comparison::{
3-
deserves_attention, write_summary_table, ArtifactComparisonSummary, Direction,
3+
deserves_attention, write_summary_table, write_summary_table_footer, ArtifactComparisonSummary,
4+
Direction, Magnitude,
45
};
56
use crate::load::{Config, SiteCtxt, TryCommit};
67

78
use anyhow::Context as _;
8-
use database::{ArtifactId, QueuedCommit};
9+
use database::{ArtifactId, Benchmark, QueuedCommit};
910
use reqwest::header::USER_AGENT;
1011
use serde::{Deserialize, Serialize};
1112

12-
use std::collections::HashSet;
13+
use collector::category::Category;
14+
use std::collections::{HashMap, HashSet};
1315
use std::{fmt::Write, sync::Arc, time::Duration};
1416

1517
type BoxedError = Box<dyn std::error::Error + Send + Sync>;
@@ -566,13 +568,21 @@ async fn post_comparison_comment(ctxt: &SiteCtxt, commit: QueuedCommit, is_maste
566568
post_comment(&ctxt.config, pr, body).await;
567569
}
568570

569-
async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit: bool) -> String {
570-
let comparison_url = format!(
571+
fn make_comparison_url(commit: &QueuedCommit, stat: Option<&str>) -> String {
572+
let mut url = format!(
571573
"https://perf.rust-lang.org/compare.html?start={}&end={}",
572574
commit.parent_sha, commit.sha
573575
);
576+
if let Some(stat) = stat {
577+
write!(&mut url, "&stat={stat}").unwrap();
578+
}
579+
url
580+
}
581+
582+
async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit: bool) -> String {
583+
let inst_comparison_url = make_comparison_url(&commit, None);
574584
let comparison = match crate::comparison::compare(
575-
collector::Bound::Commit(commit.parent_sha),
585+
collector::Bound::Commit(commit.parent_sha.clone()),
576586
collector::Bound::Commit(commit.sha.clone()),
577587
"instructions:u".to_owned(),
578588
ctxt,
@@ -603,12 +613,19 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
603613
let footer = format!("{DISAGREEMENT}{errors}");
604614

605615
let mut message = format!(
606-
"Finished benchmarking commit ({sha}): [comparison url]({comparison_url}).
616+
"Finished benchmarking commit ({sha}): [comparison url]({inst_comparison_url}).
607617
608618
**Summary**: ",
609619
sha = commit.sha,
610620
);
611621

622+
let mut table_written = false;
623+
624+
write!(
625+
&mut message,
626+
"## [Instruction count]({inst_comparison_url})"
627+
)
628+
.unwrap();
612629
if !primary.is_relevant() && !secondary.is_relevant() {
613630
write!(
614631
&mut message,
@@ -630,6 +647,29 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
630647
.unwrap();
631648

632649
write_summary_table(&primary, &secondary, true, &mut message);
650+
table_written = true;
651+
}
652+
653+
if let Some((primary, secondary)) = analyze_secondary_stat(
654+
ctxt,
655+
&commit,
656+
"max-rss",
657+
&benchmark_map,
658+
is_max_rss_interesting,
659+
)
660+
.await
661+
{
662+
write!(
663+
&mut message,
664+
"\n## [Max RSS]({})",
665+
make_comparison_url(&commit, Some("max-rss"))
666+
)
667+
.unwrap();
668+
write_summary_table(&primary, &secondary, true, &mut message);
669+
table_written = true;
670+
}
671+
672+
if table_written {
633673
write_summary_table_footer(&mut message);
634674
}
635675

@@ -640,6 +680,56 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
640680
message
641681
}
642682

683+
// TODO: determine how should this work
684+
// Should this be separate from `deserves_attention`?
685+
fn is_max_rss_interesting(
686+
primary: &ArtifactComparisonSummary,
687+
_secondary: &ArtifactComparisonSummary,
688+
) -> bool {
689+
if primary
690+
.largest_change()
691+
.map(|c| c.magnitude() >= Magnitude::Large)
692+
.unwrap_or(false)
693+
{
694+
return true;
695+
}
696+
697+
primary.num_changes() >= 20
698+
}
699+
700+
async fn analyze_secondary_stat<
701+
F: FnOnce(&ArtifactComparisonSummary, &ArtifactComparisonSummary) -> bool,
702+
>(
703+
ctxt: &SiteCtxt,
704+
commit: &QueuedCommit,
705+
stat: &str,
706+
benchmark_map: &HashMap<Benchmark, Category>,
707+
is_interesting: F,
708+
) -> Option<(ArtifactComparisonSummary, ArtifactComparisonSummary)> {
709+
let comparison = match crate::comparison::compare(
710+
collector::Bound::Commit(commit.parent_sha.clone()),
711+
collector::Bound::Commit(commit.sha.clone()),
712+
stat.to_string(),
713+
ctxt,
714+
)
715+
.await
716+
{
717+
Ok(Some(c)) => c,
718+
_ => return None,
719+
};
720+
721+
let (primary, secondary) = comparison.summarize_by_category(benchmark_map);
722+
if !primary.is_relevant() && !secondary.is_relevant() {
723+
return None;
724+
}
725+
726+
if is_interesting(&primary, &secondary) {
727+
Some((primary, secondary))
728+
} else {
729+
None
730+
}
731+
}
732+
643733
fn next_steps(
644734
primary: ArtifactComparisonSummary,
645735
secondary: ArtifactComparisonSummary,

0 commit comments

Comments
 (0)