Skip to content

Commit b6e7004

Browse files
committed
Simplify compile time benchmark query result gathering
1 parent 77c70db commit b6e7004

File tree

3 files changed

+32
-119
lines changed

3 files changed

+32
-119
lines changed

site/src/comparison.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,10 +952,14 @@ where
952952
} else {
953953
continue;
954954
};
955-
let benchmark = *response.path.get::<Benchmark>().unwrap();
956-
let profile = *response.path.get::<Profile>().unwrap();
957-
let scenario = *response.path.get::<Scenario>().unwrap();
958-
stats.insert((benchmark, profile, scenario), value);
955+
stats.insert(
956+
(
957+
response.key.benchmark,
958+
response.key.profile,
959+
response.key.scenario,
960+
),
961+
value,
962+
);
959963
}
960964
stats
961965
}

site/src/request_handlers/graph.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::Arc;
44

55
use crate::api::graphs::GraphKind;
66
use crate::api::{graph, graphs, ServerResult};
7-
use crate::db::{self, ArtifactId, Benchmark, Profile, Scenario};
7+
use crate::db::{self, ArtifactId, Profile, Scenario};
88
use crate::interpolate::IsInterpolated;
99
use crate::load::SiteCtxt;
1010
use crate::selector::{CompileBenchmarkQuery, Selector, SeriesResponse};
@@ -119,9 +119,9 @@ async fn create_graphs(
119119
}
120120

121121
for response in interpolated_responses {
122-
let benchmark = response.path.get::<Benchmark>()?.to_string();
123-
let profile = *response.path.get::<Profile>()?;
124-
let scenario = response.path.get::<Scenario>()?.to_string();
122+
let benchmark = response.key.benchmark.to_string();
123+
let profile = response.key.profile;
124+
let scenario = response.key.scenario.to_string();
125125
let graph_series = graph_series(response.series.into_iter(), request.kind);
126126

127127
benchmarks
@@ -188,9 +188,9 @@ fn create_summary(
188188
let baseline_responses = interpolated_responses
189189
.iter()
190190
.filter(|sr| {
191-
let p = sr.path.get::<Profile>().unwrap();
192-
let s = sr.path.get::<Scenario>().unwrap();
193-
*p == profile && *s == Scenario::Empty
191+
let p = sr.key.profile;
192+
let s = sr.key.scenario;
193+
p == profile && s == Scenario::Empty
194194
})
195195
.map(|sr| sr.series.iter().cloned())
196196
.collect();
@@ -205,9 +205,9 @@ fn create_summary(
205205
let summary_case_responses = interpolated_responses
206206
.iter()
207207
.filter(|sr| {
208-
let p = sr.path.get::<Profile>().unwrap();
209-
let s = sr.path.get::<Scenario>().unwrap();
210-
*p == profile && *s == scenario
208+
let p = sr.key.profile;
209+
let s = sr.key.scenario;
210+
p == profile && s == scenario
211211
})
212212
.map(|sr| sr.series.iter().cloned())
213213
.collect();

site/src/selector.rs

Lines changed: 14 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -110,73 +110,6 @@ impl Iterator for ArtifactIdIter {
110110
}
111111
}
112112

113-
#[derive(Copy, Debug, Clone, PartialEq, Eq, Hash)]
114-
pub enum Tag {
115-
Benchmark,
116-
Profile,
117-
Scenario,
118-
Metric,
119-
}
120-
121-
pub trait GetValue {
122-
fn value(component: &PathComponent) -> Option<&Self>;
123-
}
124-
125-
impl GetValue for Benchmark {
126-
fn value(component: &PathComponent) -> Option<&Self> {
127-
match component {
128-
PathComponent::Benchmark(v) => Some(v),
129-
_ => None,
130-
}
131-
}
132-
}
133-
134-
impl GetValue for Profile {
135-
fn value(component: &PathComponent) -> Option<&Self> {
136-
match component {
137-
PathComponent::Profile(v) => Some(v),
138-
_ => None,
139-
}
140-
}
141-
}
142-
143-
impl GetValue for Scenario {
144-
fn value(component: &PathComponent) -> Option<&Self> {
145-
match component {
146-
PathComponent::Scenario(v) => Some(v),
147-
_ => None,
148-
}
149-
}
150-
}
151-
152-
impl GetValue for database::Metric {
153-
fn value(component: &PathComponent) -> Option<&Self> {
154-
match component {
155-
PathComponent::Metric(v) => Some(v),
156-
_ => None,
157-
}
158-
}
159-
}
160-
161-
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
162-
pub enum PathComponent {
163-
Benchmark(Benchmark),
164-
Profile(Profile),
165-
Scenario(Scenario),
166-
Metric(database::Metric),
167-
}
168-
169-
impl PathComponent {
170-
pub fn as_tag(&self) -> Tag {
171-
match self {
172-
PathComponent::Benchmark(_) => Tag::Benchmark,
173-
PathComponent::Profile(_) => Tag::Profile,
174-
PathComponent::Scenario(_) => Tag::Scenario,
175-
PathComponent::Metric(_) => Tag::Metric,
176-
}
177-
}
178-
}
179-
180113
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
181114
pub enum Selector<T> {
182115
All,
@@ -227,14 +160,14 @@ impl<T> Selector<T> {
227160

228161
#[derive(Debug)]
229162
pub struct SeriesResponse<T> {
230-
pub path: Path,
163+
pub key: CompileBenchmarkKey,
231164
pub series: T,
232165
}
233166

234167
impl<T> SeriesResponse<T> {
235168
pub fn map<U>(self, m: impl FnOnce(T) -> U) -> SeriesResponse<U> {
236169
SeriesResponse {
237-
path: self.path,
170+
key: self.key,
238171
series: m(self.series),
239172
}
240173
}
@@ -248,37 +181,6 @@ impl<T> SeriesResponse<T> {
248181
}
249182
}
250183

251-
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
252-
pub struct Path {
253-
path: Vec<PathComponent>,
254-
}
255-
256-
impl Path {
257-
pub fn new() -> Self {
258-
Self { path: vec![] }
259-
}
260-
261-
pub fn set(mut self, component: PathComponent) -> Self {
262-
if let Some(idx) = self
263-
.path
264-
.iter()
265-
.position(|c| c.as_tag() == component.as_tag())
266-
{
267-
self.path[idx] = component;
268-
} else {
269-
self.path.push(component);
270-
}
271-
self
272-
}
273-
274-
pub fn get<V: 'static + GetValue>(&self) -> Result<&V, String> {
275-
self.path
276-
.iter()
277-
.find_map(V::value)
278-
.ok_or_else(|| format!("query must have {:?} selector", std::any::type_name::<V>()))
279-
}
280-
}
281-
282184
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
283185
pub struct CompileBenchmarkQuery {
284186
benchmark: Selector<String>,
@@ -327,6 +229,13 @@ impl CompileBenchmarkQuery {
327229
}
328230
}
329231

232+
#[derive(Debug)]
233+
pub struct CompileBenchmarkKey {
234+
pub benchmark: Benchmark,
235+
pub profile: Profile,
236+
pub scenario: Scenario,
237+
}
238+
330239
impl SiteCtxt {
331240
pub async fn compile_statistic_series(
332241
&self,
@@ -407,11 +316,11 @@ impl StatisticSeries {
407316
points.into_iter()
408317
},
409318
},
410-
path: Path::new()
411-
.set(PathComponent::Benchmark(benchmark))
412-
.set(PathComponent::Profile(profile))
413-
.set(PathComponent::Scenario(scenario))
414-
.set(PathComponent::Metric(metric)),
319+
key: CompileBenchmarkKey {
320+
benchmark,
321+
profile,
322+
scenario,
323+
},
415324
}
416325
})
417326
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)