Skip to content

Commit 2cabb6a

Browse files
authored
Merge pull request #1605 from Kobzol/embed-stable-benchmarks
Embed information about stable benchmarks into the `site` binary
2 parents 0fcb3f8 + bdb8c54 commit 2cabb6a

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

collector/src/benchmark/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn default_runs() -> usize {
2424
/// This is the internal representation of an individual benchmark's
2525
/// perf-config.json file.
2626
#[derive(Debug, Clone, serde::Deserialize)]
27-
struct BenchmarkConfig {
27+
pub struct BenchmarkConfig {
2828
cargo_opts: Option<String>,
2929
cargo_rustc_opts: Option<String>,
3030
cargo_toml: Option<String>,
@@ -53,6 +53,12 @@ struct BenchmarkConfig {
5353
excluded_scenarios: HashSet<Scenario>,
5454
}
5555

56+
impl BenchmarkConfig {
57+
pub fn category(&self) -> Category {
58+
self.category
59+
}
60+
}
61+
5662
#[derive(Ord, PartialOrd, Eq, PartialEq, Clone, Hash)]
5763
pub struct BenchmarkName(pub String);
5864

site/src/request_handlers/dashboard.rs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
use collector::benchmark::category::Category;
2+
use collector::benchmark::BenchmarkConfig;
3+
use lazy_static::lazy_static;
4+
use rust_embed::RustEmbed;
5+
use std::path::Path;
16
use std::sync::Arc;
27

38
use crate::api::{dashboard, ServerResult};
@@ -74,23 +79,14 @@ pub async fn handle_dashboard(ctxt: Arc<SiteCtxt>) -> ServerResult<dashboard::Re
7479
.collect::<Vec<_>>(),
7580
);
7681

82+
lazy_static! {
83+
static ref STABLE_BENCHMARKS: Vec<String> = get_stable_benchmarks();
84+
}
85+
7786
let query = selector::Query::new()
78-
// FIXME: don't hardcode the stabilized benchmarks
79-
// This list was found via:
80-
// `rg supports.stable collector/compile-benchmarks/ -tjson -c --sort path`
8187
.set(
8288
selector::Tag::Benchmark,
83-
selector::Selector::Subset(vec![
84-
"encoding",
85-
"futures",
86-
"html5ever",
87-
"inflate",
88-
"piston-image",
89-
"regex",
90-
"style-servo",
91-
"syn",
92-
"tokio-webpush-simple",
93-
]),
89+
selector::Selector::Subset(STABLE_BENCHMARKS.clone()),
9490
)
9591
.set(selector::Tag::Metric, selector::Selector::One("wall-time"));
9692

@@ -153,6 +149,44 @@ pub async fn handle_dashboard(ctxt: Arc<SiteCtxt>) -> ServerResult<dashboard::Re
153149
})
154150
}
155151

152+
#[derive(RustEmbed)]
153+
#[folder = "../collector/compile-benchmarks"]
154+
#[include = "*/perf-config.json"]
155+
struct EmbeddedBenchmarks;
156+
157+
/// The configurations of compile-time benchmarks are embedded directly within the binary using
158+
/// the `Benchmarks` struct.
159+
///
160+
/// Here we parse the benchmarks configurations and return only stable benchmarks.
161+
fn get_stable_benchmarks() -> Vec<String> {
162+
EmbeddedBenchmarks::iter()
163+
.filter_map(|path| EmbeddedBenchmarks::get(&path).map(|file| (file, path)))
164+
.filter_map(|(file, path)| {
165+
let config: BenchmarkConfig = match serde_json::from_slice(&file.data) {
166+
Ok(config) => config,
167+
Err(error) => {
168+
log::error!(
169+
"Cannot deserialized stored perf-config.json from {path}: {error:?}"
170+
);
171+
return None;
172+
}
173+
};
174+
if config.category() == Category::Stable {
175+
Some(
176+
Path::new(path.as_ref())
177+
.parent()
178+
.unwrap()
179+
.to_str()
180+
.unwrap()
181+
.to_string(),
182+
)
183+
} else {
184+
None
185+
}
186+
})
187+
.collect()
188+
}
189+
156190
pub struct ByProfile<T> {
157191
pub check: T,
158192
pub debug: T,

0 commit comments

Comments
 (0)