Skip to content

Commit 53f6df8

Browse files
authored
Merge pull request #1322 from rust-lang/summary-extended-stats
2 parents 8990eb4 + a77669f commit 53f6df8

File tree

3 files changed

+165
-80
lines changed

3 files changed

+165
-80
lines changed

site/src/api.rs

+2-1
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

+50-44
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ 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};
1717
use std::error::Error;
18+
use std::fmt::Write;
1819
use std::hash::Hash;
1920
use std::sync::Arc;
2021

@@ -44,11 +45,11 @@ pub async fn handle_triage(
4445
let mut before = start.clone();
4546

4647
let mut num_comparisons = 0;
47-
let stat = "instructions:u".to_owned();
48+
let stat = Stat::Instructions;
4849
let benchmark_map = ctxt.get_benchmark_category_map().await;
4950
loop {
5051
let comparison =
51-
match compare_given_commits(before, next.clone(), stat.clone(), ctxt, &master_commits)
52+
match compare_given_commits(before, next.clone(), stat, ctxt, &master_commits)
5253
.await
5354
.map_err(|e| format!("error comparing commits: {}", e))?
5455
{
@@ -171,14 +172,46 @@ async fn populate_report(
171172
(None, None) => return,
172173
};
173174

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

176177
if include_in_triage {
177178
let entry = report.entry(direction).or_default();
178179
entry.push(write_triage_summary(comparison, &primary, &secondary).await);
179180
}
180181
}
181182

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+
182215
/// A summary of a given comparison
183216
///
184217
/// This summary only includes changes that are significant and relevant (as determined by a change's magnitude).
@@ -366,7 +399,7 @@ impl ArtifactComparisonSummary {
366399
///
367400
/// For example, this can be used to determine if artifact comparisons with regressions should be labeled with the
368401
/// `perf-regression` GitHub label or should be shown in the perf triage report.
369-
pub(crate) fn deserves_attention(
402+
pub(crate) fn deserves_attention_icount(
370403
primary: &ArtifactComparisonSummary,
371404
secondary: &ArtifactComparisonSummary,
372405
) -> bool {
@@ -388,7 +421,6 @@ async fn write_triage_summary(
388421
primary: &ArtifactComparisonSummary,
389422
secondary: &ArtifactComparisonSummary,
390423
) -> String {
391-
use std::fmt::Write;
392424
let mut result = if let Some(pr) = comparison.b.pr {
393425
let title = github::pr_title(pr).await;
394426
format!(
@@ -415,8 +447,6 @@ pub fn write_summary_table(
415447
with_footnotes: bool,
416448
result: &mut String,
417449
) {
418-
use std::fmt::Write;
419-
420450
fn render_stat<F: FnOnce() -> Option<f64>>(count: usize, calculate: F) -> String {
421451
let value = if count > 0 { calculate() } else { None };
422452
value
@@ -538,16 +568,16 @@ pub fn write_summary_table(
538568
}),
539569
largest_change,
540570
]);
571+
}
541572

542-
if with_footnotes {
543-
writeln!(
544-
result,
545-
r#"
573+
pub fn write_summary_table_footer(result: &mut String) {
574+
writeln!(
575+
result,
576+
r#"
546577
[^1]: *number of relevant changes*
547578
[^2]: *the arithmetic mean of the percent change*"#
548-
)
549-
.unwrap();
550-
}
579+
)
580+
.unwrap();
551581
}
552582

553583
/// Compare two bounds on a given stat
@@ -556,7 +586,7 @@ pub fn write_summary_table(
556586
pub async fn compare(
557587
start: Bound,
558588
end: Bound,
559-
stat: String,
589+
stat: Stat,
560590
ctxt: &SiteCtxt,
561591
) -> Result<Option<ArtifactComparison>, BoxedError> {
562592
let master_commits = &ctxt.get_master_commits().commits;
@@ -568,7 +598,7 @@ pub async fn compare(
568598
async fn compare_given_commits(
569599
start: Bound,
570600
end: Bound,
571-
stat: String,
601+
stat: Stat,
572602
ctxt: &SiteCtxt,
573603
master_commits: &[collector::MasterCommit],
574604
) -> Result<Option<ArtifactComparison>, BoxedError> {
@@ -587,7 +617,7 @@ async fn compare_given_commits(
587617
.set::<String>(Tag::Benchmark, selector::Selector::All)
588618
.set::<String>(Tag::Scenario, selector::Selector::All)
589619
.set::<String>(Tag::Profile, selector::Selector::All)
590-
.set(Tag::Metric, selector::Selector::One(stat.clone()));
620+
.set(Tag::Metric, selector::Selector::One(stat.as_str()));
591621

592622
// `responses` contains series iterators. The first element in the iterator is the data
593623
// for `a` and the second is the data for `b`
@@ -834,7 +864,7 @@ impl HistoricalDataMap {
834864
ctxt: &SiteCtxt,
835865
from: ArtifactId,
836866
master_commits: &[collector::MasterCommit],
837-
stat: String,
867+
stat: Stat,
838868
) -> Result<Self, BoxedError> {
839869
let mut historical_data = HashMap::new();
840870

@@ -856,7 +886,7 @@ impl HistoricalDataMap {
856886
.set::<String>(Tag::Benchmark, selector::Selector::All)
857887
.set::<String>(Tag::Scenario, selector::Selector::All)
858888
.set::<String>(Tag::Profile, selector::Selector::All)
859-
.set(Tag::Metric, selector::Selector::One(stat));
889+
.set(Tag::Metric, selector::Selector::One(stat.as_str()));
860890

861891
let mut previous_commit_series = ctxt
862892
.statistic_series(query, previous_commits.clone())
@@ -1272,9 +1302,6 @@ mod tests {
12721302
| count[^1] | 3 | 0 | 0 | 0 | 3 |
12731303
| mean[^2] | 146.7% | N/A | N/A | N/A | 146.7% |
12741304
| max | 200.0% | N/A | N/A | N/A | 200.0% |
1275-
1276-
[^1]: *number of relevant changes*
1277-
[^2]: *the arithmetic mean of the percent change*
12781305
"#
12791306
.trim_start(),
12801307
);
@@ -1294,9 +1321,6 @@ mod tests {
12941321
| count[^1] | 0 | 0 | 3 | 0 | 3 |
12951322
| mean[^2] | N/A | N/A | -71.7% | N/A | -71.7% |
12961323
| max | N/A | N/A | -80.0% | N/A | -80.0% |
1297-
1298-
[^1]: *number of relevant changes*
1299-
[^2]: *the arithmetic mean of the percent change*
13001324
"#
13011325
.trim_start(),
13021326
);
@@ -1316,9 +1340,6 @@ mod tests {
13161340
| count[^1] | 0 | 0 | 0 | 3 | 0 |
13171341
| mean[^2] | N/A | N/A | N/A | -71.7% | N/A |
13181342
| max | N/A | N/A | N/A | -80.0% | N/A |
1319-
1320-
[^1]: *number of relevant changes*
1321-
[^2]: *the arithmetic mean of the percent change*
13221343
"#
13231344
.trim_start(),
13241345
);
@@ -1338,9 +1359,6 @@ mod tests {
13381359
| count[^1] | 0 | 3 | 0 | 0 | 0 |
13391360
| mean[^2] | N/A | 146.7% | N/A | N/A | N/A |
13401361
| max | N/A | 200.0% | N/A | N/A | N/A |
1341-
1342-
[^1]: *number of relevant changes*
1343-
[^2]: *the arithmetic mean of the percent change*
13441362
"#
13451363
.trim_start(),
13461364
);
@@ -1361,9 +1379,6 @@ mod tests {
13611379
| count[^1] | 2 | 0 | 2 | 0 | 4 |
13621380
| mean[^2] | 150.0% | N/A | -62.5% | N/A | 43.8% |
13631381
| max | 200.0% | N/A | -75.0% | N/A | 200.0% |
1364-
1365-
[^1]: *number of relevant changes*
1366-
[^2]: *the arithmetic mean of the percent change*
13671382
"#
13681383
.trim_start(),
13691384
);
@@ -1386,9 +1401,6 @@ mod tests {
13861401
| count[^1] | 2 | 1 | 2 | 1 | 4 |
13871402
| mean[^2] | 150.0% | 100.0% | -62.5% | -66.7% | 43.8% |
13881403
| max | 200.0% | 100.0% | -75.0% | -66.7% | 200.0% |
1389-
1390-
[^1]: *number of relevant changes*
1391-
[^2]: *the arithmetic mean of the percent change*
13921404
"#
13931405
.trim_start(),
13941406
);
@@ -1407,9 +1419,6 @@ mod tests {
14071419
| count[^1] | 1 | 0 | 1 | 0 | 2 |
14081420
| mean[^2] | 20.0% | N/A | -50.0% | N/A | -15.0% |
14091421
| max | 20.0% | N/A | -50.0% | N/A | -50.0% |
1410-
1411-
[^1]: *number of relevant changes*
1412-
[^2]: *the arithmetic mean of the percent change*
14131422
"#
14141423
.trim_start(),
14151424
);
@@ -1428,9 +1437,6 @@ mod tests {
14281437
| count[^1] | 1 | 0 | 1 | 0 | 2 |
14291438
| mean[^2] | 100.0% | N/A | -16.7% | N/A | 41.7% |
14301439
| max | 100.0% | N/A | -16.7% | N/A | 100.0% |
1431-
1432-
[^1]: *number of relevant changes*
1433-
[^2]: *the arithmetic mean of the percent change*
14341440
"#
14351441
.trim_start(),
14361442
);

0 commit comments

Comments
 (0)