From 451edcc09866d43def7db88d5d9c139a96ead58e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Jul 2020 10:35:45 +0200 Subject: Add rustc-perf to metrics --- xtask/src/metrics.rs | 55 ++++++++++++++++++++++++++++++++++++++++++--------- xtask/src/not_bash.rs | 3 ++- 2 files changed, 48 insertions(+), 10 deletions(-) (limited to 'xtask') diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs index 6c042d695..9ac3fa51d 100644 --- a/xtask/src/metrics.rs +++ b/xtask/src/metrics.rs @@ -3,14 +3,15 @@ use std::{ env, fmt::{self, Write as _}, io::Write as _, + path::Path, time::{Instant, SystemTime, UNIX_EPOCH}, }; use anyhow::{bail, format_err, Result}; -use crate::not_bash::{fs2, pushd, rm_rf, run}; +use crate::not_bash::{fs2, pushd, pushenv, rm_rf, run}; -type Unit = &'static str; +type Unit = String; pub struct MetricsCmd { pub dry_run: bool, @@ -22,9 +23,21 @@ impl MetricsCmd { if !self.dry_run { rm_rf("./target/release")?; } + if !Path::new("./target/rustc-perf").exists() { + fs2::create_dir_all("./target/rustc-perf")?; + run!("git clone https://github.com/rust-lang/rustc-perf.git ./target/rustc-perf")?; + } + { + let _d = pushd("./target/rustc-perf"); + run!("git reset --hard 1d9288b0da7febf2599917da1b57dc241a1af033")?; + } + + let _env = pushenv("RA_METRICS", "1"); metrics.measure_build()?; metrics.measure_analysis_stats_self()?; + metrics.measure_analysis_stats("ripgrep")?; + metrics.measure_analysis_stats("webrender")?; if !self.dry_run { let _d = pushd("target"); @@ -46,23 +59,47 @@ impl MetricsCmd { impl Metrics { fn measure_build(&mut self) -> Result<()> { + eprintln!("\nMeasuring build"); run!("cargo fetch")?; let time = Instant::now(); run!("cargo build --release --package rust-analyzer --bin rust-analyzer")?; let time = time.elapsed(); - self.report("build", time.as_millis() as u64, "ms"); + self.report("build", time.as_millis() as u64, "ms".into()); Ok(()) } fn measure_analysis_stats_self(&mut self) -> Result<()> { - let time = Instant::now(); - run!("./target/release/rust-analyzer analysis-stats .")?; - let time = time.elapsed(); - self.report("analysis-stats/self", time.as_millis() as u64, "ms"); + self.measure_analysis_stats_path("self", &".") + } + fn measure_analysis_stats(&mut self, bench: &str) -> Result<()> { + self.measure_analysis_stats_path( + bench, + &format!("./target/rustc-perf/collector/benchmarks/{}", bench), + ) + } + fn measure_analysis_stats_path(&mut self, name: &str, path: &str) -> Result<()> { + eprintln!("\nMeasuring analysis-stats/{}", name); + let output = run!("./target/release/rust-analyzer analysis-stats --quiet {}", path)?; + for (metric, value, unit) in parse_metrics(&output) { + self.report(&format!("analysis-stats/{}/{}", name, metric), value, unit.into()); + } Ok(()) } } +fn parse_metrics(output: &str) -> Vec<(&str, u64, &str)> { + output + .lines() + .filter_map(|it| { + let entry = it.split(':').collect::>(); + match entry.as_slice() { + ["METRIC", name, value, unit] => Some((*name, value.parse().unwrap(), *unit)), + _ => None, + } + }) + .collect() +} + #[derive(Debug)] struct Metrics { host: Host, @@ -111,11 +148,11 @@ impl Metrics { json.field("metrics"); json.begin_object(); { - for (k, &(value, unit)) in &self.metrics { + for (k, (value, unit)) in &self.metrics { json.field(k); json.begin_array(); { - json.number(value as f64); + json.number(*value as f64); json.string(unit); } json.end_array(); diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 0f3a56b25..ef811e5bf 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -186,7 +186,8 @@ impl Env { fn pushd(&mut self, dir: PathBuf) { let dir = self.cwd().join(dir); self.pushd_stack.push(dir); - env::set_current_dir(self.cwd()).unwrap(); + env::set_current_dir(self.cwd()) + .unwrap_or_else(|err| panic!("Failed to set cwd to {}: {}", self.cwd().display(), err)); } fn popd(&mut self) { self.pushd_stack.pop().unwrap(); -- cgit v1.2.3