Skip to content

Commit 35f451b

Browse files
committed
Simplify graph data query formation
1 parent 5853fad commit 35f451b

File tree

1 file changed

+20
-41
lines changed

1 file changed

+20
-41
lines changed

site/src/request_handlers/graph.rs

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ async fn handle_graph_impl(
9595
let range = ctxt.data_range(body.start.clone()..=body.end.clone());
9696
let commits: Arc<Vec<_>> = Arc::new(range.iter().map(|c| c.clone().into()).collect());
9797

98+
let metric: database::Metric = body.stat.parse().unwrap();
9899
let metric_selector = Selector::One(body.stat.clone());
99100

100101
let series = ctxt
@@ -117,47 +118,30 @@ async fn handle_graph_impl(
117118
.collect::<Vec<_>>();
118119

119120
let mut baselines = HashMap::new();
120-
let c = commits.clone();
121-
let baselines = &mut baselines;
122121

123-
let summary_queries = iproduct!(
122+
let summary_query_cases = iproduct!(
124123
ctxt.summary_scenarios(),
125-
vec![Profile::Check, Profile::Debug, Profile::Opt],
126-
vec![body.stat.clone()]
127-
)
128-
.map(|(scenario, profile, metric)| {
129-
Query::new()
124+
vec![Profile::Check, Profile::Debug, Profile::Opt]
125+
);
126+
127+
for (scenario, profile) in summary_query_cases {
128+
let query = Query::new()
130129
.set::<String>(Tag::Benchmark, Selector::All)
131130
.set(Tag::Profile, Selector::One(profile))
132131
.set(Tag::Scenario, Selector::One(scenario))
133-
.set::<String>(Tag::Metric, Selector::One(metric))
134-
});
132+
.set(Tag::Metric, metric_selector.clone());
135133

136-
for query in summary_queries {
137-
let profile = query
138-
.get(Tag::Profile)
139-
.unwrap()
140-
.raw
141-
.assert_one()
142-
.parse::<Profile>()
143-
.unwrap();
144-
let scenario = query
145-
.get(Tag::Scenario)
146-
.unwrap()
147-
.raw
148-
.assert_one()
149-
.parse::<Scenario>()
150-
.unwrap();
151-
let q = Query::new()
134+
let baseline_query = Query::new()
152135
.set::<String>(Tag::Benchmark, Selector::All)
153136
.set(Tag::Profile, Selector::One(profile))
154137
.set(Tag::Scenario, Selector::One(Scenario::Empty))
155-
.set(Tag::Metric, query.get(Tag::Metric).unwrap().raw.clone());
156-
let against = match baselines.entry(q.clone()) {
138+
.set(Tag::Metric, metric_selector.clone());
139+
140+
let baseline = match baselines.entry(baseline_query.clone()) {
157141
std::collections::hash_map::Entry::Occupied(o) => *o.get(),
158142
std::collections::hash_map::Entry::Vacant(v) => {
159143
let value = db::average(
160-
ctxt.statistic_series(q, c.clone())
144+
ctxt.statistic_series(baseline_query, commits.clone())
161145
.await?
162146
.into_iter()
163147
.map(|sr| sr.interpolate().series)
@@ -168,29 +152,24 @@ async fn handle_graph_impl(
168152
*v.insert(value)
169153
}
170154
};
171-
let averaged = db::average(
155+
156+
let avg_vs_baseline = db::average(
172157
ctxt.statistic_series(query.clone(), commits.clone())
173158
.await?
174159
.into_iter()
175160
.map(|sr| sr.interpolate().series)
176161
.collect(),
177162
)
178-
.map(|((c, d), i)| ((c, Some(d.expect("interpolated") / against)), i));
179-
let graph_data = to_graph_points(body.kind, averaged).collect::<Vec<_>>();
163+
.map(|((c, d), i)| ((c, Some(d.expect("interpolated") / baseline)), i));
164+
165+
let graph_data = to_graph_points(body.kind, avg_vs_baseline).collect::<Vec<_>>();
166+
180167
series.push(SeriesResponse {
181168
path: Path::new()
182169
.set(PathComponent::Benchmark("Summary".into()))
183170
.set(PathComponent::Profile(profile))
184171
.set(PathComponent::Scenario(scenario))
185-
.set(PathComponent::Metric(
186-
query
187-
.get(Tag::Metric)
188-
.unwrap()
189-
.raw
190-
.assert_one()
191-
.parse()
192-
.unwrap(),
193-
)),
172+
.set(PathComponent::Metric(metric)),
194173
series: graph_data,
195174
})
196175
}

0 commit comments

Comments
 (0)