Skip to content

Commit a48ddba

Browse files
committed
Load self profile data from cache if possible
1 parent 11431f8 commit a48ddba

File tree

3 files changed

+40
-49
lines changed

3 files changed

+40
-49
lines changed

site/src/request_handlers/graph.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::db::{self, ArtifactId, Profile, Scenario};
1010
use crate::interpolate::IsInterpolated;
1111
use crate::load::SiteCtxt;
1212
use crate::selector::{CompileBenchmarkQuery, CompileTestCase, Selector, SeriesResponse};
13-
use crate::self_profile::download_and_analyze_self_profile;
13+
use crate::self_profile::get_or_download_self_profile;
1414

1515
/// Returns data for a detailed information when comparing a single test result comparison
1616
/// for a compile-time benchmark.
@@ -49,19 +49,14 @@ pub async fn handle_compile_detail(
4949
scenario: Scenario,
5050
) -> Option<CompilationSections> {
5151
match aid {
52-
Some(aid) => download_and_analyze_self_profile(
53-
ctxt,
54-
aid.clone(),
55-
benchmark,
56-
profile,
57-
scenario,
58-
None,
59-
)
60-
.await
61-
.ok()
62-
.map(|profile| CompilationSections {
63-
sections: profile.compilation_sections,
64-
}),
52+
Some(aid) => {
53+
get_or_download_self_profile(ctxt, aid.clone(), benchmark, profile, scenario, None)
54+
.await
55+
.ok()
56+
.map(|profile| CompilationSections {
57+
sections: profile.compilation_sections,
58+
})
59+
}
6560
None => None,
6661
}
6762
}

site/src/request_handlers/self_profile.rs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use crate::comparison::Metric;
1414
use crate::db::ArtifactId;
1515
use crate::load::SiteCtxt;
1616
use crate::selector::{self};
17-
use crate::self_profile::{
18-
download_and_analyze_self_profile, get_self_profile_raw_data, SelfProfileKey,
19-
SelfProfileWithAnalysis,
20-
};
17+
use crate::self_profile::{get_or_download_self_profile, get_self_profile_raw_data};
2118
use crate::server::{Response, ResponseHeaders};
2219

2320
pub async fn handle_self_profile_processed_download(
@@ -535,35 +532,7 @@ pub async fn handle_self_profile(
535532
assert_eq!(cpu_responses.len(), 1, "all selectors are exact");
536533
let mut cpu_response = cpu_responses.remove(0).series;
537534

538-
async fn get_from_cache(
539-
ctxt: &SiteCtxt,
540-
aid: ArtifactId,
541-
benchmark: &str,
542-
profile: &str,
543-
scenario: database::Scenario,
544-
metric: Option<f64>,
545-
) -> ServerResult<SelfProfileWithAnalysis> {
546-
let key = SelfProfileKey {
547-
aid: aid.clone(),
548-
benchmark: benchmark.to_string(),
549-
profile: profile.to_string(),
550-
scenario,
551-
};
552-
let cache_result = ctxt.self_profile_cache.lock().get(&key);
553-
match cache_result {
554-
Some(res) => Ok(res),
555-
None => {
556-
let profile = download_and_analyze_self_profile(
557-
ctxt, aid, benchmark, profile, scenario, metric,
558-
)
559-
.await?;
560-
ctxt.self_profile_cache.lock().insert(key, profile.clone());
561-
Ok(profile)
562-
}
563-
}
564-
}
565-
566-
let mut self_profile = get_from_cache(
535+
let mut self_profile = get_or_download_self_profile(
567536
ctxt,
568537
commits.get(0).unwrap().clone(),
569538
bench_name,
@@ -574,7 +543,7 @@ pub async fn handle_self_profile(
574543
.await?;
575544
let base_self_profile = match commits.get(1) {
576545
Some(aid) => Some(
577-
get_from_cache(
546+
get_or_download_self_profile(
578547
ctxt,
579548
aid.clone(),
580549
bench_name,

site/src/self_profile.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub struct SelfProfileWithAnalysis {
202202
pub compilation_sections: Vec<CompilationSection>,
203203
}
204204

205-
pub(crate) async fn download_and_analyze_self_profile(
205+
async fn download_and_analyze_self_profile(
206206
ctxt: &SiteCtxt,
207207
aid: ArtifactId,
208208
benchmark: &str,
@@ -292,6 +292,33 @@ fn compute_compilation_sections(profile: &ProfilingData) -> Vec<CompilationSecti
292292
sections
293293
}
294294

295+
pub(crate) async fn get_or_download_self_profile(
296+
ctxt: &SiteCtxt,
297+
aid: ArtifactId,
298+
benchmark: &str,
299+
profile: &str,
300+
scenario: database::Scenario,
301+
metric: Option<f64>,
302+
) -> ServerResult<SelfProfileWithAnalysis> {
303+
let key = SelfProfileKey {
304+
aid: aid.clone(),
305+
benchmark: benchmark.to_string(),
306+
profile: profile.to_string(),
307+
scenario,
308+
};
309+
let cache_result = ctxt.self_profile_cache.lock().get(&key);
310+
match cache_result {
311+
Some(res) => Ok(res),
312+
None => {
313+
let profile =
314+
download_and_analyze_self_profile(ctxt, aid, benchmark, profile, scenario, metric)
315+
.await?;
316+
ctxt.self_profile_cache.lock().insert(key, profile.clone());
317+
Ok(profile)
318+
}
319+
}
320+
}
321+
295322
fn get_self_profile_data(
296323
cpu_clock: Option<f64>,
297324
profile: &analyzeme::AnalysisResults,

0 commit comments

Comments
 (0)