Skip to content

Commit d0aadd3

Browse files
committed
Explicitly enumerate all known metrics in the Metric enum
1 parent 4b1dbfc commit d0aadd3

File tree

2 files changed

+55
-21
lines changed

2 files changed

+55
-21
lines changed

site/src/comparison.rs

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub async fn handle_triage(
4545
let mut before = start.clone();
4646

4747
let mut num_comparisons = 0;
48-
let metric = Metric::Instructions;
48+
let metric = Metric::InstructionsUser;
4949
let benchmark_map = ctxt.get_benchmark_category_map().await;
5050
loop {
5151
let comparison =
@@ -180,34 +180,48 @@ async fn populate_report(
180180
}
181181
}
182182

183+
/// This enum contains all "known" metrics coming from rustc or profiling tools that we know
184+
/// (and care) about.
183185
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
184186
pub enum Metric {
185-
#[serde(rename = "instructions:u")]
186-
Instructions,
187+
#[serde(rename = "context-switches")]
188+
ContextSwitches,
189+
#[serde(rename = "cpu-clock")]
190+
CpuClock,
191+
#[serde(rename = "cpu-clock:u")]
192+
CpuClockUser,
187193
#[serde(rename = "cycles:u")]
188-
Cycles,
194+
CyclesUser,
189195
#[serde(rename = "faults")]
190196
Faults,
197+
#[serde(rename = "faults:u")]
198+
FaultsUser,
199+
#[serde(rename = "instructions:u")]
200+
InstructionsUser,
191201
#[serde(rename = "max-rss")]
192202
MaxRSS,
193203
#[serde(rename = "task-clock")]
194204
TaskClock,
205+
#[serde(rename = "task-clock:u")]
206+
TaskClockUser,
195207
#[serde(rename = "wall-time")]
196208
WallTime,
197-
#[serde(rename = "cpu-clock")]
198-
CpuClock,
199209
}
200210

201211
impl Metric {
202-
pub fn as_str(&self) -> &'static str {
212+
pub fn as_str(&self) -> &str {
203213
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",
214+
Metric::ContextSwitches => "context-switches",
215+
Metric::CpuClock => "cpu-clock",
216+
Metric::CpuClockUser => "cpu-clock:u",
217+
Metric::CyclesUser => "cycles:u",
218+
Metric::Faults => "faults",
219+
Metric::FaultsUser => "faults:u",
220+
Metric::InstructionsUser => "instructions:u",
221+
Metric::MaxRSS => "max-rss",
222+
Metric::TaskClock => "task-clock",
223+
Metric::TaskClockUser => "task-clock:u",
224+
Metric::WallTime => "wall-time",
211225
}
212226
}
213227

@@ -232,8 +246,9 @@ impl Metric {
232246
}
233247
}
234248

249+
/// Currently, we conservatively consider everything except instructions to be noisy.
235250
fn is_typically_noisy(&self) -> bool {
236-
!matches!(self, Self::Instructions)
251+
!matches!(self, Self::InstructionsUser)
237252
}
238253
}
239254

@@ -1484,6 +1499,24 @@ mod tests {
14841499
);
14851500
}
14861501

1502+
#[test]
1503+
fn parse_metric_instructions() {
1504+
let metric: Metric = serde_json::from_str(r#""instructions:u""#).unwrap();
1505+
assert!(matches!(metric, Metric::InstructionsUser));
1506+
}
1507+
1508+
#[test]
1509+
fn parse_metric_cycles() {
1510+
let metric: Metric = serde_json::from_str(r#""cycles:u""#).unwrap();
1511+
assert!(matches!(metric, Metric::CyclesUser));
1512+
}
1513+
1514+
#[test]
1515+
fn parse_metric_max_rss() {
1516+
let metric: Metric = serde_json::from_str(r#""max-rss""#).unwrap();
1517+
assert!(matches!(metric, Metric::MaxRSS));
1518+
}
1519+
14871520
// (category, before, after)
14881521
fn check_table(values: Vec<(Category, f64, f64)>, expected: &str) {
14891522
let mut primary_comparisons = HashSet::new();
@@ -1499,7 +1532,7 @@ mod tests {
14991532
benchmark: index.to_string().as_str().into(),
15001533
profile: Profile::Check,
15011534
scenario: Scenario::Empty,
1502-
metric: Metric::Instructions,
1535+
metric: Metric::InstructionsUser,
15031536
historical_data: None,
15041537
results: (before, after),
15051538
});

site/src/github.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,11 @@ async fn summarize_run(
608608
let mut message = format!(
609609
"Finished benchmarking commit ({sha}): [comparison url]({comparison_url}).\n\n",
610610
sha = commit.sha,
611-
comparison_url = make_comparison_url(&commit, Metric::Instructions)
611+
comparison_url = make_comparison_url(&commit, Metric::InstructionsUser)
612612
);
613613

614-
let inst_comparison = calculate_metric_comparison(ctxt, &commit, Metric::Instructions).await?;
614+
let inst_comparison =
615+
calculate_metric_comparison(ctxt, &commit, Metric::InstructionsUser).await?;
615616

616617
let errors = if !inst_comparison.newly_failed_benchmarks.is_empty() {
617618
let benchmarks = inst_comparison
@@ -632,7 +633,7 @@ async fn summarize_run(
632633
let metrics = vec![
633634
(
634635
"Instruction count",
635-
Metric::Instructions,
636+
Metric::InstructionsUser,
636637
false,
637638
inst_comparison,
638639
),
@@ -644,9 +645,9 @@ async fn summarize_run(
644645
),
645646
(
646647
"Cycles",
647-
Metric::Cycles,
648+
Metric::CyclesUser,
648649
true,
649-
calculate_metric_comparison(ctxt, &commit, Metric::Cycles).await?,
650+
calculate_metric_comparison(ctxt, &commit, Metric::CyclesUser).await?,
650651
),
651652
];
652653

0 commit comments

Comments
 (0)