Skip to content

Commit

Permalink
Collect self profile results
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Nov 25, 2018
1 parent 88b29cb commit 8ee44e1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
41 changes: 27 additions & 14 deletions collector/src/bin/rustc-perf-collector/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::cmp;
use tempfile::TempDir;

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

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

let output = command_output(&mut cmd)?;
let self_profile_json = fs::read_to_string(self.cwd.join("self_profile_results.json"))?;
if let Some((ref mut processor, name, run_kind, run_kind_str, patch)) =
self.processor_etc {
let data = ProcessOutputData {
Expand All @@ -237,6 +241,7 @@ impl<'a> CargoProcess<'a> {
run_kind,
run_kind_str,
patch,
self_profile: serde_json::from_str(&self_profile_json).unwrap(),
};
match processor.process_output(&data, output) {
Ok(Retry::No) => return Ok(()),
Expand Down Expand Up @@ -271,6 +276,7 @@ pub struct ProcessOutputData<'a> {
build_kind: BuildKind,
run_kind: RunKind,
run_kind_str: &'a str,
self_profile: SelfProfile,
patch: Option<&'a Patch>,
}

Expand All @@ -290,11 +296,11 @@ pub trait Processor {
}

pub struct MeasureProcessor {
clean_stats: Vec<Vec<Stat>>,
nll_stats: Vec<Vec<Stat>>,
base_incr_stats: Vec<Vec<Stat>>,
clean_incr_stats: Vec<Vec<Stat>>,
patched_incr_stats: Vec<(Patch, Vec<Vec<Stat>>)>,
clean_stats: Vec<(Vec<Stat>, SelfProfile)>,
nll_stats: Vec<(Vec<Stat>, SelfProfile)>,
base_incr_stats: Vec<(Vec<Stat>, SelfProfile)>,
clean_incr_stats: Vec<(Vec<Stat>, SelfProfile)>,
patched_incr_stats: Vec<(Patch, Vec<(Vec<Stat>, SelfProfile)>)>,

pub collected: CollectedBenchmark,
}
Expand Down Expand Up @@ -329,20 +335,21 @@ impl Processor for MeasureProcessor {
-> Result<Retry, Error> {
match process_perf_stat_output(output) {
Ok(stats) => {
let self_profile = data.self_profile.clone();
match data.run_kind {
RunKind::Clean => { self.clean_stats.push(stats); }
RunKind::Nll => { self.nll_stats.push(stats); }
RunKind::BaseIncr => { self.base_incr_stats.push(stats); }
RunKind::CleanIncr => { self.clean_incr_stats.push(stats); }
RunKind::Clean => { self.clean_stats.push((stats, self_profile)); }
RunKind::Nll => { self.nll_stats.push((stats, self_profile)); }
RunKind::BaseIncr => { self.base_incr_stats.push((stats, self_profile)); }
RunKind::CleanIncr => { self.clean_incr_stats.push((stats, self_profile)); }
RunKind::PatchedIncrs => {
let patch = data.patch.unwrap();
if let Some(mut entry) =
self.patched_incr_stats.iter_mut().find(|s| &s.0 == patch)
{
entry.1.push(stats);
entry.1.push((stats, self_profile));
return Ok(Retry::No);
}
self.patched_incr_stats.push((patch.clone(), vec![stats]));
self.patched_incr_stats.push((patch.clone(), vec![(stats, self_profile)]));
}
}
Ok(Retry::No)
Expand Down Expand Up @@ -776,10 +783,14 @@ fn process_perf_stat_output(output: process::Output) -> Result<Vec<Stat>, Deseri
Ok(stats)
}

fn process_stats(build_kind: BuildKind, state: BenchmarkState, runs: &[Vec<Stat>]) -> Run {
fn process_stats(
build_kind: BuildKind,
state: BenchmarkState,
runs: &[(Vec<Stat>, SelfProfile)],
) -> Run {
let mut stats: HashMap<String, Vec<f64>> = HashMap::new();
for run in runs.clone() {
for stat in run {
for (run_stats, _) in runs.clone() {
for stat in run_stats {
stats
.entry(stat.name.clone())
.or_insert_with(|| Vec::new())
Expand Down Expand Up @@ -811,5 +822,7 @@ fn process_stats(build_kind: BuildKind, state: BenchmarkState, runs: &[Vec<Stat>
check: build_kind == BuildKind::Check,
release: build_kind == BuildKind::Opt,
state: state,
// TODO: Aggregate self profiles.
self_profile: runs[0].1.clone(),
}
}
2 changes: 2 additions & 0 deletions collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use chrono::naive::NaiveDate;
use serde::{Deserialize, Serialize};

pub mod api;
pub mod self_profile;

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Commit {
Expand Down Expand Up @@ -194,6 +195,7 @@ pub struct Stat {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Run {
pub stats: Vec<Stat>,
pub self_profile: self_profile::SelfProfile,
#[serde(default)]
pub check: bool,
pub release: bool,
Expand Down
25 changes: 25 additions & 0 deletions collector/src/self_profile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SelfProfile {
pub category_data: Vec<Category>,
// This field is intentionally private as for perf it should not be read.
compilation_options: Options,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Category {
/// Category name, e.g. Parsing
#[serde(rename = "category")]
pub name: String,
/// Duration of all queries executed, combined, in milliseconds
pub time_ms: u64,
/// Number of queries executed
pub query_count: u64,
/// Percentage of query hits that were cached
pub query_hits: f32,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
struct Options {
optimization_level: String,
incremental: bool,
}

0 comments on commit 8ee44e1

Please sign in to comment.