Skip to content

Commit cf2b596

Browse files
Merge pull request #1019 from Mark-Simulacrum/codegen-schedule-direct
Support directly rendering codegen scheduling
2 parents 2aab119 + a456465 commit cf2b596

File tree

8 files changed

+482
-61
lines changed

8 files changed

+482
-61
lines changed

database/schema.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ series aid cid value
128128

129129
**TODO**
130130

131-
### pull_request_builds
131+
### pull_request_build
132132

133133
**TODO**
134134

@@ -164,4 +164,4 @@ aid step start end
164164

165165
### error
166166

167-
**TODO**
167+
**TODO**

database/src/pool/sqlite.rs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ static MIGRATIONS: &[&str] = &[
162162
PRIMARY KEY(aid, cid, crate)
163163
);
164164
"#,
165+
r#"alter table pull_request_builds rename to pull_request_build"#,
166+
r#"
167+
create table raw_self_profile(
168+
aid integer references artifact(id) on delete cascade on update cascade,
169+
cid integer references collection(id) on delete cascade on update cascade,
170+
crate text not null references benchmark(name) on delete cascade on update cascade,
171+
profile text not null,
172+
cache text not null,
173+
PRIMARY KEY(aid, cid, crate, profile, cache)
174+
);
175+
"#,
165176
];
166177

167178
#[async_trait::async_trait]
@@ -470,7 +481,7 @@ impl Connection for SqliteConnection {
470481
) {
471482
self.raw_ref()
472483
.prepare_cached(
473-
"insert into pull_request_builds (pr, complete, requested, include, exclude, runs) VALUES (?, 0, strftime('%s','now'), ?, ?, ?)",
484+
"insert into pull_request_build (pr, complete, requested, include, exclude, runs) VALUES (?, 0, strftime('%s','now'), ?, ?, ?)",
474485
)
475486
.unwrap()
476487
.execute(params![pr, include, exclude, &runs])
@@ -479,7 +490,7 @@ impl Connection for SqliteConnection {
479490
async fn pr_attach_commit(&self, pr: u32, sha: &str, parent_sha: &str) -> bool {
480491
self.raw_ref()
481492
.prepare_cached(
482-
"update pull_request_builds SET bors_sha = ?, parent_sha = ?
493+
"update pull_request_build SET bors_sha = ?, parent_sha = ?
483494
where pr = ? and bors_sha is null",
484495
)
485496
.unwrap()
@@ -490,7 +501,7 @@ impl Connection for SqliteConnection {
490501
async fn queued_commits(&self) -> Vec<QueuedCommit> {
491502
self.raw_ref()
492503
.prepare_cached(
493-
"select pr, bors_sha, parent_sha, include, exclude, runs from pull_request_builds
504+
"select pr, bors_sha, parent_sha, include, exclude, runs from pull_request_build
494505
where complete is false and bors_sha is not null
495506
order by requested asc",
496507
)
@@ -514,7 +525,7 @@ impl Connection for SqliteConnection {
514525
let count = self
515526
.raw_ref()
516527
.execute(
517-
"update pull_request_builds SET complete = 1 where sha = ? and complete = 0",
528+
"update pull_request_build SET complete = 1 where sha = ? and complete = 0",
518529
params![sha],
519530
)
520531
.unwrap();
@@ -524,7 +535,7 @@ impl Connection for SqliteConnection {
524535
assert_eq!(count, 1, "sha is unique column");
525536
self.raw_ref()
526537
.query_row(
527-
"select pr, sha, parent_sha, include, exclude, runs from pull_request_builds
538+
"select pr, sha, parent_sha, include, exclude, runs from pull_request_build
528539
where sha = ?",
529540
params![sha],
530541
|row| {
@@ -867,7 +878,7 @@ impl Connection for SqliteConnection {
867878
async fn parent_of(&self, sha: &str) -> Option<String> {
868879
let mut shas = self
869880
.raw_ref()
870-
.prepare_cached("select parent_sha from pull_request_builds where bors_sha = ?")
881+
.prepare_cached("select parent_sha from pull_request_build where bors_sha = ?")
871882
.unwrap()
872883
.query(params![sha])
873884
.unwrap()
@@ -880,7 +891,7 @@ impl Connection for SqliteConnection {
880891
async fn pr_of(&self, sha: &str) -> Option<u32> {
881892
self.raw_ref()
882893
.query_row(
883-
"select pr from pull_request_builds where bors_sha = ?",
894+
"select pr from pull_request_build where bors_sha = ?",
884895
params![sha],
885896
|row| Ok(row.get(0).unwrap()),
886897
)
@@ -903,12 +914,35 @@ impl Connection for SqliteConnection {
903914
}
904915
async fn list_self_profile(
905916
&self,
906-
_aid: ArtifactId,
907-
_crate_: &str,
908-
_profile: &str,
909-
_scenario: &str,
917+
aid: ArtifactId,
918+
crate_: &str,
919+
profile: &str,
920+
scenario: &str,
910921
) -> Vec<(ArtifactIdNumber, i32)> {
911-
Vec::new()
922+
self.raw_ref()
923+
.prepare(
924+
"select aid, cid from raw_self_profile where
925+
crate = ?1 and
926+
profile = ?2 and
927+
cache = ?3 and
928+
aid = (select id from artifact where name = ?4);",
929+
)
930+
.unwrap()
931+
.query_map(
932+
params![
933+
&crate_,
934+
profile,
935+
scenario,
936+
&match aid {
937+
ArtifactId::Commit(c) => c.sha,
938+
ArtifactId::Tag(a) => a,
939+
}
940+
],
941+
|r| Ok((ArtifactIdNumber(r.get::<_, i32>(0)? as u32), r.get(1)?)),
942+
)
943+
.unwrap()
944+
.collect::<Result<_, _>>()
945+
.unwrap()
912946
}
913947

914948
async fn get_bootstrap(&self, aids: &[ArtifactIdNumber]) -> Vec<Option<Duration>> {

site/src/request_handlers/self_profile.rs

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,80 @@ use crate::server::{Request, Response, ResponseHeaders};
1616

1717
pub async fn handle_self_profile_processed_download(
1818
body: self_profile_raw::Request,
19-
params: HashMap<String, String>,
19+
mut params: HashMap<String, String>,
2020
ctxt: &SiteCtxt,
2121
) -> http::Response<hyper::Body> {
22-
let title = format!(
23-
"{}: {} {}",
24-
&body.commit[..std::cmp::min(7, body.commit.len())],
25-
body.benchmark,
26-
body.run_name
27-
);
22+
let diff_against = params.remove("base_commit");
23+
if params
24+
.get("type")
25+
.map_or(false, |t| t != "codegen-schedule")
26+
&& diff_against.is_some()
27+
{
28+
let mut resp = Response::new("Only codegen_schedule supports diffing right now.".into());
29+
*resp.status_mut() = StatusCode::BAD_REQUEST;
30+
return resp;
31+
}
32+
33+
let title = if let Some(diff_against) = diff_against.as_ref() {
34+
format!(
35+
"{} vs {}: {} {}",
36+
&diff_against[..std::cmp::min(7, diff_against.len())],
37+
&body.commit[..std::cmp::min(7, body.commit.len())],
38+
body.benchmark,
39+
body.run_name
40+
)
41+
} else {
42+
format!(
43+
"{}: {} {}",
44+
&body.commit[..std::cmp::min(7, body.commit.len())],
45+
body.benchmark,
46+
body.run_name
47+
)
48+
};
2849

2950
let start = Instant::now();
3051

31-
let (url, is_tarball) = match handle_self_profile_raw(body, ctxt).await {
32-
Ok(v) => (v.url, v.is_tarball),
52+
let base_data = if let Some(diff_against) = diff_against {
53+
match handle_self_profile_raw(
54+
self_profile_raw::Request {
55+
commit: diff_against,
56+
benchmark: body.benchmark.clone(),
57+
run_name: body.run_name.clone(),
58+
cid: None,
59+
},
60+
ctxt,
61+
)
62+
.await
63+
{
64+
Ok(v) => match get_self_profile_raw_data(&v.url).await {
65+
Ok(v) => Some(v),
66+
Err(e) => return e,
67+
},
68+
Err(e) => {
69+
let mut resp = Response::new(e.into());
70+
*resp.status_mut() = StatusCode::BAD_REQUEST;
71+
return resp;
72+
}
73+
}
74+
} else {
75+
None
76+
};
77+
78+
let data = match handle_self_profile_raw(body, ctxt).await {
79+
Ok(v) => match get_self_profile_raw_data(&v.url).await {
80+
Ok(v) => v,
81+
Err(e) => return e,
82+
},
3383
Err(e) => {
3484
let mut resp = Response::new(e.into());
3585
*resp.status_mut() = StatusCode::BAD_REQUEST;
3686
return resp;
3787
}
3888
};
3989

40-
if is_tarball {
41-
let mut resp =
42-
Response::new("Processing legacy format self-profile data is not supported".into());
43-
*resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
44-
return resp;
45-
}
46-
47-
let data = match get_self_profile_raw_data(&url).await {
48-
Ok(v) => v,
49-
Err(e) => return e,
50-
};
51-
5290
log::trace!("got data in {:?}", start.elapsed());
5391

54-
let output = match crate::self_profile::generate(&title, data, params) {
92+
let output = match crate::self_profile::generate(&title, base_data, data, params) {
5593
Ok(c) => c,
5694
Err(e) => {
5795
log::error!("Failed to generate json {:?}", e);
@@ -63,8 +101,12 @@ pub async fn handle_self_profile_processed_download(
63101
let mut builder = http::Response::builder()
64102
.header_typed(if output.filename.ends_with("json") {
65103
ContentType::json()
66-
} else {
104+
} else if output.filename.ends_with("svg") {
67105
ContentType::from("image/svg+xml".parse::<mime::Mime>().unwrap())
106+
} else if output.filename.ends_with("html") {
107+
ContentType::html()
108+
} else {
109+
unreachable!()
68110
})
69111
.status(StatusCode::OK);
70112

@@ -257,6 +299,7 @@ fn sort_self_profile(
257299
async fn get_self_profile_raw_data(url: &str) -> Result<Vec<u8>, Response> {
258300
log::trace!("downloading {}", url);
259301

302+
let start = Instant::now();
260303
let resp = match reqwest::get(url).await {
261304
Ok(r) => r,
262305
Err(e) => {
@@ -283,6 +326,12 @@ async fn get_self_profile_raw_data(url: &str) -> Result<Vec<u8>, Response> {
283326
}
284327
};
285328

329+
log::trace!(
330+
"downloaded {} bytes in {:?}",
331+
compressed.len(),
332+
start.elapsed()
333+
);
334+
286335
let mut data = Vec::new();
287336

288337
match snap::read::FrameDecoder::new(compressed.reader()).read_to_end(&mut data) {
@@ -462,7 +511,7 @@ pub async fn handle_self_profile_raw(
462511
let aids_and_cids = conn
463512
.list_self_profile(
464513
ArtifactId::Commit(database::Commit {
465-
sha: body.commit,
514+
sha: body.commit.clone(),
466515
date: database::Date::empty(),
467516
}),
468517
bench_name,
@@ -473,7 +522,7 @@ pub async fn handle_self_profile_raw(
473522
let (aid, first_cid) = aids_and_cids
474523
.first()
475524
.copied()
476-
.ok_or_else(|| format!("No results for this commit"))?;
525+
.ok_or_else(|| format!("No results for {}", body.commit))?;
477526

478527
let cid = match body.cid {
479528
Some(cid) => {
@@ -500,27 +549,15 @@ pub async fn handle_self_profile_raw(
500549
.map(|(_, cid)| cid)
501550
.collect::<Vec<_>>();
502551

503-
return match fetch(&cids, cid, format!("{}.mm_profdata.sz", url_prefix), false).await {
552+
return match fetch(&cids, cid, format!("{}.mm_profdata.sz", url_prefix)).await {
504553
Ok(fetched) => Ok(fetched),
505-
Err(new_error) => {
506-
match fetch(&cids, cid, format!("{}.tar.sz", url_prefix), true).await {
507-
Ok(fetched) => Ok(fetched),
508-
Err(old_error) => {
509-
// Both files failed to fetch; return the errors for both:
510-
Err(format!(
511-
"mm_profdata download failed: {:?}, tarball download failed: {:?}",
512-
new_error, old_error
513-
))
514-
}
515-
}
516-
}
554+
Err(new_error) => Err(format!("mm_profdata download failed: {:?}", new_error,)),
517555
};
518556

519557
async fn fetch(
520558
cids: &[i32],
521559
cid: i32,
522560
url: String,
523-
is_tarball: bool,
524561
) -> ServerResult<self_profile_raw::Response> {
525562
let resp = reqwest::Client::new()
526563
.head(&url)
@@ -538,7 +575,7 @@ pub async fn handle_self_profile_raw(
538575
cids: cids.to_vec(),
539576
cid,
540577
url,
541-
is_tarball,
578+
is_tarball: false,
542579
})
543580
}
544581
}

site/src/self_profile.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use anyhow::Context;
55
use std::collections::HashMap;
66

7+
mod codegen_schedule;
78
pub mod crox;
89
pub mod flamegraph;
910

@@ -15,6 +16,7 @@ pub struct Output {
1516

1617
pub fn generate(
1718
title: &str,
19+
self_profile_base_data: Option<Vec<u8>>,
1820
self_profile_data: Vec<u8>,
1921
mut params: HashMap<String, String>,
2022
) -> anyhow::Result<Output> {
@@ -38,6 +40,21 @@ pub fn generate(
3840
is_download: false,
3941
})
4042
}
41-
_ => anyhow::bail!("Unknown type, specify type={crox,flamegraph}"),
43+
Some("codegen-schedule") => {
44+
let opt =
45+
serde_json::from_str(&serde_json::to_string(&params).unwrap()).context("params")?;
46+
Ok(Output {
47+
filename: "schedule.html",
48+
data: codegen_schedule::generate(
49+
title,
50+
self_profile_base_data,
51+
self_profile_data,
52+
opt,
53+
)
54+
.context("codegen_schedule")?,
55+
is_download: false,
56+
})
57+
}
58+
_ => anyhow::bail!("Unknown type, specify type={crox,flamegraph,codegen-schedule}"),
4259
}
4360
}

0 commit comments

Comments
 (0)