Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(metrics): Run measurement functions in parallel #15030

Merged
merged 5 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
234 changes: 224 additions & 10 deletions .github/workflows/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,234 @@ env:
RUSTUP_MAX_RETRIES: 10

jobs:
metrics:
if: github.repository == 'rust-lang/rust-analyzer'
setup_cargo:
runs-on: ubuntu-latest
HKalbasi marked this conversation as resolved.
Show resolved Hide resolved
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

self_metrics:
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 }}
- name: Collect build metrics
run: cargo xtask metrics self

- name: Upload build metrics
uses: actions/upload-artifact@v3
with:
name: self-${{ github.sha }}
path: target/self.json
if-no-files-found: error

ripgrep_metrics:
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 build metrics
run: cargo xtask metrics ripgrep
HKalbasi marked this conversation as resolved.
Show resolved Hide resolved

- name: Upload ripgrep metrics
uses: actions/upload-artifact@v3
with:
name: ripgrep-${{ github.sha }}
path: target/ripgrep.json
if-no-files-found: error

webrender_metrics:
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 webrender metrics
run: cargo xtask metrics webrender

- name: Upload webrender metrics
uses: actions/upload-artifact@v3
with:
name: webrender-${{ github.sha }}
path: target/webrender.json
if-no-files-found: error

diesel_metrics:
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 build metrics
run: cargo xtask metrics diesel

- name: Upload build metrics
uses: actions/upload-artifact@v3
with:
name: diesel-${{ github.sha }}
path: target/diesel.json
if-no-files-found: error



generate_final_metrics:
runs-on: ubuntu-latest
needs: [build_metrics, self_metrics, ripgrep_metrics, webrender_metrics, diesel_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://$METRICS_TOKEN@github.com/nanthR/metrics.git
NanthR marked this conversation as resolved.
Show resolved Hide resolved
jq -s ".[0] * .[1] * .[2] * .[3] * .[4]" build.json self.json ripgrep.json webrender.json diesel.json -c >> metrics/metrics.json
git -C metrics add .
git -C metrics -c user.name=Bot -c user.email=dummy@example.com commit --message 📈
git -C metrics push origin master
env:
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
29 changes: 27 additions & 2 deletions xtask/src/flags.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(unreachable_pub)]

use std::str::FromStr;

use crate::install::{ClientOpt, Malloc, ServerOpt};

xflags::xflags! {
Expand Down Expand Up @@ -42,7 +44,7 @@ xflags::xflags! {
required changelog: String
}
cmd metrics {
optional --dry-run
HKalbasi marked this conversation as resolved.
Show resolved Hide resolved
optional measurement_type: MeasurementType
}
/// Builds a benchmark version of rust-analyzer and puts it into `./target`.
cmd bb {
Expand Down Expand Up @@ -105,9 +107,32 @@ pub struct PublishReleaseNotes {
pub dry_run: bool,
}

#[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)]
Expand Down
76 changes: 41 additions & 35 deletions xtask/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
collections::BTreeMap,
env, fs,
fs,
io::Write as _,
path::Path,
time::{Instant, SystemTime, UNIX_EPOCH},
Expand All @@ -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")
Expand All @@ -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 user.email=dummy@example.com 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(())
}
Expand Down