Skip to content

Commit d05d0a7

Browse files
committed
Rename DateDate to ArtifactData
1 parent 2132441 commit d05d0a7

File tree

3 files changed

+93
-59
lines changed

3 files changed

+93
-59
lines changed

site/src/api.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub struct CommitResponse {
8080
}
8181

8282
pub mod data {
83-
use crate::comparison::DateData;
83+
use crate::comparison::ArtifactData;
8484
use collector::Bound;
8585
use serde::{Deserialize, Serialize};
8686

@@ -95,7 +95,7 @@ pub mod data {
9595

9696
/// List of DateData's from oldest to newest
9797
#[derive(Debug, Clone, Serialize)]
98-
pub struct Response(pub Vec<DateData>);
98+
pub struct Response(pub Vec<ArtifactData>);
9999
}
100100

101101
pub mod graph {
@@ -165,10 +165,11 @@ pub mod bootstrap {
165165
}
166166
}
167167

168-
pub mod days {
169-
use crate::comparison::DateData;
168+
pub mod comparison {
170169
use collector::Bound;
170+
use database::Date;
171171
use serde::{Deserialize, Serialize};
172+
use std::collections::HashMap;
172173

173174
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
174175
pub struct Request {
@@ -183,8 +184,8 @@ pub mod days {
183184
/// The names for the previous artifact before `a`, if any.
184185
pub prev: Option<String>,
185186

186-
pub a: DateData,
187-
pub b: DateData,
187+
pub a: ArtifactData,
188+
pub b: ArtifactData,
188189

189190
/// The names for the next artifact after `b`, if any.
190191
pub next: Option<String>,
@@ -193,6 +194,16 @@ pub mod days {
193194
/// `b`).
194195
pub is_contiguous: bool,
195196
}
197+
198+
/// A serializable wrapper for `comparison::ArtifactData`
199+
#[derive(Debug, Clone, Serialize)]
200+
pub struct ArtifactData {
201+
pub commit: String,
202+
pub date: Option<Date>,
203+
pub pr: Option<u32>,
204+
pub data: HashMap<String, Vec<(String, f64)>>,
205+
pub bootstrap: HashMap<String, u64>,
206+
}
196207
}
197208

198209
pub mod status {

site/src/comparison.rs

Lines changed: 74 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::load::InputData;
88
use crate::selector::{self, Tag};
99

1010
use collector::Bound;
11-
use database::Date;
1211
use serde::Serialize;
1312

1413
use std::collections::HashMap;
@@ -60,8 +59,8 @@ pub async fn handle_triage(
6059
};
6160
log::info!(
6261
"Comparing {} to {}",
63-
comparison.b.commit,
64-
comparison.a.commit
62+
comparison.b.artifact,
63+
comparison.a.artifact
6564
);
6665

6766
// handle results of comparison
@@ -84,9 +83,9 @@ pub async fn handle_triage(
8483
}
8584

8685
pub async fn handle_compare(
87-
body: api::days::Request,
86+
body: api::comparison::Request,
8887
data: &InputData,
89-
) -> Result<api::days::Response, BoxedError> {
88+
) -> Result<api::comparison::Response, BoxedError> {
9089
let master_commits = collector::master_commits().await?;
9190
let end = body.end;
9291
let comparison =
@@ -99,10 +98,36 @@ pub async fn handle_compare(
9998
let next = comparison.next(&master_commits);
10099
let is_contiguous = comparison.is_contiguous(&*conn, &master_commits).await;
101100

102-
Ok(api::days::Response {
101+
Ok(api::comparison::Response {
103102
prev,
104-
a: comparison.a,
105-
b: comparison.b,
103+
a: api::comparison::ArtifactData {
104+
commit: match comparison.a.artifact.clone() {
105+
ArtifactId::Commit(c) => c.sha,
106+
ArtifactId::Artifact(t) => t,
107+
},
108+
date: if let ArtifactId::Commit(c) = &comparison.a.artifact {
109+
Some(c.date)
110+
} else {
111+
None
112+
},
113+
pr: comparison.a.pr,
114+
data: comparison.a.data,
115+
bootstrap: comparison.a.bootstrap,
116+
},
117+
b: api::comparison::ArtifactData {
118+
commit: match comparison.b.artifact.clone() {
119+
ArtifactId::Commit(c) => c.sha,
120+
ArtifactId::Artifact(t) => t,
121+
},
122+
date: if let ArtifactId::Commit(c) = &comparison.b.artifact {
123+
Some(c.date)
124+
} else {
125+
None
126+
},
127+
pr: comparison.b.pr,
128+
data: comparison.b.data,
129+
bootstrap: comparison.b.bootstrap,
130+
},
106131
next,
107132
is_contiguous,
108133
})
@@ -197,8 +222,8 @@ impl ComparisonSummary<'_> {
197222
} else {
198223
String::from("<Unknown Change>\n")
199224
};
200-
let start = &comparison.a.commit;
201-
let end = &comparison.b.commit;
225+
let start = &comparison.a.artifact;
226+
let end = &comparison.b.artifact;
202227
let link = &compare_link(start, end);
203228

204229
for change in self.ordered_changes() {
@@ -246,27 +271,23 @@ pub async fn compare_given_commits(
246271
.set::<String>(Tag::Profile, selector::Selector::All)
247272
.set(Tag::ProcessStatistic, selector::Selector::One(stat.clone()));
248273

249-
// `responses` contains a series iterators. The first element in the iterator is the data
274+
// `responses` contains series iterators. The first element in the iterator is the data
250275
// for `a` and the second is the data for `b`
251276
let mut responses = data.query::<Option<f64>>(query, cids).await?;
252277

253278
let conn = data.conn().await;
254279

255280
Ok(Some(Comparison {
256-
a: DateData::consume_one(&*conn, a.clone(), &mut responses, master_commits).await,
257-
a_id: a,
258-
b: DateData::consume_one(&*conn, b.clone(), &mut responses, master_commits).await,
259-
b_id: b,
281+
a: ArtifactData::consume_one(&*conn, a.clone(), &mut responses, master_commits).await,
282+
b: ArtifactData::consume_one(&*conn, b.clone(), &mut responses, master_commits).await,
260283
}))
261284
}
262285

263286
/// Data associated with a specific artifact
264287
#[derive(Debug, Clone, Serialize)]
265-
pub struct DateData {
288+
pub struct ArtifactData {
266289
/// The artifact in question
267-
pub commit: String,
268-
/// The date of the artifact if known
269-
pub date: Option<Date>,
290+
pub artifact: ArtifactId,
270291
/// The pr of the artifact if known
271292
pub pr: Option<u32>,
272293
/// Benchmark data in the form "$crate-$profile" -> Vec<("$cache", nanoseconds)>
@@ -279,14 +300,14 @@ pub struct DateData {
279300
pub bootstrap: HashMap<String, u64>,
280301
}
281302

282-
impl DateData {
303+
impl ArtifactData {
283304
/// For the given `ArtifactId`, consume the first datapoint in each of the given `SeriesResponse`
284305
///
285-
/// It is assumed that the provided ArtifactId is the same as artifact id returned as the next data
286-
/// point from all of the series `SeriesResponse`s. If this is not true, this function will panic.
306+
/// It is assumed that the provided `ArtifactId` matches the artifact id of the next data
307+
/// point for all of `SeriesResponse<T>`. If this is not true, this function will panic.
287308
async fn consume_one<'a, T>(
288309
conn: &dyn database::Connection,
289-
commit: ArtifactId,
310+
artifact: ArtifactId,
290311
series: &mut [selector::SeriesResponse<T>],
291312
master_commits: &[collector::MasterCommit],
292313
) -> Self
@@ -297,7 +318,7 @@ impl DateData {
297318

298319
for response in series {
299320
let (id, point) = response.series.next().expect("must have element");
300-
assert_eq!(commit, id);
321+
assert_eq!(artifact, id);
301322

302323
let point = if let Some(pt) = point {
303324
pt
@@ -313,7 +334,9 @@ impl DateData {
313334
.push((response.path.get::<Cache>().unwrap().to_string(), point));
314335
}
315336

316-
let bootstrap = conn.get_bootstrap(&[conn.artifact_id(&commit).await]).await;
337+
let bootstrap = conn
338+
.get_bootstrap(&[conn.artifact_id(&artifact).await])
339+
.await;
317340
let bootstrap = bootstrap
318341
.into_iter()
319342
.filter_map(|(k, mut v)| {
@@ -332,25 +355,19 @@ impl DateData {
332355
})
333356
.collect::<HashMap<_, _>>();
334357

335-
Self {
336-
date: if let ArtifactId::Commit(c) = &commit {
337-
Some(c.date)
338-
} else {
339-
None
340-
},
341-
pr: if let ArtifactId::Commit(c) = &commit {
342-
if let Some(m) = master_commits.iter().find(|m| m.sha == c.sha) {
343-
m.pr
344-
} else {
345-
conn.pr_of(&c.sha).await
346-
}
358+
let pr = if let ArtifactId::Commit(c) = &artifact {
359+
if let Some(m) = master_commits.iter().find(|m| m.sha == c.sha) {
360+
m.pr
347361
} else {
348-
None
349-
},
350-
commit: match commit {
351-
ArtifactId::Commit(c) => c.sha,
352-
ArtifactId::Artifact(i) => i,
353-
},
362+
conn.pr_of(&c.sha).await
363+
}
364+
} else {
365+
None
366+
};
367+
368+
Self {
369+
pr,
370+
artifact,
354371
data,
355372
bootstrap,
356373
}
@@ -359,16 +376,14 @@ impl DateData {
359376

360377
// A comparison of two artifacts
361378
pub struct Comparison {
362-
pub a_id: ArtifactId,
363-
pub a: DateData,
364-
pub b_id: ArtifactId,
365-
pub b: DateData,
379+
pub a: ArtifactData,
380+
pub b: ArtifactData,
366381
}
367382

368383
impl Comparison {
369384
/// Gets the previous commit before `a`
370385
pub fn prev(&self, master_commits: &[collector::MasterCommit]) -> Option<String> {
371-
match &self.a_id {
386+
match &self.a.artifact {
372387
ArtifactId::Commit(a) => master_commits
373388
.iter()
374389
.find(|c| c.sha == a.sha)
@@ -383,7 +398,7 @@ impl Comparison {
383398
conn: &dyn database::Connection,
384399
master_commits: &[collector::MasterCommit],
385400
) -> bool {
386-
match (&self.a_id, &self.b_id) {
401+
match (&self.a.artifact, &self.b.artifact) {
387402
(ArtifactId::Commit(a), ArtifactId::Commit(b)) => {
388403
if let Some(b) = master_commits.iter().find(|c| c.sha == b.sha) {
389404
b.parent_sha == a.sha
@@ -397,7 +412,7 @@ impl Comparison {
397412

398413
/// Gets the sha of the next commit after `b`
399414
pub fn next(&self, master_commits: &[collector::MasterCommit]) -> Option<String> {
400-
match &self.b_id {
415+
match &self.b.artifact {
401416
ArtifactId::Commit(b) => master_commits
402417
.iter()
403418
.find(|c| c.parent_sha == b.sha)
@@ -585,7 +600,15 @@ TODO: Nags
585600
)
586601
}
587602

588-
fn compare_link(start: &str, end: &str) -> String {
603+
fn compare_link(start: &ArtifactId, end: &ArtifactId) -> String {
604+
let start = match &start {
605+
ArtifactId::Artifact(a) => a,
606+
ArtifactId::Commit(c) => &c.sha,
607+
};
608+
let end = match &end {
609+
ArtifactId::Artifact(a) => a,
610+
ArtifactId::Commit(c) => &c.sha,
611+
};
589612
format!(
590613
"https://perf.rust-lang.org/compare.html?start={}&end={}&stat=instructions:u",
591614
start, end

site/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ type Request = http::Request<hyper::Body>;
3939
type Response = http::Response<hyper::Body>;
4040

4141
pub use crate::api::{
42-
self, bootstrap, dashboard, data, days, github, graph, info, self_profile, self_profile_raw,
43-
status, triage, CommitResponse, ServerResult, StyledBenchmarkName,
42+
self, bootstrap, comparison, dashboard, data, github, graph, info, self_profile,
43+
self_profile_raw, status, triage, CommitResponse, ServerResult, StyledBenchmarkName,
4444
};
4545
use crate::db::{self, Cache, Crate, Profile};
4646
use crate::interpolate::Interpolated;

0 commit comments

Comments
 (0)