Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ac4e046

Browse files
committed
Auto merge of rust-lang#15030 - NanthR:parallel-metrics, r=HKalbasi
ci(metrics): Run measurement functions in parallel Resolves rust-lang#14853
2 parents 4b06d3c + cf34df0 commit ac4e046

File tree

3 files changed

+191
-45
lines changed

3 files changed

+191
-45
lines changed

.github/workflows/metrics.yaml

Lines changed: 123 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,135 @@ env:
1111
RUSTUP_MAX_RETRIES: 10
1212

1313
jobs:
14-
metrics:
14+
setup_cargo:
1515
if: github.repository == 'rust-lang/rust-analyzer'
1616
runs-on: ubuntu-latest
17+
steps:
18+
- name: Install Rust toolchain
19+
run: |
20+
rustup update --no-self-update stable
21+
rustup component add rustfmt rust-src
22+
- name: Cache cargo
23+
uses: actions/cache@v3
24+
with:
25+
path: |
26+
~/.cargo/bin/
27+
~/.cargo/registry/index/
28+
~/.cargo/registry/cache/
29+
~/.cargo/git/db/
30+
key: ${{ runner.os }}-cargo-${{ github.sha }}
31+
32+
build_metrics:
33+
runs-on: ubuntu-latest
34+
needs: setup_cargo
1735

1836
steps:
1937
- name: Checkout repository
2038
uses: actions/checkout@v3
2139

22-
- name: Install Rust toolchain
23-
run: |
24-
rustup update --no-self-update stable
25-
rustup component add rustfmt rust-src
40+
- name: Restore cargo cache
41+
uses: actions/cache@v3
42+
with:
43+
path: |
44+
~/.cargo/bin/
45+
~/.cargo/registry/index/
46+
~/.cargo/registry/cache/
47+
~/.cargo/git/db/
48+
key: ${{ runner.os }}-cargo-${{ github.sha }}
49+
50+
51+
- name: Collect build metrics
52+
run: cargo xtask metrics build
53+
54+
- name: Cache target
55+
uses: actions/cache@v3
56+
with:
57+
path: target/
58+
key: ${{ runner.os }}-target-${{ github.sha }}
59+
60+
- name: Upload build metrics
61+
uses: actions/upload-artifact@v3
62+
with:
63+
name: build-${{ github.sha }}
64+
path: target/build.json
65+
if-no-files-found: error
66+
67+
other_metrics:
68+
strategy:
69+
matrix:
70+
names: [self, ripgrep, webrender, diesel]
71+
runs-on: ubuntu-latest
72+
needs: [setup_cargo, build_metrics]
73+
74+
steps:
75+
- name: Checkout repository
76+
uses: actions/checkout@v3
77+
78+
- name: Restore cargo cache
79+
uses: actions/cache@v3
80+
with:
81+
path: |
82+
~/.cargo/bin/
83+
~/.cargo/registry/index/
84+
~/.cargo/registry/cache/
85+
~/.cargo/git/db/
86+
key: ${{ runner.os }}-cargo-${{ github.sha }}
87+
88+
- name: Restore target cache
89+
uses: actions/cache@v3
90+
with:
91+
path: target/
92+
key: ${{ runner.os }}-target-${{ github.sha }}
2693

2794
- name: Collect metrics
28-
run: cargo xtask metrics
29-
env:
30-
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
95+
run: cargo xtask metrics ${{ matrix.names }}
96+
97+
- name: Upload metrics
98+
uses: actions/upload-artifact@v3
99+
with:
100+
name: ${{ matrix.names }}-${{ github.sha }}
101+
path: target/${{ matrix.names }}.json
102+
if-no-files-found: error
103+
104+
generate_final_metrics:
105+
runs-on: ubuntu-latest
106+
needs: [build_metrics, other_metrics]
107+
steps:
108+
- name: Checkout repository
109+
uses: actions/checkout@v3
110+
111+
- name: Download build metrics
112+
uses: actions/download-artifact@v3
113+
with:
114+
name: build-${{ github.sha }}
115+
116+
- name: Download self metrics
117+
uses: actions/download-artifact@v3
118+
with:
119+
name: self-${{ github.sha }}
120+
121+
- name: Download ripgrep metrics
122+
uses: actions/download-artifact@v3
123+
with:
124+
name: ripgrep-${{ github.sha }}
125+
126+
- name: Download webrender metrics
127+
uses: actions/download-artifact@v3
128+
with:
129+
name: webrender-${{ github.sha }}
130+
131+
- name: Download diesel metrics
132+
uses: actions/download-artifact@v3
133+
with:
134+
name: diesel-${{ github.sha }}
135+
136+
- name: Combine json
137+
run: |
138+
git clone --depth 1 https://[email protected]/rust-analyzer/metrics.git
139+
jq -s ".[0] * .[1] * .[2] * .[3] * .[4]" build.json self.json ripgrep.json webrender.json diesel.json -c >> metrics/metrics.json
140+
cd metrics
141+
git add .
142+
git -c user.name=Bot -c [email protected] commit --message 📈
143+
git push origin new
144+
env:
145+
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}

xtask/src/flags.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(unreachable_pub)]
22

3+
use std::str::FromStr;
4+
35
use crate::install::{ClientOpt, Malloc, ServerOpt};
46

57
xflags::xflags! {
@@ -42,7 +44,7 @@ xflags::xflags! {
4244
required changelog: String
4345
}
4446
cmd metrics {
45-
optional --dry-run
47+
optional measurement_type: MeasurementType
4648
}
4749
/// Builds a benchmark version of rust-analyzer and puts it into `./target`.
4850
cmd bb {
@@ -105,9 +107,32 @@ pub struct PublishReleaseNotes {
105107
pub dry_run: bool,
106108
}
107109

110+
#[derive(Debug)]
111+
pub enum MeasurementType {
112+
Build,
113+
AnalyzeSelf,
114+
AnalyzeRipgrep,
115+
AnalyzeWebRender,
116+
AnalyzeDiesel,
117+
}
118+
119+
impl FromStr for MeasurementType {
120+
type Err = String;
121+
fn from_str(s: &str) -> Result<Self, Self::Err> {
122+
match s {
123+
"build" => Ok(Self::Build),
124+
"self" => Ok(Self::AnalyzeSelf),
125+
"ripgrep" => Ok(Self::AnalyzeRipgrep),
126+
"webrender" => Ok(Self::AnalyzeWebRender),
127+
"diesel" => Ok(Self::AnalyzeDiesel),
128+
_ => Err("Invalid option".to_string()),
129+
}
130+
}
131+
}
132+
108133
#[derive(Debug)]
109134
pub struct Metrics {
110-
pub dry_run: bool,
135+
pub measurement_type: Option<MeasurementType>,
111136
}
112137

113138
#[derive(Debug)]

xtask/src/metrics.rs

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
collections::BTreeMap,
3-
env, fs,
3+
fs,
44
io::Write as _,
55
path::Path,
66
time::{Instant, SystemTime, UNIX_EPOCH},
@@ -9,16 +9,13 @@ use std::{
99
use anyhow::{bail, format_err};
1010
use xshell::{cmd, Shell};
1111

12-
use crate::flags;
12+
use crate::flags::{self, MeasurementType};
1313

1414
type Unit = String;
1515

1616
impl flags::Metrics {
1717
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
1818
let mut metrics = Metrics::new(sh)?;
19-
if !self.dry_run {
20-
sh.remove_path("./target/release")?;
21-
}
2219
if !Path::new("./target/rustc-perf").exists() {
2320
sh.create_dir("./target/rustc-perf")?;
2421
cmd!(sh, "git clone https://github.com/rust-lang/rustc-perf.git ./target/rustc-perf")
@@ -32,38 +29,47 @@ impl flags::Metrics {
3229

3330
let _env = sh.push_env("RA_METRICS", "1");
3431

35-
{
36-
// https://github.com/rust-lang/rust-analyzer/issues/9997
37-
let _d = sh.push_dir("target/rustc-perf/collector/benchmarks/webrender");
38-
cmd!(sh, "cargo update -p url --precise 1.6.1").run()?;
39-
}
40-
metrics.measure_build(sh)?;
41-
metrics.measure_analysis_stats_self(sh)?;
42-
metrics.measure_analysis_stats(sh, "ripgrep")?;
43-
metrics.measure_analysis_stats(sh, "webrender")?;
44-
metrics.measure_analysis_stats(sh, "diesel/diesel")?;
45-
46-
if !self.dry_run {
47-
let _d = sh.push_dir("target");
48-
let metrics_token = env::var("METRICS_TOKEN").unwrap();
49-
cmd!(
50-
sh,
51-
"git clone --depth 1 https://{metrics_token}@github.com/rust-analyzer/metrics.git"
52-
)
53-
.run()?;
54-
55-
{
56-
let mut file =
57-
fs::File::options().append(true).open("target/metrics/metrics.json")?;
58-
writeln!(file, "{}", metrics.json())?;
32+
let filename = match self.measurement_type {
33+
Some(ms) => match ms {
34+
MeasurementType::Build => {
35+
metrics.measure_build(sh)?;
36+
"build.json"
37+
}
38+
MeasurementType::AnalyzeSelf => {
39+
metrics.measure_analysis_stats_self(sh)?;
40+
"self.json"
41+
}
42+
MeasurementType::AnalyzeRipgrep => {
43+
metrics.measure_analysis_stats(sh, "ripgrep")?;
44+
"ripgrep.json"
45+
}
46+
MeasurementType::AnalyzeWebRender => {
47+
{
48+
// https://github.com/rust-lang/rust-analyzer/issues/9997
49+
let _d = sh.push_dir("target/rustc-perf/collector/benchmarks/webrender");
50+
cmd!(sh, "cargo update -p url --precise 1.6.1").run()?;
51+
}
52+
metrics.measure_analysis_stats(sh, "webrender")?;
53+
"webrender.json"
54+
}
55+
MeasurementType::AnalyzeDiesel => {
56+
metrics.measure_analysis_stats(sh, "diesel/diesel")?;
57+
"diesel.json"
58+
}
59+
},
60+
None => {
61+
metrics.measure_build(sh)?;
62+
metrics.measure_analysis_stats_self(sh)?;
63+
metrics.measure_analysis_stats(sh, "ripgrep")?;
64+
metrics.measure_analysis_stats(sh, "webrender")?;
65+
metrics.measure_analysis_stats(sh, "diesel/diesel")?;
66+
"all.json"
5967
}
68+
};
6069

61-
let _d = sh.push_dir("metrics");
62-
cmd!(sh, "git add .").run()?;
63-
cmd!(sh, "git -c user.name=Bot -c [email protected] commit --message 📈")
64-
.run()?;
65-
cmd!(sh, "git push origin master").run()?;
66-
}
70+
let mut file =
71+
fs::File::options().write(true).create(true).open(format!("target/{}", filename))?;
72+
writeln!(file, "{}", metrics.json())?;
6773
eprintln!("{metrics:#?}");
6874
Ok(())
6975
}

0 commit comments

Comments
 (0)