Skip to content

Commit 4aa168c

Browse files
committed
Load self profile data from cache if possible
1 parent dd55027 commit 4aa168c

File tree

3 files changed

+38
-47
lines changed

3 files changed

+38
-47
lines changed

site/src/request_handlers/graph.rs

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

1414
/// Returns data for a detailed information when comparing a single test result comparison
1515
/// for a compile-time benchmark.
@@ -48,17 +48,12 @@ pub async fn handle_compile_detail(
4848
scenario: Scenario,
4949
) -> Option<CompilationSections> {
5050
match aid {
51-
Some(aid) => download_and_analyze_self_profile(
52-
ctxt,
53-
aid.clone(),
54-
benchmark,
55-
profile,
56-
scenario,
57-
None,
58-
)
59-
.await
60-
.ok()
61-
.map(|profile| compute_sections(&profile)),
51+
Some(aid) => {
52+
get_or_download_self_profile(ctxt, aid.clone(), benchmark, profile, scenario, None)
53+
.await
54+
.ok()
55+
.map(|profile| compute_sections(&profile))
56+
}
6257
None => None,
6358
}
6459
}

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
@@ -199,7 +199,7 @@ pub struct SelfProfileWithAnalysis {
199199
pub profiling_data: analyzeme::AnalysisResults,
200200
}
201201

202-
pub(crate) async fn download_and_analyze_self_profile(
202+
async fn download_and_analyze_self_profile(
203203
ctxt: &SiteCtxt,
204204
aid: ArtifactId,
205205
benchmark: &str,
@@ -230,6 +230,33 @@ pub(crate) async fn download_and_analyze_self_profile(
230230
})
231231
}
232232

233+
pub(crate) async fn get_or_download_self_profile(
234+
ctxt: &SiteCtxt,
235+
aid: ArtifactId,
236+
benchmark: &str,
237+
profile: &str,
238+
scenario: database::Scenario,
239+
metric: Option<f64>,
240+
) -> ServerResult<SelfProfileWithAnalysis> {
241+
let key = SelfProfileKey {
242+
aid: aid.clone(),
243+
benchmark: benchmark.to_string(),
244+
profile: profile.to_string(),
245+
scenario,
246+
};
247+
let cache_result = ctxt.self_profile_cache.lock().get(&key);
248+
match cache_result {
249+
Some(res) => Ok(res),
250+
None => {
251+
let profile =
252+
download_and_analyze_self_profile(ctxt, aid, benchmark, profile, scenario, metric)
253+
.await?;
254+
ctxt.self_profile_cache.lock().insert(key, profile.clone());
255+
Ok(profile)
256+
}
257+
}
258+
}
259+
233260
fn get_self_profile_data(
234261
cpu_clock: Option<f64>,
235262
profile: &analyzeme::AnalysisResults,

0 commit comments

Comments
 (0)