aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/metrics.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-17 01:44:12 +0100
committerGitHub <[email protected]>2020-10-17 01:44:12 +0100
commit59483c217662fc5d89ef9da1cb93760e14a48418 (patch)
treecf93fa6a4f3d18e8be27acf56ee85927fd6f66c7 /xtask/src/metrics.rs
parentf0412da4a2c06e50030d13e37002d0440fc7cded (diff)
parent49a90d4c31148a6533d9ee9a288f42b454b2f421 (diff)
Merge #6260
6260: xshell r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'xtask/src/metrics.rs')
-rw-r--r--xtask/src/metrics.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs
index 4bade2c7e..e0d1aaf97 100644
--- a/xtask/src/metrics.rs
+++ b/xtask/src/metrics.rs
@@ -7,8 +7,7 @@ use std::{
7}; 7};
8 8
9use anyhow::{bail, format_err, Result}; 9use anyhow::{bail, format_err, Result};
10 10use xshell::{cmd, mkdir_p, pushd, pushenv, read_file, rm_rf};
11use crate::not_bash::{fs2, pushd, pushenv, rm_rf, run};
12 11
13type Unit = String; 12type Unit = String;
14 13
@@ -23,12 +22,13 @@ impl MetricsCmd {
23 rm_rf("./target/release")?; 22 rm_rf("./target/release")?;
24 } 23 }
25 if !Path::new("./target/rustc-perf").exists() { 24 if !Path::new("./target/rustc-perf").exists() {
26 fs2::create_dir_all("./target/rustc-perf")?; 25 mkdir_p("./target/rustc-perf")?;
27 run!("git clone https://github.com/rust-lang/rustc-perf.git ./target/rustc-perf")?; 26 cmd!("git clone https://github.com/rust-lang/rustc-perf.git ./target/rustc-perf")
27 .run()?;
28 } 28 }
29 { 29 {
30 let _d = pushd("./target/rustc-perf"); 30 let _d = pushd("./target/rustc-perf")?;
31 run!("git reset --hard 1d9288b0da7febf2599917da1b57dc241a1af033")?; 31 cmd!("git reset --hard 1d9288b0da7febf2599917da1b57dc241a1af033").run()?;
32 } 32 }
33 33
34 let _env = pushenv("RA_METRICS", "1"); 34 let _env = pushenv("RA_METRICS", "1");
@@ -39,17 +39,20 @@ impl MetricsCmd {
39 metrics.measure_analysis_stats("webrender")?; 39 metrics.measure_analysis_stats("webrender")?;
40 40
41 if !self.dry_run { 41 if !self.dry_run {
42 let _d = pushd("target"); 42 let _d = pushd("target")?;
43 let metrics_token = env::var("METRICS_TOKEN").unwrap(); 43 let metrics_token = env::var("METRICS_TOKEN").unwrap();
44 let repo = format!("https://{}@github.com/rust-analyzer/metrics.git", metrics_token); 44 cmd!(
45 run!("git clone --depth 1 {}", repo)?; 45 "git clone --depth 1 https://{metrics_token}@github.com/rust-analyzer/metrics.git"
46 let _d = pushd("metrics"); 46 )
47 .run()?;
48 let _d = pushd("metrics")?;
47 49
48 let mut file = std::fs::OpenOptions::new().append(true).open("metrics.json")?; 50 let mut file = std::fs::OpenOptions::new().append(true).open("metrics.json")?;
49 writeln!(file, "{}", metrics.json())?; 51 writeln!(file, "{}", metrics.json())?;
50 run!("git add .")?; 52 cmd!("git add .").run()?;
51 run!("git -c user.name=Bot -c [email protected] commit --message 📈")?; 53 cmd!("git -c user.name=Bot -c [email protected] commit --message 📈")
52 run!("git push origin master")?; 54 .run()?;
55 cmd!("git push origin master").run()?;
53 } 56 }
54 eprintln!("{:#?}", metrics); 57 eprintln!("{:#?}", metrics);
55 Ok(()) 58 Ok(())
@@ -59,10 +62,10 @@ impl MetricsCmd {
59impl Metrics { 62impl Metrics {
60 fn measure_build(&mut self) -> Result<()> { 63 fn measure_build(&mut self) -> Result<()> {
61 eprintln!("\nMeasuring build"); 64 eprintln!("\nMeasuring build");
62 run!("cargo fetch")?; 65 cmd!("cargo fetch").run()?;
63 66
64 let time = Instant::now(); 67 let time = Instant::now();
65 run!("cargo build --release --package rust-analyzer --bin rust-analyzer")?; 68 cmd!("cargo build --release --package rust-analyzer --bin rust-analyzer").run()?;
66 let time = time.elapsed(); 69 let time = time.elapsed();
67 self.report("build", time.as_millis() as u64, "ms".into()); 70 self.report("build", time.as_millis() as u64, "ms".into());
68 Ok(()) 71 Ok(())
@@ -78,7 +81,7 @@ impl Metrics {
78 } 81 }
79 fn measure_analysis_stats_path(&mut self, name: &str, path: &str) -> Result<()> { 82 fn measure_analysis_stats_path(&mut self, name: &str, path: &str) -> Result<()> {
80 eprintln!("\nMeasuring analysis-stats/{}", name); 83 eprintln!("\nMeasuring analysis-stats/{}", name);
81 let output = run!("./target/release/rust-analyzer analysis-stats --quiet {}", path)?; 84 let output = cmd!("./target/release/rust-analyzer analysis-stats --quiet {path}").read()?;
82 for (metric, value, unit) in parse_metrics(&output) { 85 for (metric, value, unit) in parse_metrics(&output) {
83 self.report(&format!("analysis-stats/{}/{}", name, metric), value, unit.into()); 86 self.report(&format!("analysis-stats/{}/{}", name, metric), value, unit.into());
84 } 87 }
@@ -118,7 +121,7 @@ impl Metrics {
118 fn new() -> Result<Metrics> { 121 fn new() -> Result<Metrics> {
119 let host = Host::new()?; 122 let host = Host::new()?;
120 let timestamp = SystemTime::now(); 123 let timestamp = SystemTime::now();
121 let revision = run!("git rev-parse HEAD")?; 124 let revision = cmd!("git rev-parse HEAD").read()?;
122 Ok(Metrics { host, timestamp, revision, metrics: BTreeMap::new() }) 125 Ok(Metrics { host, timestamp, revision, metrics: BTreeMap::new() })
123 } 126 }
124 127
@@ -160,7 +163,7 @@ impl Host {
160 return Ok(Host { os, cpu, mem }); 163 return Ok(Host { os, cpu, mem });
161 164
162 fn read_field<'a>(path: &str, field: &str) -> Result<String> { 165 fn read_field<'a>(path: &str, field: &str) -> Result<String> {
163 let text = fs2::read_to_string(path)?; 166 let text = read_file(path)?;
164 167
165 let line = text 168 let line = text
166 .lines() 169 .lines()