Skip to content

Commit 8ee44e1

Browse files
Collect self profile results
1 parent 88b29cb commit 8ee44e1

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

collector/src/bin/rustc-perf-collector/execute.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::cmp;
1313
use tempfile::TempDir;
1414

1515
use collector::{Benchmark as CollectedBenchmark, BenchmarkState, Patch, Run, Stat};
16+
use collector::self_profile::SelfProfile;
1617

1718
use failure::{err_msg, Error, ResultExt};
1819
use serde_json;
@@ -211,6 +212,8 @@ impl<'a> CargoProcess<'a> {
211212
cmd.arg("-Zborrowck=mir");
212213
cmd.arg("-Ztwo-phase-borrows");
213214
}
215+
cmd.arg("-Zself-profile");
216+
cmd.arg("-Zprofile-json");
214217
// --wrap-rustc-with is not a valid rustc flag. But rustc-fake
215218
// recognizes it, strips it (and its argument) out, and uses it as an
216219
// indicator that the rustc invocation should be profiled. This works
@@ -228,6 +231,7 @@ impl<'a> CargoProcess<'a> {
228231
touch_all(&self.cwd)?;
229232

230233
let output = command_output(&mut cmd)?;
234+
let self_profile_json = fs::read_to_string(self.cwd.join("self_profile_results.json"))?;
231235
if let Some((ref mut processor, name, run_kind, run_kind_str, patch)) =
232236
self.processor_etc {
233237
let data = ProcessOutputData {
@@ -237,6 +241,7 @@ impl<'a> CargoProcess<'a> {
237241
run_kind,
238242
run_kind_str,
239243
patch,
244+
self_profile: serde_json::from_str(&self_profile_json).unwrap(),
240245
};
241246
match processor.process_output(&data, output) {
242247
Ok(Retry::No) => return Ok(()),
@@ -271,6 +276,7 @@ pub struct ProcessOutputData<'a> {
271276
build_kind: BuildKind,
272277
run_kind: RunKind,
273278
run_kind_str: &'a str,
279+
self_profile: SelfProfile,
274280
patch: Option<&'a Patch>,
275281
}
276282

@@ -290,11 +296,11 @@ pub trait Processor {
290296
}
291297

292298
pub struct MeasureProcessor {
293-
clean_stats: Vec<Vec<Stat>>,
294-
nll_stats: Vec<Vec<Stat>>,
295-
base_incr_stats: Vec<Vec<Stat>>,
296-
clean_incr_stats: Vec<Vec<Stat>>,
297-
patched_incr_stats: Vec<(Patch, Vec<Vec<Stat>>)>,
299+
clean_stats: Vec<(Vec<Stat>, SelfProfile)>,
300+
nll_stats: Vec<(Vec<Stat>, SelfProfile)>,
301+
base_incr_stats: Vec<(Vec<Stat>, SelfProfile)>,
302+
clean_incr_stats: Vec<(Vec<Stat>, SelfProfile)>,
303+
patched_incr_stats: Vec<(Patch, Vec<(Vec<Stat>, SelfProfile)>)>,
298304

299305
pub collected: CollectedBenchmark,
300306
}
@@ -329,20 +335,21 @@ impl Processor for MeasureProcessor {
329335
-> Result<Retry, Error> {
330336
match process_perf_stat_output(output) {
331337
Ok(stats) => {
338+
let self_profile = data.self_profile.clone();
332339
match data.run_kind {
333-
RunKind::Clean => { self.clean_stats.push(stats); }
334-
RunKind::Nll => { self.nll_stats.push(stats); }
335-
RunKind::BaseIncr => { self.base_incr_stats.push(stats); }
336-
RunKind::CleanIncr => { self.clean_incr_stats.push(stats); }
340+
RunKind::Clean => { self.clean_stats.push((stats, self_profile)); }
341+
RunKind::Nll => { self.nll_stats.push((stats, self_profile)); }
342+
RunKind::BaseIncr => { self.base_incr_stats.push((stats, self_profile)); }
343+
RunKind::CleanIncr => { self.clean_incr_stats.push((stats, self_profile)); }
337344
RunKind::PatchedIncrs => {
338345
let patch = data.patch.unwrap();
339346
if let Some(mut entry) =
340347
self.patched_incr_stats.iter_mut().find(|s| &s.0 == patch)
341348
{
342-
entry.1.push(stats);
349+
entry.1.push((stats, self_profile));
343350
return Ok(Retry::No);
344351
}
345-
self.patched_incr_stats.push((patch.clone(), vec![stats]));
352+
self.patched_incr_stats.push((patch.clone(), vec![(stats, self_profile)]));
346353
}
347354
}
348355
Ok(Retry::No)
@@ -776,10 +783,14 @@ fn process_perf_stat_output(output: process::Output) -> Result<Vec<Stat>, Deseri
776783
Ok(stats)
777784
}
778785

779-
fn process_stats(build_kind: BuildKind, state: BenchmarkState, runs: &[Vec<Stat>]) -> Run {
786+
fn process_stats(
787+
build_kind: BuildKind,
788+
state: BenchmarkState,
789+
runs: &[(Vec<Stat>, SelfProfile)],
790+
) -> Run {
780791
let mut stats: HashMap<String, Vec<f64>> = HashMap::new();
781-
for run in runs.clone() {
782-
for stat in run {
792+
for (run_stats, _) in runs.clone() {
793+
for stat in run_stats {
783794
stats
784795
.entry(stat.name.clone())
785796
.or_insert_with(|| Vec::new())
@@ -811,5 +822,7 @@ fn process_stats(build_kind: BuildKind, state: BenchmarkState, runs: &[Vec<Stat>
811822
check: build_kind == BuildKind::Check,
812823
release: build_kind == BuildKind::Opt,
813824
state: state,
825+
// TODO: Aggregate self profiles.
826+
self_profile: runs[0].1.clone(),
814827
}
815828
}

collector/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use chrono::naive::NaiveDate;
2121
use serde::{Deserialize, Serialize};
2222

2323
pub mod api;
24+
pub mod self_profile;
2425

2526
#[derive(Debug, Clone, Deserialize, Serialize)]
2627
pub struct Commit {
@@ -194,6 +195,7 @@ pub struct Stat {
194195
#[derive(Debug, Clone, Deserialize, Serialize)]
195196
pub struct Run {
196197
pub stats: Vec<Stat>,
198+
pub self_profile: self_profile::SelfProfile,
197199
#[serde(default)]
198200
pub check: bool,
199201
pub release: bool,

collector/src/self_profile.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#[derive(Serialize, Deserialize, Debug, Clone)]
2+
pub struct SelfProfile {
3+
pub category_data: Vec<Category>,
4+
// This field is intentionally private as for perf it should not be read.
5+
compilation_options: Options,
6+
}
7+
8+
#[derive(Serialize, Deserialize, Debug, Clone)]
9+
pub struct Category {
10+
/// Category name, e.g. Parsing
11+
#[serde(rename = "category")]
12+
pub name: String,
13+
/// Duration of all queries executed, combined, in milliseconds
14+
pub time_ms: u64,
15+
/// Number of queries executed
16+
pub query_count: u64,
17+
/// Percentage of query hits that were cached
18+
pub query_hits: f32,
19+
}
20+
21+
#[derive(Serialize, Deserialize, Debug, Clone)]
22+
struct Options {
23+
optimization_level: String,
24+
incremental: bool,
25+
}

0 commit comments

Comments
 (0)