Skip to content

Commit f15e026

Browse files
committed
ci(metrics): Run measurement functions in parallel
feat(xtask): Split metrics function
1 parent d567091 commit f15e026

File tree

3 files changed

+292
-47
lines changed

3 files changed

+292
-47
lines changed

.github/workflows/metrics.yaml

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

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

1835
steps:
1936
- name: Checkout repository
2037
uses: actions/checkout@v3
2138

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

27-
- name: Collect metrics
28-
run: cargo xtask metrics
29-
env:
30-
METRICS_TOKEN: ${{ secrets.METRICS_TOKEN }}
90+
- name: Collect build metrics
91+
run: cargo xtask metrics self
92+
93+
- name: Upload build metrics
94+
uses: actions/upload-artifact@v3
95+
with:
96+
name: self-${{ github.sha }}
97+
path: target/self.json
98+
if-no-files-found: error
99+
100+
ripgrep_metrics:
101+
runs-on: ubuntu-latest
102+
needs: [setup_cargo, build_metrics]
103+
104+
steps:
105+
- name: Checkout repository
106+
uses: actions/checkout@v3
107+
108+
- name: Restore cargo cache
109+
uses: actions/cache@v3
110+
with:
111+
path: |
112+
~/.cargo/bin/
113+
~/.cargo/registry/index/
114+
~/.cargo/registry/cache/
115+
~/.cargo/git/db/
116+
key: ${{ runner.os }}-cargo-${{ github.sha }}
117+
118+
- name: Restore target cache
119+
uses: actions/cache@v3
120+
with:
121+
path: target/
122+
key: ${{ runner.os }}-target-${{ github.sha }}
123+
124+
- name: Collect build metrics
125+
run: cargo xtask metrics ripgrep
126+
127+
- name: Upload ripgrep metrics
128+
uses: actions/upload-artifact@v3
129+
with:
130+
name: ripgrep-${{ github.sha }}
131+
path: target/ripgrep.json
132+
if-no-files-found: error
133+
134+
webrender_metrics:
135+
runs-on: ubuntu-latest
136+
needs: [setup_cargo, build_metrics]
137+
138+
steps:
139+
- name: Checkout repository
140+
uses: actions/checkout@v3
141+
142+
- name: Restore cargo cache
143+
uses: actions/cache@v3
144+
with:
145+
path: |
146+
~/.cargo/bin/
147+
~/.cargo/registry/index/
148+
~/.cargo/registry/cache/
149+
~/.cargo/git/db/
150+
key: ${{ runner.os }}-cargo-${{ github.sha }}
151+
152+
- name: Restore target cache
153+
uses: actions/cache@v3
154+
with:
155+
path: target/
156+
key: ${{ runner.os }}-target-${{ github.sha }}
157+
158+
- name: Collect webrender metrics
159+
run: cargo xtask metrics webrender
160+
161+
- name: Upload webrender metrics
162+
uses: actions/upload-artifact@v3
163+
with:
164+
name: webrender-${{ github.sha }}
165+
path: target/webrender.json
166+
if-no-files-found: error
167+
168+
diesel_metrics:
169+
runs-on: ubuntu-latest
170+
needs: [setup_cargo, build_metrics]
171+
172+
steps:
173+
- name: Checkout repository
174+
uses: actions/checkout@v3
175+
176+
- name: Restore cargo cache
177+
uses: actions/cache@v3
178+
with:
179+
path: |
180+
~/.cargo/bin/
181+
~/.cargo/registry/index/
182+
~/.cargo/registry/cache/
183+
~/.cargo/git/db/
184+
key: ${{ runner.os }}-cargo-${{ github.sha }}
185+
186+
- name: Restore target cache
187+
uses: actions/cache@v3
188+
with:
189+
path: target/
190+
key: ${{ runner.os }}-target-${{ github.sha }}
191+
192+
- name: Collect build metrics
193+
run: cargo xtask metrics diesel
194+
195+
- name: Upload build metrics
196+
uses: actions/upload-artifact@v3
197+
with:
198+
name: diesel-${{ github.sha }}
199+
path: target/diesel.json
200+
if-no-files-found: error
201+
202+
203+
204+
generate_final_metrics:
205+
runs-on: ubuntu-latest
206+
needs: [build_metrics, self_metrics, ripgrep_metrics, webrender_metrics, diesel_metrics]
207+
steps:
208+
- name: Checkout repository
209+
uses: actions/checkout@v3
210+
211+
- name: Download build metrics
212+
uses: actions/download-artifact@v3
213+
with:
214+
name: build-${{ github.sha }}
215+
216+
- name: Download self metrics
217+
uses: actions/download-artifact@v3
218+
with:
219+
name: self-${{ github.sha }}
220+
221+
- name: Download ripgrep metrics
222+
uses: actions/download-artifact@v3
223+
with:
224+
name: ripgrep-${{ github.sha }}
225+
226+
- name: Download webrender metrics
227+
uses: actions/download-artifact@v3
228+
with:
229+
name: webrender-${{ github.sha }}
230+
231+
- name: Download diesel metrics
232+
uses: actions/download-artifact@v3
233+
with:
234+
name: diesel-${{ github.sha }}
235+
236+
- name: Combine json
237+
run: |
238+
git clone --depth 1 https://$METRICS_TOKEN@github.com/nanthR/metrics.git
239+
jq -s ".[0] * .[1] * .[2] * .[3] * .[4]" build.json self.json ripgrep.json webrender.json diesel.json -c >> metrics/metrics.json
240+
git -C metrics add .
241+
git -C metrics -c user.name=Bot -c user.email=dummy@example.com commit --message 📈
242+
git -C metrics push origin master
243+
env:
244+
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+
AnalyseSelf,
114+
AnalyseRipgrep,
115+
AnalyseWebRender,
116+
AnalyseDiesel,
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::AnalyseSelf),
125+
"ripgrep" => Ok(Self::AnalyseRipgrep),
126+
"webrender" => Ok(Self::AnalyseWebRender),
127+
"diesel" => Ok(Self::AnalyseDiesel),
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::AnalyseSelf => {
39+
metrics.measure_analysis_stats_self(sh)?;
40+
"self.json"
41+
}
42+
MeasurementType::AnalyseRipgrep => {
43+
metrics.measure_analysis_stats(sh, "ripgrep")?;
44+
"ripgrep.json"
45+
}
46+
MeasurementType::AnalyseWebRender => {
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::AnalyseDiesel => {
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 user.email=dummy@example.com 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)