Skip to content

Commit f174358

Browse files
authored
Merge pull request #1647 from Kobzol/self-profile-hw-counters
Switch self profile to use HW counters instead of walltime
2 parents 9459ec2 + 47e20b8 commit f174358

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

collector/src/bin/rustc-fake.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ fn main() {
9595
if wrapper == "PerfStatSelfProfile" {
9696
cmd.arg(&format!(
9797
"-Zself-profile={}",
98-
prof_out_dir.to_str().unwrap()
98+
prof_out_dir.to_str().unwrap(),
9999
));
100+
cmd.arg("-Zself-profile-counter=instructions:u");
100101
let _ = fs::remove_dir_all(&prof_out_dir);
101102
let _ = fs::create_dir_all(&prof_out_dir);
102103
}

site/frontend/src/pages/detailed-query.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {createUrlWithAppendedParams, getUrlParams} from "../utils/navigation";
22
import {postMsgpack} from "../utils/requests";
33
import {SELF_PROFILE_DATA_URL} from "../urls";
44

5-
function to_seconds(time) {
6-
return time / 1000000000;
5+
function normalize_value(value) {
6+
return value;
77
}
88

99
function fmt_delta(to, delta, is_integral_delta) {
@@ -267,14 +267,14 @@ function populate_data(data, state: Selector) {
267267
t.setAttribute("title", "% of cpu-time stat");
268268
}
269269
}
270-
td(row, to_seconds(cur.self_time).toFixed(3));
270+
td(row, normalize_value(cur.self_time));
271271
if (delta) {
272272
td(
273273
row,
274274
fmt_delta(
275-
to_seconds(cur.self_time),
276-
to_seconds(delta.self_time),
277-
false
275+
normalize_value(cur.self_time),
276+
normalize_value(delta.self_time),
277+
true
278278
),
279279
true
280280
);
@@ -291,16 +291,14 @@ function populate_data(data, state: Selector) {
291291
} else {
292292
td(row, "-", true);
293293
}
294-
td(row, to_seconds(cur.incremental_load_time).toFixed(3)).classList.add(
295-
"incr"
296-
);
294+
td(row, normalize_value(cur.incremental_load_time)).classList.add("incr");
297295
if (delta) {
298296
td(
299297
row,
300298
fmt_delta(
301-
to_seconds(cur.incremental_load_time),
302-
to_seconds(delta.incremental_load_time),
303-
false
299+
normalize_value(cur.incremental_load_time),
300+
normalize_value(delta.incremental_load_time),
301+
true
304302
),
305303
true
306304
).classList.add("incr");

site/frontend/templates/pages/detailed-query.html

+8-7
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,21 @@ <h4>Artifact Size</h4>
7979
<tbody id="artifact-body">
8080
</tbody>
8181
</table>
82-
<p>'Time (%)' is the percentage of the cpu-clock time spent on this query (we do not use
83-
wall-time as we want to account for parallelism).</p>
82+
<p>'Instructions (%)' is the percentage of instructions executed on this query.</p>
83+
<p><b>Note: self-profile measurements have been <a href="https://github.com/rust-lang/rustc-perf/pull/1647">recently switched</a>
84+
from wall-time to HW counters (instruction count). If comparing with an older artifact, the timings might not be directly comparable.</b></p>
8485
<p>Executions do not include cached executions.</p>
8586
<table>
8687
<thead>
8788
<tr id="table-header">
8889
<th data-sort-idx="1" data-default-sort-dir="1">Query/Function</th>
89-
<th data-sort-idx="10" data-default-sort-dir="-1">Time (%)</th>
90-
<th data-sort-idx="2" data-default-sort-dir="-1">Time (s)</th>
91-
<th data-sort-idx="11" data-default-sort-dir="-1" class="delta">Time delta</th>
90+
<th data-sort-idx="10" data-default-sort-dir="-1">Instructions (%)</th>
91+
<th data-sort-idx="2" data-default-sort-dir="-1">Instructions</th>
92+
<th data-sort-idx="11" data-default-sort-dir="-1" class="delta">Instructions delta</th>
9293
<th data-sort-idx="5" data-default-sort-dir="-1">Executions</th>
9394
<th data-sort-idx="12" data-default-sort-dir="-1" class="delta">Executions delta</th>
94-
<th class="incr" data-sort-idx="7" data-default-sort-dir="-1" title="Incremental loading time">
95-
Incremental loading (s)</th>
95+
<th class="incr" data-sort-idx="7" data-default-sort-dir="-1" title="Incremental loading instructions">
96+
Incremental loading instructions</th>
9697
<th class="incr delta" data-sort-idx="13" data-default-sort-dir="-1">Incremental loading delta</th>
9798
</tr>
9899
</thead>

site/src/api.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,21 @@ pub mod self_profile {
345345
pub artifact_sizes: Option<Vec<ArtifactSize>>,
346346
}
347347

348+
// Due to backwards compatibility, self profile event timing data is represented as durations,
349+
// however since https://github.com/rust-lang/rustc-perf/pull/1647 it actually represents
350+
// HW counter data (instruction counts).
348351
#[derive(Serialize, Deserialize, Clone, Debug)]
349352
pub struct QueryData {
350353
pub label: QueryLabel,
351-
// Nanoseconds
354+
// Instruction count
352355
pub self_time: u64,
353356
pub percent_total_time: f32,
354357
pub number_of_cache_misses: u32,
355358
pub number_of_cache_hits: u32,
356359
pub invocation_count: u32,
357-
// Nanoseconds
360+
// Instruction count
358361
pub blocked_time: u64,
359-
// Nanoseconds
362+
// Instruction count
360363
pub incremental_load_time: u64,
361364
}
362365

site/src/request_handlers/self_profile.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub async fn handle_self_profile_processed_download(
155155
}
156156

157157
fn get_self_profile_data(
158-
cpu_clock: Option<f64>,
158+
total_instructions: Option<f64>,
159159
profile: &analyzeme::AnalysisResults,
160160
) -> ServerResult<self_profile::SelfProfile> {
161161
let total_time: Duration = profile.query_data.iter().map(|qd| qd.self_time).sum();
@@ -180,7 +180,7 @@ fn get_self_profile_data(
180180
label: "Totals".into(),
181181
self_time: total_time.as_nanos() as u64,
182182
// TODO: check against wall-time from perf stats
183-
percent_total_time: cpu_clock
183+
percent_total_time: total_instructions
184184
.map(|w| ((total_time.as_secs_f64() / w) * 100.0) as f32)
185185
// sentinel "we couldn't compute this time"
186186
.unwrap_or(-100.0),
@@ -587,7 +587,7 @@ pub async fn handle_self_profile(
587587
.benchmark(selector::Selector::One(bench_name.to_string()))
588588
.profile(selector::Selector::One(profile.parse().unwrap()))
589589
.scenario(selector::Selector::One(scenario))
590-
.metric(selector::Selector::One(Metric::CpuClock));
590+
.metric(selector::Selector::One(Metric::InstructionsUser));
591591

592592
// Helper for finding an `ArtifactId` based on a commit sha
593593
let find_aid = |commit: &str| {
@@ -602,9 +602,9 @@ pub async fn handle_self_profile(
602602
}
603603
let commits = Arc::new(commits);
604604

605-
let mut cpu_responses = ctxt.statistic_series(query, commits.clone()).await?;
606-
assert_eq!(cpu_responses.len(), 1, "all selectors are exact");
607-
let mut cpu_response = cpu_responses.remove(0).series;
605+
let mut instructions_responses = ctxt.statistic_series(query, commits.clone()).await?;
606+
assert_eq!(instructions_responses.len(), 1, "all selectors are exact");
607+
let mut instructions_response = instructions_responses.remove(0).series;
608608

609609
let mut self_profile_data = Vec::new();
610610
let conn = ctxt.conn().await;
@@ -623,12 +623,16 @@ pub async fn handle_self_profile(
623623
}
624624
}
625625
let profiling_data = self_profile_data.remove(0).perform_analysis();
626-
let mut profile = get_self_profile_data(cpu_response.next().unwrap().1, &profiling_data)
627-
.map_err(|e| format!("{}: {}", body.commit, e))?;
626+
let mut profile =
627+
get_self_profile_data(instructions_response.next().unwrap().1, &profiling_data)
628+
.map_err(|e| format!("{}: {}", body.commit, e))?;
628629
let (base_profile, base_raw_data) = if body.base_commit.is_some() {
629630
let base_profiling_data = self_profile_data.remove(0).perform_analysis();
630-
let profile = get_self_profile_data(cpu_response.next().unwrap().1, &base_profiling_data)
631-
.map_err(|e| format!("{}: {}", body.base_commit.as_ref().unwrap(), e))?;
631+
let profile = get_self_profile_data(
632+
instructions_response.next().unwrap().1,
633+
&base_profiling_data,
634+
)
635+
.map_err(|e| format!("{}: {}", body.base_commit.as_ref().unwrap(), e))?;
632636
(Some(profile), Some(base_profiling_data))
633637
} else {
634638
(None, None)

0 commit comments

Comments
 (0)