aboutsummaryrefslogtreecommitdiff
path: root/xtask
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-24 23:16:21 +0100
committerAleksey Kladov <[email protected]>2020-07-24 23:16:21 +0100
commit101cdc57c2eaec7c98213cf8babcad6c6342a144 (patch)
tree65d924108908be412680cb377de1149d84a4140c /xtask
parenta09a00a56049c705dcddc33773a27d5ce976b02e (diff)
Add self-analysis-stats to metrics
Diffstat (limited to 'xtask')
-rw-r--r--xtask/src/main.rs8
-rw-r--r--xtask/src/metrics.rs63
2 files changed, 46 insertions, 25 deletions
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::{
15 codegen::{self, Mode}, 15 codegen::{self, Mode},
16 dist::DistCmd, 16 dist::DistCmd,
17 install::{ClientOpt, InstallCmd, Malloc, ServerOpt}, 17 install::{ClientOpt, InstallCmd, Malloc, ServerOpt},
18 metrics::run_metrics, 18 metrics::MetricsCmd,
19 not_bash::pushd, 19 not_bash::pushd,
20 pre_commit, project_root, 20 pre_commit, project_root,
21 release::{PromoteCmd, ReleaseCmd}, 21 release::{PromoteCmd, ReleaseCmd},
@@ -118,7 +118,11 @@ FLAGS:
118 args.finish()?; 118 args.finish()?;
119 DistCmd { nightly, client_version }.run() 119 DistCmd { nightly, client_version }.run()
120 } 120 }
121 "metrics" => run_metrics(), 121 "metrics" => {
122 let dry_run = args.contains("--dry-run");
123 args.finish()?;
124 MetricsCmd { dry_run }.run()
125 }
122 _ => { 126 _ => {
123 eprintln!( 127 eprintln!(
124 "\ 128 "\
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};
12 12
13type Unit = &'static str; 13type Unit = &'static str;
14 14
15pub fn run_metrics() -> Result<()> { 15pub struct MetricsCmd {
16 let mut metrics = Metrics::new()?; 16 pub dry_run: bool,
17 metrics.measure_build()?; 17}
18 18
19 { 19impl MetricsCmd {
20 let _d = pushd("target"); 20 pub fn run(self) -> Result<()> {
21 let metrics_token = env::var("METRICS_TOKEN").unwrap(); 21 let mut metrics = Metrics::new()?;
22 let repo = format!("https://{}@github.com/rust-analyzer/metrics.git", metrics_token); 22 if !self.dry_run {
23 run!("git clone --depth 1 {}", repo)?; 23 rm_rf("./target/release")?;
24 let _d = pushd("metrics"); 24 }
25 25
26 let mut file = std::fs::OpenOptions::new().append(true).open("metrics.json")?; 26 metrics.measure_build()?;
27 writeln!(file, "{}", metrics.json())?; 27 metrics.measure_analysis_stats_self()?;
28 run!("git add .")?; 28
29 run!("git -c user.name=Bot -c [email protected] commit --message 📈")?; 29 if !self.dry_run {
30 run!("git push origin master")?; 30 let _d = pushd("target");
31 } 31 let metrics_token = env::var("METRICS_TOKEN").unwrap();
32 eprintln!("{:#?}", metrics); 32 let repo = format!("https://{}@github.com/rust-analyzer/metrics.git", metrics_token);
33 Ok(()) 33 run!("git clone --depth 1 {}", repo)?;
34 let _d = pushd("metrics");
35
36 let mut file = std::fs::OpenOptions::new().append(true).open("metrics.json")?;
37 writeln!(file, "{}", metrics.json())?;
38 run!("git add .")?;
39 run!("git -c user.name=Bot -c [email protected] commit --message 📈")?;
40 run!("git push origin master")?;
41 }
42 eprintln!("{:#?}", metrics);
43 Ok(())
44 }
34} 45}
35 46
36impl Metrics { 47impl Metrics {
37 fn measure_build(&mut self) -> Result<()> { 48 fn measure_build(&mut self) -> Result<()> {
38 run!("cargo fetch")?; 49 run!("cargo fetch")?;
39 rm_rf("./target/release")?;
40 50
41 let build = Instant::now(); 51 let time = Instant::now();
42 run!("cargo build --release --package rust-analyzer --bin rust-analyzer")?; 52 run!("cargo build --release --package rust-analyzer --bin rust-analyzer")?;
43 let build = build.elapsed(); 53 let time = time.elapsed();
44 self.report("build", build.as_millis() as u64, "ms"); 54 self.report("build", time.as_millis() as u64, "ms");
55 Ok(())
56 }
57 fn measure_analysis_stats_self(&mut self) -> Result<()> {
58 let time = Instant::now();
59 run!("./target/release/rust-analyzer analysis-stats .")?;
60 let time = time.elapsed();
61 self.report("analysis-stats/self", time.as_millis() as u64, "ms");
45 Ok(()) 62 Ok(())
46 } 63 }
47} 64}