From 101cdc57c2eaec7c98213cf8babcad6c6342a144 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Jul 2020 00:16:21 +0200 Subject: Add self-analysis-stats to metrics --- xtask/src/main.rs | 8 +++++-- xtask/src/metrics.rs | 63 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 25 deletions(-) (limited to 'xtask') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 604954269..b69b884e5 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -15,7 +15,7 @@ use xtask::{ codegen::{self, Mode}, dist::DistCmd, install::{ClientOpt, InstallCmd, Malloc, ServerOpt}, - metrics::run_metrics, + metrics::MetricsCmd, not_bash::pushd, pre_commit, project_root, release::{PromoteCmd, ReleaseCmd}, @@ -118,7 +118,11 @@ FLAGS: args.finish()?; DistCmd { nightly, client_version }.run() } - "metrics" => run_metrics(), + "metrics" => { + let dry_run = args.contains("--dry-run"); + args.finish()?; + MetricsCmd { dry_run }.run() + } _ => { eprintln!( "\ diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs index 9567f18f0..6c042d695 100644 --- a/xtask/src/metrics.rs +++ b/xtask/src/metrics.rs @@ -12,36 +12,53 @@ use crate::not_bash::{fs2, pushd, rm_rf, run}; type Unit = &'static str; -pub fn run_metrics() -> Result<()> { - let mut metrics = Metrics::new()?; - metrics.measure_build()?; - - { - let _d = pushd("target"); - let metrics_token = env::var("METRICS_TOKEN").unwrap(); - let repo = format!("https://{}@github.com/rust-analyzer/metrics.git", metrics_token); - run!("git clone --depth 1 {}", repo)?; - let _d = pushd("metrics"); - - let mut file = std::fs::OpenOptions::new().append(true).open("metrics.json")?; - writeln!(file, "{}", metrics.json())?; - run!("git add .")?; - run!("git -c user.name=Bot -c user.email=dummy@example.com commit --message 📈")?; - run!("git push origin master")?; - } - eprintln!("{:#?}", metrics); - Ok(()) +pub struct MetricsCmd { + pub dry_run: bool, +} + +impl MetricsCmd { + pub fn run(self) -> Result<()> { + let mut metrics = Metrics::new()?; + if !self.dry_run { + rm_rf("./target/release")?; + } + + metrics.measure_build()?; + metrics.measure_analysis_stats_self()?; + + if !self.dry_run { + let _d = pushd("target"); + let metrics_token = env::var("METRICS_TOKEN").unwrap(); + let repo = format!("https://{}@github.com/rust-analyzer/metrics.git", metrics_token); + run!("git clone --depth 1 {}", repo)?; + let _d = pushd("metrics"); + + let mut file = std::fs::OpenOptions::new().append(true).open("metrics.json")?; + writeln!(file, "{}", metrics.json())?; + run!("git add .")?; + run!("git -c user.name=Bot -c user.email=dummy@example.com commit --message 📈")?; + run!("git push origin master")?; + } + eprintln!("{:#?}", metrics); + Ok(()) + } } impl Metrics { fn measure_build(&mut self) -> Result<()> { run!("cargo fetch")?; - rm_rf("./target/release")?; - let build = Instant::now(); + let time = Instant::now(); run!("cargo build --release --package rust-analyzer --bin rust-analyzer")?; - let build = build.elapsed(); - self.report("build", build.as_millis() as u64, "ms"); + let time = time.elapsed(); + self.report("build", time.as_millis() as u64, "ms"); + 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"); Ok(()) } } -- cgit v1.2.3