Skip to content

Commit 0eb46c3

Browse files
authored
Merge pull request #1096 from rylev/fix-on-demand
Fix issues with on-demand self profile fetching
2 parents 10c1cf8 + 656f9f1 commit 0eb46c3

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

site/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub mod self_profile {
338338

339339
#[derive(Serialize, Clone, Debug)]
340340
pub struct ArtifactSizeDelta {
341-
pub bytes: u64,
341+
pub bytes: i64,
342342
}
343343
}
344344

site/src/request_handlers/self_profile.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::io::Read;
33
use std::sync::Arc;
44
use std::time::{Duration, Instant};
55

6+
use analyzeme::ProfilingData;
67
use bytes::Buf;
78
use database::ArtifactIdNumber;
89
use headers::{ContentType, Header};
@@ -144,7 +145,7 @@ pub async fn handle_self_profile_processed_download(
144145
fn get_self_profile_data(
145146
cpu_clock: Option<f64>,
146147
self_profile: Option<crate::selector::SelfProfileData>,
147-
raw_data: Vec<u8>,
148+
profiling_data: &ProfilingData,
148149
) -> ServerResult<self_profile::SelfProfile> {
149150
let profile = self_profile
150151
.as_ref()
@@ -181,7 +182,7 @@ fn get_self_profile_data(
181182
.map(|qd| qd.incremental_load_time)
182183
.sum(),
183184
};
184-
let artifact_sizes = raw_mmprof_data_to_artifact_sizes(raw_data).ok();
185+
let artifact_sizes = raw_mmprof_data_to_artifact_sizes(profiling_data).ok();
185186
let profile = self_profile::SelfProfile {
186187
query_data: profile
187188
.query_data
@@ -244,11 +245,11 @@ fn add_uninvoked_base_profile_queries(
244245
fn get_self_profile_delta(
245246
profile: &self_profile::SelfProfile,
246247
base_profile: &Option<self_profile::SelfProfile>,
247-
raw_data: Vec<u8>,
248-
base_raw_data: Option<Vec<u8>>,
248+
profiling_data: &ProfilingData,
249+
base_profiling_data: Option<&ProfilingData>,
249250
) -> Option<self_profile::SelfProfileDelta> {
250251
let base_profile = base_profile.as_ref()?;
251-
let base_raw_data = base_raw_data?;
252+
let base_raw_data = base_profiling_data?;
252253

253254
let totals = self_profile::QueryDataDelta {
254255
self_time: profile.totals.self_time as i64 - base_profile.totals.self_time as i64,
@@ -288,13 +289,13 @@ fn get_self_profile_delta(
288289
}
289290
}
290291

291-
let first = raw_mmprof_data_to_artifact_sizes(raw_data).unwrap_or_else(|_| Vec::new());
292+
let first = raw_mmprof_data_to_artifact_sizes(profiling_data).unwrap_or_else(|_| Vec::new());
292293
let base = raw_mmprof_data_to_artifact_sizes(base_raw_data).unwrap_or_else(|_| Vec::new());
293294
let artifact_sizes = first
294295
.into_iter()
295296
.zip(base.into_iter())
296297
.map(|(a1, a2)| ArtifactSizeDelta {
297-
bytes: a1.bytes - a2.bytes,
298+
bytes: a1.bytes as i64 - a2.bytes as i64,
298299
})
299300
.collect();
300301

@@ -687,7 +688,7 @@ pub async fn handle_self_profile(
687688
.await?;
688689
assert_eq!(cpu_responses.len(), 1, "all selectors are exact");
689690
let mut cpu_response = cpu_responses.remove(0).series;
690-
let mut raw_self_profile_data = Vec::new();
691+
let mut self_profile_data = Vec::new();
691692
let conn = ctxt.conn().await;
692693
for commit in commits.iter() {
693694
let aids_and_cids = conn
@@ -696,34 +697,37 @@ pub async fn handle_self_profile(
696697
if let Some((aid, cid)) = aids_and_cids.first() {
697698
match fetch_raw_self_profile_data(*aid, bench_name, profile, &body.run_name, *cid).await
698699
{
699-
Ok(d) => raw_self_profile_data.push(d),
700+
Ok(d) => self_profile_data.push(
701+
extract_profiling_data(d)
702+
.map_err(|e| format!("error extracting self profiling data: {}", e))?,
703+
),
700704
Err(_) => return Err(format!("could not fetch raw profile data")),
701705
};
702706
}
703707
}
704-
let raw_data = raw_self_profile_data.remove(0);
708+
let profiling_data = self_profile_data.get(0).unwrap();
705709
let mut profile = get_self_profile_data(
706710
cpu_response.next().unwrap().1,
707711
sp_response.next().unwrap().1,
708-
raw_data.clone(),
712+
profiling_data,
709713
)
710714
.map_err(|e| format!("{}: {}", body.commit, e))?;
711715
let (base_profile, base_raw_data) = if body.base_commit.is_some() {
712-
let base_raw_data = raw_self_profile_data.remove(0);
716+
let base_profiling_data = self_profile_data.get(1).unwrap();
713717
let profile = get_self_profile_data(
714718
cpu_response.next().unwrap().1,
715719
sp_response.next().unwrap().1,
716-
base_raw_data.clone(),
720+
base_profiling_data,
717721
)
718722
.map_err(|e| format!("{}: {}", body.base_commit.as_ref().unwrap(), e))?;
719-
(Some(profile), Some(base_raw_data))
723+
(Some(profile), Some(base_profiling_data))
720724
} else {
721725
(None, None)
722726
};
723727

724728
add_uninvoked_base_profile_queries(&mut profile, &base_profile);
725729
let mut base_profile_delta =
726-
get_self_profile_delta(&profile, &base_profile, raw_data, base_raw_data);
730+
get_self_profile_delta(&profile, &base_profile, profiling_data, base_raw_data);
727731
sort_self_profile(&mut profile, &mut base_profile_delta, sort_idx);
728732

729733
Ok(self_profile::Response {
@@ -733,11 +737,8 @@ pub async fn handle_self_profile(
733737
}
734738

735739
fn raw_mmprof_data_to_artifact_sizes(
736-
data: Vec<u8>,
740+
profiling_data: &ProfilingData,
737741
) -> anyhow::Result<Vec<self_profile::ArtifactSize>> {
738-
let profiling_data = analyzeme::ProfilingData::from_paged_buffer(data, None)
739-
.map_err(|_| anyhow::Error::msg("could not parse profiling data"))?;
740-
741742
let mut artifact_sizes: BTreeMap<_, u64> = Default::default();
742743

743744
for event in profiling_data.iter_full() {
@@ -760,3 +761,8 @@ fn raw_mmprof_data_to_artifact_sizes(
760761
})
761762
.collect())
762763
}
764+
765+
fn extract_profiling_data(data: Vec<u8>) -> Result<analyzeme::ProfilingData, anyhow::Error> {
766+
analyzeme::ProfilingData::from_paged_buffer(data, None)
767+
.map_err(|_| anyhow::Error::msg("could not parse profiling data"))
768+
}

0 commit comments

Comments
 (0)