Skip to content

Commit b7a8b49

Browse files
committed
Return compilation sections from benchmark detail endpoint
1 parent 42ebc55 commit b7a8b49

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

site/src/api.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,21 @@ pub mod detail {
162162
deserializer.deserialize_str(CommaSeparatedVisitor(Default::default()))
163163
}
164164

165-
#[derive(Debug, PartialEq, Clone, Serialize)]
165+
/// Counts how much <resource> (time/instructions) was spent in individual compilation sections
166+
/// (frontend, backend, linking) during the compilation of a single test case.
167+
#[derive(Default, Debug, Serialize)]
168+
pub struct CompilationSections {
169+
pub frontend: u64,
170+
pub backend: u64,
171+
pub linker: u64,
172+
}
173+
174+
#[derive(Debug, Serialize)]
166175
pub struct Response {
167176
pub commits: Vec<(i64, String)>,
168177
pub graphs: Vec<Series>,
178+
pub sections_before: Option<CompilationSections>,
179+
pub sections_after: Option<CompilationSections>,
169180
}
170181
}
171182

site/src/request_handlers/graph.rs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use collector::Bound;
22
use std::collections::HashMap;
33
use std::sync::Arc;
44

5+
use crate::api::detail::CompilationSections;
56
use crate::api::graphs::GraphKind;
67
use crate::api::{detail, graphs, ServerResult};
78
use crate::db::{self, ArtifactId, Profile, Scenario};
89
use crate::interpolate::IsInterpolated;
910
use crate::load::SiteCtxt;
1011
use crate::selector::{CompileBenchmarkQuery, CompileTestCase, Selector, SeriesResponse};
12+
use crate::self_profile::{download_and_analyze_self_profile, SelfProfileWithAnalysis};
1113

1214
/// Returns data for a detailed information when comparing a single test result comparison
1315
/// for a compile-time benchmark.
@@ -23,12 +25,13 @@ pub async fn handle_compile_detail(
2325
request.end,
2426
));
2527

28+
let scenario = request.scenario.parse()?;
2629
let interpolated_responses: Vec<_> = ctxt
2730
.statistic_series(
2831
CompileBenchmarkQuery::default()
29-
.benchmark(Selector::One(request.benchmark))
32+
.benchmark(Selector::One(request.benchmark.clone()))
3033
.profile(Selector::One(request.profile.parse()?))
31-
.scenario(Selector::One(request.scenario.parse()?))
34+
.scenario(Selector::One(scenario))
3235
.metric(Selector::One(request.stat.parse()?)),
3336
artifact_ids.clone(),
3437
)
@@ -37,6 +40,46 @@ pub async fn handle_compile_detail(
3740
.map(|sr| sr.interpolate().map(|series| series.collect::<Vec<_>>()))
3841
.collect();
3942

43+
async fn calculate_sections(
44+
ctxt: &SiteCtxt,
45+
aid: Option<&ArtifactId>,
46+
benchmark: &str,
47+
profile: &str,
48+
scenario: Scenario,
49+
) -> Option<CompilationSections> {
50+
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)),
62+
None => None,
63+
}
64+
}
65+
66+
let sections_before = calculate_sections(
67+
&ctxt,
68+
artifact_ids.get(0),
69+
&request.benchmark,
70+
&request.profile,
71+
scenario,
72+
)
73+
.await;
74+
let sections_after = calculate_sections(
75+
&ctxt,
76+
artifact_ids.get(1),
77+
&request.benchmark,
78+
&request.profile,
79+
scenario,
80+
)
81+
.await;
82+
4083
let mut graphs = Vec::new();
4184

4285
let mut interpolated_responses = interpolated_responses.into_iter();
@@ -51,9 +94,26 @@ pub async fn handle_compile_detail(
5194
Ok(detail::Response {
5295
commits: artifact_ids_to_commits(artifact_ids),
5396
graphs,
97+
sections_before,
98+
sections_after,
5499
})
55100
}
56101

102+
fn compute_sections(profile: &SelfProfileWithAnalysis) -> CompilationSections {
103+
let mut sections = CompilationSections::default();
104+
for query in &profile.profile.query_data {
105+
let query_name = query.label.as_str().to_lowercase();
106+
if query_name.contains("link") {
107+
sections.linker += query.self_time;
108+
} else if query_name.contains("llvm") {
109+
sections.backend += query.self_time;
110+
} else {
111+
sections.frontend += query.self_time;
112+
}
113+
}
114+
sections
115+
}
116+
57117
pub async fn handle_graphs(
58118
request: graphs::Request,
59119
ctxt: Arc<SiteCtxt>,

site/src/self_profile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub(crate) async fn download_and_analyze_self_profile(
172172
) -> ServerResult<SelfProfileWithAnalysis> {
173173
let conn = ctxt.conn().await;
174174
let aids_and_cids = conn
175-
.list_self_profile(aid.clone(), benchmark, profile, &scenario.to_id())
175+
.list_self_profile(aid.clone(), benchmark, profile, &scenario.to_string())
176176
.await;
177177

178178
let Some((anum, cid)) = aids_and_cids.first() else {

0 commit comments

Comments
 (0)