Skip to content

Commit 85de333

Browse files
Fix raw downloads of self profile data
Upstream has migrated to single-file profile format which has been accounted for in the collector (moving us over to uploading just the single compressed file instead of a compressed tarball), but not yet in the server. This fixes the raw download URLs; the rendered (crox + flamegraph) views will be fixed in a separate commit.
1 parent 623acd9 commit 85de333

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

site/src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ pub mod self_profile_raw {
263263
pub cids: Vec<i32>,
264264
pub cid: i32,
265265
pub url: String,
266+
pub is_tarball: bool,
266267
}
267268
}
268269

site/src/self_profile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub async fn get_pieces(
6969
body: crate::api::self_profile_raw::Request,
7070
data: &InputData,
7171
) -> Result<Pieces, Response> {
72-
let res = crate::server::handle_self_profile_raw(body, data, false).await;
72+
let res = crate::server::handle_self_profile_raw(body, data).await;
7373
let url = match res {
7474
Ok(v) => v.url,
7575
Err(e) => {

site/src/server.rs

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,9 @@ pub async fn handle_self_profile_raw_download(
932932
body: self_profile_raw::Request,
933933
data: &InputData,
934934
) -> Response {
935-
let res = handle_self_profile_raw(body, data, false).await;
936-
let url = match res {
937-
Ok(v) => v.url,
935+
let res = handle_self_profile_raw(body, data).await;
936+
let (url, is_tarball) = match res {
937+
Ok(v) => (v.url, v.is_tarball),
938938
Err(e) => {
939939
let mut resp = Response::new(e.into());
940940
*resp.status_mut() = StatusCode::BAD_REQUEST;
@@ -969,7 +969,12 @@ pub async fn handle_self_profile_raw_download(
969969
server_resp.headers_mut().insert(
970970
hyper::header::CONTENT_DISPOSITION,
971971
hyper::header::HeaderValue::from_maybe_shared(format!(
972-
"attachment; filename=\"self-profile.tar\""
972+
"attachment; filename=\"{}\"",
973+
if is_tarball {
974+
"self-profile.tar"
975+
} else {
976+
"self-profile.mm_profdata"
977+
}
973978
))
974979
.expect("valid header"),
975980
);
@@ -1071,7 +1076,6 @@ async fn tarball(resp: reqwest::Response, mut sender: hyper::body::Sender) {
10711076
pub async fn handle_self_profile_raw(
10721077
body: self_profile_raw::Request,
10731078
data: &InputData,
1074-
validate: bool,
10751079
) -> ServerResult<self_profile_raw::Response> {
10761080
log::info!("handle_self_profile_raw({:?})", body);
10771081
let mut it = body.benchmark.rsplitn(2, '-');
@@ -1112,16 +1116,42 @@ pub async fn handle_self_profile_raw(
11121116
_ => first_cid,
11131117
};
11141118

1115-
let url = format!(
1116-
"https://perf-data.rust-lang.org/self-profile/{}/{}/{}/{}/self-profile-{}.tar.sz",
1119+
let url_prefix = format!(
1120+
"https://perf-data.rust-lang.org/self-profile/{}/{}/{}/{}/self-profile-{}",
11171121
aid.0,
11181122
bench_name,
11191123
bench_ty,
11201124
cache.to_id(),
1121-
cid
1125+
cid,
11221126
);
11231127

1124-
if validate {
1128+
let cids = aids_and_cids
1129+
.into_iter()
1130+
.map(|(_, cid)| cid)
1131+
.collect::<Vec<_>>();
1132+
1133+
return match fetch(&cids, cid, format!("{}.mm_profdata.sz", url_prefix), false).await {
1134+
Ok(fetched) => Ok(fetched),
1135+
Err(new_error) => {
1136+
match fetch(&cids, cid, format!("{}.tar.sz", url_prefix), true).await {
1137+
Ok(fetched) => Ok(fetched),
1138+
Err(old_error) => {
1139+
// Both files failed to fetch; return the errors for both:
1140+
Err(format!(
1141+
"mm_profdata download failed: {:?}, tarball download failed: {:?}",
1142+
new_error, old_error
1143+
))
1144+
}
1145+
}
1146+
}
1147+
};
1148+
1149+
async fn fetch(
1150+
cids: &[i32],
1151+
cid: i32,
1152+
url: String,
1153+
is_tarball: bool,
1154+
) -> ServerResult<self_profile_raw::Response> {
11251155
let resp = reqwest::Client::new()
11261156
.head(&url)
11271157
.send()
@@ -1133,13 +1163,14 @@ pub async fn handle_self_profile_raw(
11331163
resp.status()
11341164
));
11351165
}
1136-
}
11371166

1138-
Ok(self_profile_raw::Response {
1139-
cids: aids_and_cids.into_iter().map(|(_, cid)| cid).collect(),
1140-
cid,
1141-
url,
1142-
})
1167+
Ok(self_profile_raw::Response {
1168+
cids: cids.to_vec(),
1169+
cid,
1170+
url,
1171+
is_tarball,
1172+
})
1173+
}
11431174
}
11441175

11451176
pub async fn handle_self_profile(
@@ -1656,7 +1687,7 @@ async fn serve_req(ctx: Arc<Server>, req: Request) -> Result<Response, ServerErr
16561687
))
16571688
} else if p == "/perf/self-profile-raw" {
16581689
Ok(to_response(
1659-
handle_self_profile_raw(body!(parse_body(&body)), &data, true).await,
1690+
handle_self_profile_raw(body!(parse_body(&body)), &data).await,
16601691
))
16611692
} else if p == "/perf/graph-new" {
16621693
Ok(

0 commit comments

Comments
 (0)