Skip to content

Commit 935c4da

Browse files
committed
Turn Stat into an enum
1 parent 33a3461 commit 935c4da

File tree

3 files changed

+81
-51
lines changed

3 files changed

+81
-51
lines changed

site/src/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub mod bootstrap {
130130
}
131131

132132
pub mod comparison {
133+
use crate::comparison::Stat;
133134
use collector::Bound;
134135
use database::{BenchmarkData, Date};
135136
use serde::{Deserialize, Serialize};
@@ -139,7 +140,7 @@ pub mod comparison {
139140
pub struct Request {
140141
pub start: Bound,
141142
pub end: Bound,
142-
pub stat: String,
143+
pub stat: Stat,
143144
}
144145

145146
#[derive(Debug, Clone, Serialize, Deserialize)]

site/src/comparison.rs

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::selector::{self, Tag};
1010

1111
use collector::category::Category;
1212
use collector::Bound;
13-
use serde::Serialize;
13+
use serde::{Deserialize, Serialize};
1414

1515
use std::cmp::Ordering;
1616
use std::collections::{HashMap, HashSet};
@@ -45,11 +45,11 @@ pub async fn handle_triage(
4545
let mut before = start.clone();
4646

4747
let mut num_comparisons = 0;
48-
let stat = "instructions:u".to_owned();
48+
let stat = Stat::Instructions;
4949
let benchmark_map = ctxt.get_benchmark_category_map().await;
5050
loop {
5151
let comparison =
52-
match compare_given_commits(before, next.clone(), stat.clone(), ctxt, &master_commits)
52+
match compare_given_commits(before, next.clone(), stat, ctxt, &master_commits)
5353
.await
5454
.map_err(|e| format!("error comparing commits: {}", e))?
5555
{
@@ -172,14 +172,46 @@ async fn populate_report(
172172
(None, None) => return,
173173
};
174174

175-
let include_in_triage = deserves_attention(&primary, &secondary);
175+
let include_in_triage = deserves_attention_icount(&primary, &secondary);
176176

177177
if include_in_triage {
178178
let entry = report.entry(direction).or_default();
179179
entry.push(write_triage_summary(comparison, &primary, &secondary).await);
180180
}
181181
}
182182

183+
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
184+
pub enum Stat {
185+
#[serde(rename = "instructions:u")]
186+
Instructions,
187+
#[serde(rename = "cycles:u")]
188+
Cycles,
189+
#[serde(rename = "faults")]
190+
Faults,
191+
#[serde(rename = "max-rss")]
192+
MaxRSS,
193+
#[serde(rename = "task-clock")]
194+
TaskClock,
195+
#[serde(rename = "wall-time")]
196+
WallTime,
197+
#[serde(rename = "cpu-clock")]
198+
CpuClock,
199+
}
200+
201+
impl Stat {
202+
pub fn as_str(&self) -> &'static str {
203+
match self {
204+
Self::Instructions => "instructions:u",
205+
Self::Cycles => "cycles:u",
206+
Self::Faults => "faults",
207+
Self::MaxRSS => "max-rss",
208+
Self::TaskClock => "task-clock",
209+
Self::WallTime => "wall-time",
210+
Self::CpuClock => "cpu-clock",
211+
}
212+
}
213+
}
214+
183215
/// A summary of a given comparison
184216
///
185217
/// This summary only includes changes that are significant and relevant (as determined by a change's magnitude).
@@ -367,7 +399,7 @@ impl ArtifactComparisonSummary {
367399
///
368400
/// For example, this can be used to determine if artifact comparisons with regressions should be labeled with the
369401
/// `perf-regression` GitHub label or should be shown in the perf triage report.
370-
pub(crate) fn deserves_attention(
402+
pub(crate) fn deserves_attention_icount(
371403
primary: &ArtifactComparisonSummary,
372404
secondary: &ArtifactComparisonSummary,
373405
) -> bool {
@@ -384,6 +416,21 @@ pub(crate) fn deserves_attention(
384416
}
385417
}
386418

419+
pub(crate) fn deserves_attention_maxrss(
420+
primary: &ArtifactComparisonSummary,
421+
secondary: &ArtifactComparisonSummary,
422+
) -> bool {
423+
let primary_big_changes = primary
424+
.improvements()
425+
.filter(|comparison| comparison.magnitude() >= Magnitude::Large)
426+
.count();
427+
let secondary_big_changes = secondary
428+
.improvements()
429+
.filter(|comparison| comparison.magnitude() >= Magnitude::Large)
430+
.count();
431+
primary_big_changes >= 10 || secondary_big_changes >= 20
432+
}
433+
387434
async fn write_triage_summary(
388435
comparison: &ArtifactComparison,
389436
primary: &ArtifactComparisonSummary,
@@ -554,7 +601,7 @@ pub fn write_summary_table_footer(result: &mut String) {
554601
pub async fn compare(
555602
start: Bound,
556603
end: Bound,
557-
stat: String,
604+
stat: Stat,
558605
ctxt: &SiteCtxt,
559606
) -> Result<Option<ArtifactComparison>, BoxedError> {
560607
let master_commits = &ctxt.get_master_commits().commits;
@@ -566,7 +613,7 @@ pub async fn compare(
566613
async fn compare_given_commits(
567614
start: Bound,
568615
end: Bound,
569-
stat: String,
616+
stat: Stat,
570617
ctxt: &SiteCtxt,
571618
master_commits: &[collector::MasterCommit],
572619
) -> Result<Option<ArtifactComparison>, BoxedError> {
@@ -585,7 +632,7 @@ async fn compare_given_commits(
585632
.set::<String>(Tag::Benchmark, selector::Selector::All)
586633
.set::<String>(Tag::Scenario, selector::Selector::All)
587634
.set::<String>(Tag::Profile, selector::Selector::All)
588-
.set(Tag::Metric, selector::Selector::One(stat.clone()));
635+
.set(Tag::Metric, selector::Selector::One(stat.as_str()));
589636

590637
// `responses` contains series iterators. The first element in the iterator is the data
591638
// for `a` and the second is the data for `b`
@@ -832,7 +879,7 @@ impl HistoricalDataMap {
832879
ctxt: &SiteCtxt,
833880
from: ArtifactId,
834881
master_commits: &[collector::MasterCommit],
835-
stat: String,
882+
stat: Stat,
836883
) -> Result<Self, BoxedError> {
837884
let mut historical_data = HashMap::new();
838885

@@ -854,7 +901,7 @@ impl HistoricalDataMap {
854901
.set::<String>(Tag::Benchmark, selector::Selector::All)
855902
.set::<String>(Tag::Scenario, selector::Selector::All)
856903
.set::<String>(Tag::Profile, selector::Selector::All)
857-
.set(Tag::Metric, selector::Selector::One(stat));
904+
.set(Tag::Metric, selector::Selector::One(stat.as_str()));
858905

859906
let mut previous_commit_series = ctxt
860907
.statistic_series(query, previous_commits.clone())

site/src/github.rs

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::api::github::Issue;
22
use crate::comparison::{
3-
deserves_attention, write_summary_table, write_summary_table_footer, ArtifactComparisonSummary,
4-
Direction, Magnitude,
3+
deserves_attention_icount, deserves_attention_maxrss, write_summary_table,
4+
write_summary_table_footer, ArtifactComparisonSummary, Direction, Stat,
55
};
66
use crate::load::{Config, SiteCtxt, TryCommit};
77

@@ -568,23 +568,20 @@ async fn post_comparison_comment(ctxt: &SiteCtxt, commit: QueuedCommit, is_maste
568568
post_comment(&ctxt.config, pr, body).await;
569569
}
570570

571-
fn make_comparison_url(commit: &QueuedCommit, stat: Option<&str>) -> String {
572-
let mut url = format!(
573-
"https://perf.rust-lang.org/compare.html?start={}&end={}",
574-
commit.parent_sha, commit.sha
575-
);
576-
if let Some(stat) = stat {
577-
write!(&mut url, "&stat={stat}").unwrap();
578-
}
579-
url
571+
fn make_comparison_url(commit: &QueuedCommit, stat: Stat) -> String {
572+
format!(
573+
"https://perf.rust-lang.org/compare.html?start={}&end={}&stat={}",
574+
commit.parent_sha,
575+
commit.sha,
576+
stat.as_str()
577+
)
580578
}
581579

582580
async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit: bool) -> String {
583-
let inst_comparison_url = make_comparison_url(&commit, None);
584581
let comparison = match crate::comparison::compare(
585582
collector::Bound::Commit(commit.parent_sha.clone()),
586583
collector::Bound::Commit(commit.sha.clone()),
587-
"instructions:u".to_owned(),
584+
Stat::Instructions,
588585
ctxt,
589586
)
590587
.await
@@ -612,6 +609,7 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
612609
please file an issue in [rust-lang/rustc-perf](https://github.com/rust-lang/rustc-perf/issues/new).";
613610
let footer = format!("{DISAGREEMENT}{errors}");
614611

612+
let inst_comparison_url = make_comparison_url(&commit, Stat::Instructions);
615613
let mut message = format!(
616614
"Finished benchmarking commit ({sha}): [comparison url]({inst_comparison_url}).
617615
@@ -653,16 +651,16 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
653651
if let Some((primary, secondary)) = analyze_secondary_stat(
654652
ctxt,
655653
&commit,
656-
"max-rss",
654+
Stat::MaxRSS,
657655
&benchmark_map,
658-
is_max_rss_interesting,
656+
deserves_attention_maxrss,
659657
)
660658
.await
661659
{
662660
write!(
663661
&mut message,
664662
"\n## [Max RSS]({})",
665-
make_comparison_url(&commit, Some("max-rss"))
663+
make_comparison_url(&commit, Stat::MaxRSS)
666664
)
667665
.unwrap();
668666
write_summary_table(&primary, &secondary, true, &mut message);
@@ -680,36 +678,20 @@ async fn summarize_run(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit:
680678
message
681679
}
682680

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-
>(
681+
async fn analyze_secondary_stat<F>(
703682
ctxt: &SiteCtxt,
704683
commit: &QueuedCommit,
705-
stat: &str,
684+
stat: Stat,
706685
benchmark_map: &HashMap<Benchmark, Category>,
707686
is_interesting: F,
708-
) -> Option<(ArtifactComparisonSummary, ArtifactComparisonSummary)> {
687+
) -> Option<(ArtifactComparisonSummary, ArtifactComparisonSummary)>
688+
where
689+
F: FnOnce(&ArtifactComparisonSummary, &ArtifactComparisonSummary) -> bool,
690+
{
709691
let comparison = match crate::comparison::compare(
710692
collector::Bound::Commit(commit.parent_sha.clone()),
711693
collector::Bound::Commit(commit.sha.clone()),
712-
stat.to_string(),
694+
stat,
713695
ctxt,
714696
)
715697
.await
@@ -736,7 +718,7 @@ fn next_steps(
736718
direction: Option<Direction>,
737719
is_master_commit: bool,
738720
) -> String {
739-
let deserves_attention = deserves_attention(&primary, &secondary);
721+
let deserves_attention = deserves_attention_icount(&primary, &secondary);
740722
let label = match (deserves_attention, direction) {
741723
(true, Some(Direction::Regression | Direction::Mixed)) => "+perf-regression",
742724
_ => "-perf-regression",

0 commit comments

Comments
 (0)