Skip to content

Commit b44d633

Browse files
Move locating a single benchmark's data at a SHA into load.rs
1 parent b383a18 commit b44d633

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

site/src/load.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ pub struct InputData {
163163
}
164164

165165
impl InputData {
166+
pub fn benchmark_data(
167+
&self,
168+
interpolate: Interpolate,
169+
sha: Sha,
170+
name: BenchmarkName,
171+
) -> Result<&'_ Benchmark, String> {
172+
let data = match interpolate {
173+
Interpolate::Yes => &self.data,
174+
Interpolate::No => &self.data_real,
175+
};
176+
if let Some(e) = data.iter().find(|e| e.commit.sha == sha) {
177+
e.benchmarks
178+
.get(&name)
179+
.ok_or_else(|| format!("benchmark {} does not exist at commit {}", name, sha))?
180+
.as_ref()
181+
.map_err(|_| format!("benchmark {} failed to compile for commit {}", name, sha))
182+
} else {
183+
return Err(format!("could not find commit {}", sha));
184+
}
185+
}
186+
166187
pub fn data(&self, interpolate: Interpolate) -> &[Arc<CommitData>] {
167188
match interpolate {
168189
Interpolate::Yes => &self.data,

site/src/server.rs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ use crate::load::{Config, InputData};
4949
use crate::util::{self, get_repo_path, Interpolate};
5050
use collector::api::collected;
5151
use collector::version_supports_incremental;
52-
use collector::BenchmarkName;
53-
use collector::CommitData;
5452
use collector::Sha;
5553
use collector::StatId;
5654
use parking_lot::RwLock;
@@ -612,23 +610,11 @@ pub async fn handle_collected(
612610
}
613611

614612
fn get_self_profile_data(
615-
commit: &CommitData,
613+
benchmark: &collector::Benchmark,
616614
bench_ty: &str,
617-
bench_name: BenchmarkName,
618615
run_name: &str,
619616
sort_idx: Option<i32>,
620617
) -> ServerResult<self_profile::SelfProfile> {
621-
let benchmark = commit
622-
.benchmarks
623-
.get(&bench_name)
624-
.ok_or(format!("No benchmark with name {}", bench_name))?;
625-
let benchmark = benchmark.as_ref().map_err(|_| {
626-
format!(
627-
"Benchmark {} did not compile successfully at this commit",
628-
bench_name
629-
)
630-
})?;
631-
632618
let run = benchmark
633619
.runs
634620
.iter()
@@ -753,28 +739,15 @@ pub async fn handle_self_profile(
753739
.ok()
754740
.ok_or(format!("sort_idx needs to be i32"))?;
755741

756-
let commit = data
757-
.data(Interpolate::No)
758-
.iter()
759-
.find(|cd| cd.commit.sha == *body.commit)
760-
.ok_or(format!("could not find commit {}", body.commit))?;
761-
let profile = get_self_profile_data(
762-
&commit,
763-
bench_ty,
764-
bench_name,
765-
&body.run_name,
766-
Some(sort_idx),
767-
)?;
742+
let benchmark =
743+
data.benchmark_data(Interpolate::No, body.commit.as_str().into(), bench_name)?;
744+
let profile = get_self_profile_data(&benchmark, bench_ty, &body.run_name, Some(sort_idx))?;
768745
let base_profile = if let Some(bc) = body.base_commit {
769-
let base_commit = data
770-
.data(Interpolate::No)
771-
.iter()
772-
.find(|cd| cd.commit.sha == *bc)
773-
.ok_or(format!("could not find commit {}", bc))?;
746+
let base_benchmark =
747+
data.benchmark_data(Interpolate::No, bc.as_str().into(), bench_name)?;
774748
Some(get_self_profile_data(
775-
&base_commit,
749+
&base_benchmark,
776750
bench_ty,
777-
bench_name,
778751
&body.run_name,
779752
None,
780753
)?)

0 commit comments

Comments
 (0)