Skip to content

Commit 28aa733

Browse files
committed
Clean up
1 parent 99cf314 commit 28aa733

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

site/src/request_handlers/self_profile.rs

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::collections::HashSet;
1+
use std::collections::{BTreeMap, HashSet};
22
use std::io::Read;
33
use std::sync::Arc;
44
use std::time::{Duration, Instant};
55

66
use bytes::Buf;
7+
use database::ArtifactIdNumber;
78
use headers::{ContentType, Header};
89
use hyper::StatusCode;
910

@@ -14,8 +15,6 @@ use crate::load::SiteCtxt;
1415
use crate::selector::{self, Tag};
1516
use crate::server::{Response, ResponseHeaders};
1617

17-
use std::collections::BTreeMap;
18-
1918
pub async fn handle_self_profile_processed_download(
2019
body: self_profile_processed::Request,
2120
ctxt: &SiteCtxt,
@@ -246,12 +245,10 @@ fn get_self_profile_delta(
246245
profile: &self_profile::SelfProfile,
247246
base_profile: &Option<self_profile::SelfProfile>,
248247
raw_data: Vec<u8>,
249-
base_raw_data: Vec<u8>,
248+
base_raw_data: Option<Vec<u8>>,
250249
) -> Option<self_profile::SelfProfileDelta> {
251-
let base_profile = match base_profile.as_ref() {
252-
Some(bp) => bp,
253-
None => return None,
254-
};
250+
let base_profile = base_profile.as_ref()?;
251+
let base_raw_data = base_raw_data?;
255252

256253
let totals = self_profile::QueryDataDelta {
257254
self_time: profile.totals.self_time as i64 - base_profile.totals.self_time as i64,
@@ -593,15 +590,15 @@ pub async fn handle_self_profile_raw(
593590
}
594591

595592
pub async fn fetch_raw_self_profile_data(
596-
aid: &str,
593+
aid: ArtifactIdNumber,
597594
benchmark: &str,
598595
profile: &str,
599596
scenario: &str,
600597
cid: i32,
601598
) -> Result<Vec<u8>, Response> {
602599
let url = format!(
603-
"https://perf-data.rust-lang.org/self-profile/{}/{}/{}/{}/self-profile-{}",
604-
aid, benchmark, profile, scenario, cid,
600+
"https://perf-data.rust-lang.org/self-profile/{}/{}/{}/{}/self-profile-{}.mm_profdata.sz",
601+
aid.0, benchmark, profile, scenario, cid,
605602
);
606603

607604
get_self_profile_raw_data(&url).await
@@ -690,50 +687,43 @@ pub async fn handle_self_profile(
690687
.await?;
691688
assert_eq!(cpu_responses.len(), 1, "all selectors are exact");
692689
let mut cpu_response = cpu_responses.remove(0).series;
693-
let mut raw_data = Vec::new();
690+
let mut raw_self_profile_data = Vec::new();
694691
let conn = ctxt.conn().await;
695692
for commit in commits.iter() {
696-
let aid = match commit {
697-
ArtifactId::Commit(c) => c.sha.as_str(),
698-
ArtifactId::Tag(t) => t.as_str(),
699-
};
700693
let aids_and_cids = conn
701694
.list_self_profile(commit.clone(), bench_name, profile, &body.run_name)
702695
.await;
703-
if let Some((_, cid)) = aids_and_cids.first() {
704-
match fetch_raw_self_profile_data(aid, bench_name, profile, &body.run_name, *cid).await
696+
if let Some((aid, cid)) = aids_and_cids.first() {
697+
match fetch_raw_self_profile_data(*aid, bench_name, profile, &body.run_name, *cid).await
705698
{
706-
Ok(d) => raw_data.push(d),
707-
Err(_resp) => {
708-
eprintln!("could not fetch raw self_profile data");
709-
}
699+
Ok(d) => raw_self_profile_data.push(d),
700+
Err(_) => return Err(format!("could not fetch raw profile data")),
710701
};
711702
}
712703
}
713-
let raw_datum = raw_data.remove(0);
714-
let base_raw_datum = raw_data.remove(0);
704+
let raw_data = raw_self_profile_data.remove(0);
715705
let mut profile = get_self_profile_data(
716706
cpu_response.next().unwrap().1,
717707
sp_response.next().unwrap().1,
718-
raw_datum.clone(),
708+
raw_data.clone(),
719709
)
720710
.map_err(|e| format!("{}: {}", body.commit, e))?;
721-
let base_profile = if body.base_commit.is_some() {
722-
Some(
723-
get_self_profile_data(
724-
cpu_response.next().unwrap().1,
725-
sp_response.next().unwrap().1,
726-
base_raw_datum.clone(),
727-
)
728-
.map_err(|e| format!("{}: {}", body.base_commit.as_ref().unwrap(), e))?,
711+
let (base_profile, base_raw_data) = if body.base_commit.is_some() {
712+
let base_raw_data = raw_self_profile_data.remove(0);
713+
let profile = get_self_profile_data(
714+
cpu_response.next().unwrap().1,
715+
sp_response.next().unwrap().1,
716+
base_raw_data.clone(),
729717
)
718+
.map_err(|e| format!("{}: {}", body.base_commit.as_ref().unwrap(), e))?;
719+
(Some(profile), Some(base_raw_data))
730720
} else {
731-
None
721+
(None, None)
732722
};
733723

734724
add_uninvoked_base_profile_queries(&mut profile, &base_profile);
735725
let mut base_profile_delta =
736-
get_self_profile_delta(&profile, &base_profile, raw_datum, base_raw_datum);
726+
get_self_profile_delta(&profile, &base_profile, raw_data, base_raw_data);
737727
sort_self_profile(&mut profile, &mut base_profile_delta, sort_idx);
738728

739729
Ok(self_profile::Response {

0 commit comments

Comments
 (0)