Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--.github/workflows/metrics.yaml131
-rw-r--r--xtask/src/flags.rs29
-rw-r--r--xtask/src/metrics.rs76
3 files changed, 191 insertions, 45 deletions
diff --git a/.github/workflows/metrics.yaml b/.github/workflows/metrics.yaml
index 3fe2fc917a..37603d6ff6 100644
--- a/.github/workflows/metrics.yaml
+++ b/.github/workflows/metrics.yaml
@@ -11,20 +11,135 @@ env:
RUSTUP_MAX_RETRIES: 10
jobs:
- metrics:
+ setup_cargo:
if: github.repository == 'rust-lang/rust-analyzer'
runs-on: ubuntu-latest
+ steps:
+ - name: Install Rust toolchain
+ run: |
+ rustup update --no-self-update stable
+ rustup component add rustfmt rust-src
+ - name: Cache cargo
+ uses: actions/cache@v3
+ with:
+ path: |
+ ~/.cargo/bin/
+ ~/.cargo/registry/index/
+ ~/.cargo/registry/cache/
+ ~/.cargo/git/db/
+ key: ${{ runner.os }}-cargo-${{ github.sha }}
+
+ build_metrics:
+ runs-on: ubuntu-latest
+ needs: setup_cargo
steps:
- name: Checkout repository
uses: actions/checkout@v3
- - name: Install Rust toolchain
- run: |
- rustup update --no-self-update stable
- rustup component add rustfmt rust-src
+ - name: Restore cargo cache
+ uses: actions/cache@v3
+ with:
+ path: |
+ ~/.cargo/bin/
+ ~/.cargo/registry/index/
+ ~/.cargo/registry/cache/
+ ~/.cargo/git/db/
+ key: ${{ runner.os }}-cargo-${{ github.sha }}
+
+
+ - name: Collect build metrics
+ run: cargo xtask metrics build
+
+ - name: Cache target
+ uses: actions/cache@v3
+ with:
+ path: target/
+ key: ${{ runner.os }}-target-${{ github.sha }}
+
+ - name: Upload build metrics
+ uses: actions/upload-artifact@v3
+ with:
+ name: build-${{ github.sha }}
+ path: target/build.json
+ if-no-files-found: error
+
+ other_metrics:
+ strategy:
+ matrix:
+ names: [self, ripgrep, webrender, diesel]
+ runs-on: ubuntu-latest
+ needs: [setup_cargo, build_metrics]
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ - name: Restore cargo cache
+ uses: actions/cache@v3
+ with:
+ path: |
+ ~/.cargo/bin/
+ ~/.cargo/registry/index/
+ ~/.cargo/registry/cache/
+ ~/.cargo/git/db/
+ key: ${{ runner.os }}-cargo-${{ github.sha }}
+
+ - name: Restore target cache
+ uses: actions/cache@v3
+ with:
+ path: target/
+ key: ${{ runner.os }}-target-${{ github.sha }}
- name: Collect metrics
- run: cargo xtask metrics
- env:
- METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
+ run: cargo xtask metrics ${{ matrix.names }}
+
+ - name: Upload metrics
+ uses: actions/upload-artifact@v3
+ with:
+ name: ${{ matrix.names }}-${{ github.sha }}
+ path: target/${{ matrix.names }}.json
+ if-no-files-found: error
+
+ generate_final_metrics:
+ runs-on: ubuntu-latest
+ needs: [build_metrics, other_metrics]
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ - name: Download build metrics
+ uses: actions/download-artifact@v3
+ with:
+ name: build-${{ github.sha }}
+
+ - name: Download self metrics
+ uses: actions/download-artifact@v3
+ with:
+ name: self-${{ github.sha }}
+
+ - name: Download ripgrep metrics
+ uses: actions/download-artifact@v3
+ with:
+ name: ripgrep-${{ github.sha }}
+
+ - name: Download webrender metrics
+ uses: actions/download-artifact@v3
+ with:
+ name: webrender-${{ github.sha }}
+
+ - name: Download diesel metrics
+ uses: actions/download-artifact@v3
+ with:
+ name: diesel-${{ github.sha }}
+
+ - name: Combine json
+ run: |
+ git clone --depth 1 https://[email protected]/rust-analyzer/metrics.git
+ jq -s ".[0] * .[1] * .[2] * .[3] * .[4]" build.json self.json ripgrep.json webrender.json diesel.json -c >> metrics/metrics.json
+ cd metrics
+ git add .
+ git -c user.name=Bot -c [email protected] commit --message 📈
+ git push origin new
+ env:
+ METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs
index 2100479701..7720ad69fe 100644
--- a/xtask/src/flags.rs
+++ b/xtask/src/flags.rs
@@ -1,5 +1,7 @@
#![allow(unreachable_pub)]
+use std::str::FromStr;
+
use crate::install::{ClientOpt, Malloc, ServerOpt};
xflags::xflags! {
@@ -42,7 +44,7 @@ xflags::xflags! {
required changelog: String
}
cmd metrics {
- optional --dry-run
+ optional measurement_type: MeasurementType
}
/// Builds a benchmark version of rust-analyzer and puts it into `./target`.
cmd bb {
@@ -106,8 +108,31 @@ pub struct PublishReleaseNotes {
}
#[derive(Debug)]
+pub enum MeasurementType {
+ Build,
+ AnalyzeSelf,
+ AnalyzeRipgrep,
+ AnalyzeWebRender,
+ AnalyzeDiesel,
+}
+
+impl FromStr for MeasurementType {
+ type Err = String;
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "build" => Ok(Self::Build),
+ "self" => Ok(Self::AnalyzeSelf),
+ "ripgrep" => Ok(Self::AnalyzeRipgrep),
+ "webrender" => Ok(Self::AnalyzeWebRender),
+ "diesel" => Ok(Self::AnalyzeDiesel),
+ _ => Err("Invalid option".to_string()),
+ }
+ }
+}
+
+#[derive(Debug)]
pub struct Metrics {
- pub dry_run: bool,
+ pub measurement_type: Option<MeasurementType>,
}
#[derive(Debug)]
diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs
index b6f730dbf1..6853742319 100644
--- a/xtask/src/metrics.rs
+++ b/xtask/src/metrics.rs
@@ -1,6 +1,6 @@
use std::{
collections::BTreeMap,
- env, fs,
+ fs,
io::Write as _,
path::Path,
time::{Instant, SystemTime, UNIX_EPOCH},
@@ -9,16 +9,13 @@ use std::{
use anyhow::{bail, format_err};
use xshell::{cmd, Shell};
-use crate::flags;
+use crate::flags::{self, MeasurementType};
type Unit = String;
impl flags::Metrics {
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
let mut metrics = Metrics::new(sh)?;
- if !self.dry_run {
- sh.remove_path("./target/release")?;
- }
if !Path::new("./target/rustc-perf").exists() {
sh.create_dir("./target/rustc-perf")?;
cmd!(sh, "git clone https://github.com/rust-lang/rustc-perf.git ./target/rustc-perf")
@@ -32,38 +29,47 @@ impl flags::Metrics {
let _env = sh.push_env("RA_METRICS", "1");
- {
- // https://github.com/rust-lang/rust-analyzer/issues/9997
- let _d = sh.push_dir("target/rustc-perf/collector/benchmarks/webrender");
- cmd!(sh, "cargo update -p url --precise 1.6.1").run()?;
- }
- metrics.measure_build(sh)?;
- metrics.measure_analysis_stats_self(sh)?;
- metrics.measure_analysis_stats(sh, "ripgrep")?;
- metrics.measure_analysis_stats(sh, "webrender")?;
- metrics.measure_analysis_stats(sh, "diesel/diesel")?;
-
- if !self.dry_run {
- let _d = sh.push_dir("target");
- let metrics_token = env::var("METRICS_TOKEN").unwrap();
- cmd!(
- sh,
- "git clone --depth 1 https://{metrics_token}@github.com/rust-analyzer/metrics.git"
- )
- .run()?;
-
- {
- let mut file =
- fs::File::options().append(true).open("target/metrics/metrics.json")?;
- writeln!(file, "{}", metrics.json())?;
+ let filename = match self.measurement_type {
+ Some(ms) => match ms {
+ MeasurementType::Build => {
+ metrics.measure_build(sh)?;
+ "build.json"
+ }
+ MeasurementType::AnalyzeSelf => {
+ metrics.measure_analysis_stats_self(sh)?;
+ "self.json"
+ }
+ MeasurementType::AnalyzeRipgrep => {
+ metrics.measure_analysis_stats(sh, "ripgrep")?;
+ "ripgrep.json"
+ }
+ MeasurementType::AnalyzeWebRender => {
+ {
+ // https://github.com/rust-lang/rust-analyzer/issues/9997
+ let _d = sh.push_dir("target/rustc-perf/collector/benchmarks/webrender");
+ cmd!(sh, "cargo update -p url --precise 1.6.1").run()?;
+ }
+ metrics.measure_analysis_stats(sh, "webrender")?;
+ "webrender.json"
+ }
+ MeasurementType::AnalyzeDiesel => {
+ metrics.measure_analysis_stats(sh, "diesel/diesel")?;
+ "diesel.json"
+ }
+ },
+ None => {
+ metrics.measure_build(sh)?;
+ metrics.measure_analysis_stats_self(sh)?;
+ metrics.measure_analysis_stats(sh, "ripgrep")?;
+ metrics.measure_analysis_stats(sh, "webrender")?;
+ metrics.measure_analysis_stats(sh, "diesel/diesel")?;
+ "all.json"
}
+ };
- let _d = sh.push_dir("metrics");
- cmd!(sh, "git add .").run()?;
- cmd!(sh, "git -c user.name=Bot -c [email protected] commit --message 📈")
- .run()?;
- cmd!(sh, "git push origin master").run()?;
- }
+ let mut file =
+ fs::File::options().write(true).create(true).open(format!("target/{}", filename))?;
+ writeln!(file, "{}", metrics.json())?;
eprintln!("{metrics:#?}");
Ok(())
}