Add self-analysis-stats to metrics

This commit is contained in:
Aleksey Kladov 2020-07-25 00:16:21 +02:00
parent a09a00a560
commit 101cdc57c2
2 changed files with 43 additions and 22 deletions

View file

@ -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!(
"\

View file

@ -12,11 +12,21 @@ 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()?;
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);
@ -32,16 +42,23 @@ pub fn run_metrics() -> Result<()> {
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(())
}
}