Skip to content

Commit 77c70db

Browse files
committed
Simplify compile time benchmark querying
1 parent 3ad5bf1 commit 77c70db

File tree

5 files changed

+93
-132
lines changed

5 files changed

+93
-132
lines changed

site/src/comparison.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ use crate::api;
66
use crate::db::{ArtifactId, Benchmark, Lookup, Profile, Scenario};
77
use crate::github;
88
use crate::load::SiteCtxt;
9-
use crate::selector::{self, Tag};
9+
use crate::selector::{self};
1010

1111
use collector::benchmark::category::Category;
1212
use collector::Bound;
1313
use serde::{Deserialize, Serialize};
1414

1515
use database::CommitType;
16+
use serde::de::IntoDeserializer;
1617
use std::cmp;
1718
use std::collections::{HashMap, HashSet};
1819
use std::error::Error;
1920
use std::fmt::Write;
2021
use std::hash::Hash;
2122
use std::iter;
2223
use std::ops::Deref;
24+
use std::str::FromStr;
2325
use std::sync::Arc;
2426

2527
type BoxedError = Box<dyn Error + Send + Sync>;
@@ -259,6 +261,15 @@ pub enum Metric {
259261
DocFilesCount,
260262
}
261263

264+
impl FromStr for Metric {
265+
type Err = String;
266+
267+
fn from_str(s: &str) -> Result<Self, Self::Err> {
268+
Metric::deserialize(s.into_deserializer())
269+
.map_err(|e: serde::de::value::Error| format!("Unknown metric `{s}`: {e:?}"))
270+
}
271+
}
272+
262273
impl Metric {
263274
pub fn as_str(&self) -> &str {
264275
match self {
@@ -787,15 +798,11 @@ async fn compare_given_commits(
787798
let aids = Arc::new(vec![a.clone(), b.clone()]);
788799

789800
// get all crates, cache, and profile combinations for the given metric
790-
let query = selector::Query::new()
791-
.set::<String>(Tag::Benchmark, selector::Selector::All)
792-
.set::<String>(Tag::Scenario, selector::Selector::All)
793-
.set::<String>(Tag::Profile, selector::Selector::All)
794-
.set(Tag::Metric, selector::Selector::One(metric.as_str()));
801+
let query = selector::CompileBenchmarkQuery::all_for_metric(metric);
795802

796803
// `responses` contains series iterators. The first element in the iterator is the data
797804
// for `a` and the second is the data for `b`
798-
let mut responses = ctxt.statistic_series(query.clone(), aids).await?;
805+
let mut responses = ctxt.compile_statistic_series(query, aids).await?;
799806

800807
let conn = ctxt.conn().await;
801808
let statistics_for_a = statistics_from_series(&mut responses);
@@ -1072,14 +1079,10 @@ impl HistoricalDataMap {
10721079
}
10731080

10741081
// get all crates, cache, and profile combinations for the given metric
1075-
let query = selector::Query::new()
1076-
.set::<String>(Tag::Benchmark, selector::Selector::All)
1077-
.set::<String>(Tag::Scenario, selector::Selector::All)
1078-
.set::<String>(Tag::Profile, selector::Selector::All)
1079-
.set(Tag::Metric, selector::Selector::One(metric.as_str()));
1082+
let query = selector::CompileBenchmarkQuery::all_for_metric(metric);
10801083

10811084
let mut previous_commit_series = ctxt
1082-
.statistic_series(query, previous_commits.clone())
1085+
.compile_statistic_series(query, previous_commits.clone())
10831086
.await?;
10841087

10851088
for _ in previous_commits.iter() {

site/src/request_handlers/dashboard.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::Path;
66
use std::sync::Arc;
77

88
use crate::api::{dashboard, ServerResult};
9+
use crate::comparison::Metric;
910
use crate::db::{self, ArtifactId, Profile, Scenario};
1011
use crate::load::SiteCtxt;
1112
use crate::selector;
@@ -83,12 +84,9 @@ pub async fn handle_dashboard(ctxt: Arc<SiteCtxt>) -> ServerResult<dashboard::Re
8384
static ref STABLE_BENCHMARKS: Vec<String> = get_stable_benchmarks();
8485
}
8586

86-
let query = selector::Query::new()
87-
.set(
88-
selector::Tag::Benchmark,
89-
selector::Selector::Subset(STABLE_BENCHMARKS.clone()),
90-
)
91-
.set(selector::Tag::Metric, selector::Selector::One("wall-time"));
87+
let query = selector::CompileBenchmarkQuery::new()
88+
.benchmark(selector::Selector::Subset(STABLE_BENCHMARKS.clone()))
89+
.metric(selector::Selector::One(Metric::WallTime));
9290

9391
let summary_scenarios = ctxt.summary_scenarios();
9492
let by_profile = ByProfile::new::<String, _, _>(|profile| {
@@ -100,11 +98,11 @@ pub async fn handle_dashboard(ctxt: Arc<SiteCtxt>) -> ServerResult<dashboard::Re
10098
let mut cases = dashboard::Cases::default();
10199
for scenario in summary_scenarios.iter() {
102100
let responses = ctxt
103-
.statistic_series(
101+
.compile_statistic_series(
104102
query
105103
.clone()
106-
.set(selector::Tag::Profile, selector::Selector::One(profile))
107-
.set(selector::Tag::Scenario, selector::Selector::One(scenario)),
104+
.profile(selector::Selector::One(profile))
105+
.scenario(selector::Selector::One(*scenario)),
108106
aids.clone(),
109107
)
110108
.await?;

site/src/request_handlers/graph.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::api::{graph, graphs, ServerResult};
77
use crate::db::{self, ArtifactId, Benchmark, Profile, Scenario};
88
use crate::interpolate::IsInterpolated;
99
use crate::load::SiteCtxt;
10-
use crate::selector::{Query, Selector, SeriesResponse, Tag};
10+
use crate::selector::{CompileBenchmarkQuery, Selector, SeriesResponse};
1111

1212
pub async fn handle_graph(
1313
request: graph::Request,
@@ -57,12 +57,12 @@ async fn create_graph(
5757
) -> ServerResult<graph::Response> {
5858
let artifact_ids = artifact_ids_for_range(&ctxt, request.start, request.end);
5959
let mut series_iterator = ctxt
60-
.statistic_series(
61-
Query::new()
62-
.set::<String>(Tag::Benchmark, Selector::One(request.benchmark))
63-
.set::<String>(Tag::Profile, Selector::One(request.profile))
64-
.set::<String>(Tag::Scenario, Selector::One(request.scenario))
65-
.set::<String>(Tag::Metric, Selector::One(request.metric)),
60+
.compile_statistic_series(
61+
CompileBenchmarkQuery::new()
62+
.benchmark(Selector::One(request.benchmark))
63+
.profile(Selector::One(request.profile.parse()?))
64+
.scenario(Selector::One(request.scenario.parse()?))
65+
.metric(Selector::One(request.metric.parse()?)),
6666
Arc::new(artifact_ids),
6767
)
6868
.await?
@@ -95,16 +95,17 @@ async fn create_graphs(
9595
};
9696

9797
let benchmark_selector = create_selector(&request.benchmark);
98-
let profile_selector = create_selector(&request.profile);
99-
let scenario_selector = create_selector(&request.scenario);
98+
let profile_selector = create_selector(&request.profile).try_map(|v| v.parse::<Profile>())?;
99+
let scenario_selector =
100+
create_selector(&request.scenario).try_map(|v| v.parse::<Scenario>())?;
100101

101102
let interpolated_responses: Vec<_> = ctxt
102-
.statistic_series(
103-
Query::new()
104-
.set::<String>(Tag::Benchmark, benchmark_selector)
105-
.set::<String>(Tag::Profile, profile_selector)
106-
.set::<String>(Tag::Scenario, scenario_selector)
107-
.set::<String>(Tag::Metric, Selector::One(request.stat)),
103+
.compile_statistic_series(
104+
CompileBenchmarkQuery::new()
105+
.benchmark(benchmark_selector)
106+
.profile(profile_selector)
107+
.scenario(scenario_selector)
108+
.metric(Selector::One(request.stat.parse()?)),
108109
artifact_ids.clone(),
109110
)
110111
.await?

site/src/request_handlers/self_profile.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use hyper::StatusCode;
1010

1111
use crate::api::self_profile::{ArtifactSize, ArtifactSizeDelta};
1212
use crate::api::{self_profile, self_profile_processed, self_profile_raw, ServerResult};
13+
use crate::comparison::Metric;
1314
use crate::db::ArtifactId;
1415
use crate::load::SiteCtxt;
15-
use crate::selector::{self, Tag};
16+
use crate::selector::{self};
1617
use crate::self_profile::{
1718
extract_profiling_data, fetch_raw_self_profile_data, get_self_profile_raw_data,
1819
};
@@ -582,17 +583,11 @@ pub async fn handle_self_profile(
582583
.ok()
583584
.ok_or("sort_idx needs to be i32".to_string())?;
584585

585-
let query = selector::Query::new()
586-
.set(Tag::Benchmark, selector::Selector::One(bench_name))
587-
.set(Tag::Profile, selector::Selector::One(profile))
588-
.set(
589-
Tag::Scenario,
590-
selector::Selector::One(body.scenario.clone()),
591-
)
592-
.set(
593-
Tag::Metric,
594-
selector::Selector::One("cpu-clock".to_string()),
595-
);
586+
let query = selector::CompileBenchmarkQuery::new()
587+
.benchmark(selector::Selector::One(bench_name.to_string()))
588+
.profile(selector::Selector::One(profile.parse().unwrap()))
589+
.scenario(selector::Selector::One(scenario))
590+
.metric(selector::Selector::One(Metric::CpuClock));
596591

597592
// Helper for finding an `ArtifactId` based on a commit sha
598593
let find_aid = |commit: &str| {
@@ -607,7 +602,9 @@ pub async fn handle_self_profile(
607602
}
608603
let commits = Arc::new(commits);
609604

610-
let mut cpu_responses = ctxt.statistic_series(query, commits.clone()).await?;
605+
let mut cpu_responses = ctxt
606+
.compile_statistic_series(query, commits.clone())
607+
.await?;
611608
assert_eq!(cpu_responses.len(), 1, "all selectors are exact");
612609
let mut cpu_response = cpu_responses.remove(0).series;
613610

0 commit comments

Comments
 (0)