Skip to content

Commit f469ef7

Browse files
Merge pull request #717 from Mark-Simulacrum/assert-single-build
Assert that we invoke rustc once per statistics run
2 parents be31ac4 + 6a205a4 commit f469ef7

File tree

22 files changed

+83
-85
lines changed

22 files changed

+83
-85
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,20 @@ jobs:
3434
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/deploy'
3535

3636
test_benchmarks:
37+
strategy:
38+
matrix:
39+
BENCH_INCLUDE_EXCLUDE_OPTS: [
40+
"--exclude script-servo,webrender-wrench,style-servo",
41+
"--include webrender-wrench,style-servo",
42+
"--include script-servo",
43+
]
44+
BUILD_KINDS: [
45+
"Check,Doc",
46+
"Debug",
47+
"Opt",
48+
]
3749
name: Test benchmarks
3850
runs-on: ubuntu-latest
39-
steps:
40-
- name: Checkout the source code
41-
uses: actions/checkout@v2
42-
with:
43-
fetch-depth: 1
44-
45-
- name: Install latest beta
46-
uses: actions-rs/toolchain@v1
47-
with:
48-
toolchain: beta
49-
override: true
50-
51-
- name: Configure environment
52-
run: |
53-
sudo apt-get update
54-
sudo apt-get install -y linux-tools-common linux-tools-generic linux-tools-`uname -r`
55-
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
56-
57-
- name: Build collector
58-
run: cargo build -p collector
59-
60-
- name: Check benchmarks
61-
run: sh -x -c "ci/check-benchmarks.sh"
62-
env:
63-
BENCH_INCLUDE_EXCLUDE_OPTS: "--exclude script-servo"
64-
65-
test_script_servo:
66-
name: Test benchmark script-servo
67-
runs-on: ubuntu-latest
6851
steps:
6952
- name: Checkout the source code
7053
uses: actions/checkout@v2
@@ -84,15 +67,17 @@ jobs:
8467
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
8568
8669
- name: Install servo dependencies
87-
run: sudo apt-get install -y llvm-dev clang libx11-dev python2.7 autoconf2.13
70+
run: sudo apt-get install -y llvm-dev clang libx11-dev python2.7 autoconf2.13 libjemalloc-dev
8871

8972
- name: Build collector
9073
run: cargo build -p collector
9174

9275
- name: Check benchmarks
9376
run: sh -x -c "ci/check-benchmarks.sh"
9477
env:
95-
BENCH_INCLUDE_EXCLUDE_OPTS: "--include script-servo"
78+
JEMALLOC_OVERRIDE: /usr/lib/x86_64-linux-gnu/libjemalloc.so
79+
BENCH_INCLUDE_EXCLUDE_OPTS: ${{ matrix.BENCH_INCLUDE_EXCLUDE_OPTS }}
80+
BUILD_KINDS: ${{ matrix.BUILD_KINDS }}
9681
SHELL: "/bin/bash"
9782

9883
test_profiling:

ci/check-benchmarks.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ PING_LOOP_PID=$!
77
trap 'kill $PING_LOOP_PID' ERR 1 2 3 6
88

99
# Install a toolchain.
10-
RUST_BACKTRACE=1 RUST_LOG=collector_raw_cargo=trace,collector=debug,rust_sysroot=debug \
10+
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
1111
bindir=`cargo run -p collector --bin collector install_next`
1212

1313
# Do some benchmarking.
14-
RUST_BACKTRACE=1 RUST_LOG=collector_raw_cargo=trace,collector=debug,rust_sysroot=debug \
14+
RUST_BACKTRACE=1 \
15+
RUST_LIB_BACKTRACE=0 \
16+
CARGO_LOG=cargo::core::compiler::fingerprint=info \
17+
RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
1518
cargo run -p collector --bin collector -- \
1619
bench_local $bindir/rustc Test \
17-
--builds Check,Doc \
20+
--builds $BUILD_KINDS \
1821
--cargo $bindir/cargo \
1922
--runs All \
2023
--rustdoc $bindir/rustdoc \

ci/check-profiling.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ PING_LOOP_PID=$!
1010
trap 'kill $PING_LOOP_PID' ERR 1 2 3 6
1111

1212
# Install a toolchain.
13-
RUST_BACKTRACE=1 RUST_LOG=collector_raw_cargo=trace,collector=debug,rust_sysroot=debug \
13+
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
1414
bindir=`cargo run -p collector --bin collector install_next`
1515

1616
# Profile with eprintln.
17-
RUST_BACKTRACE=1 RUST_LOG=collector_raw_cargo=trace,collector=debug,rust_sysroot=debug \
17+
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
1818
cargo run -p collector --bin collector -- \
1919
profile_local eprintln $bindir/rustc Test \
2020
--cargo $bindir/cargo \
@@ -29,7 +29,7 @@ test -f results/eprintln-Test-helloworld-Opt-Full
2929
test ! -e results/eprintln-Test-helloworld-Doc-Full
3030

3131
# Profile with llvm-lines.
32-
RUST_BACKTRACE=1 RUST_LOG=collector_raw_cargo=trace,collector=debug,rust_sysroot=debug \
32+
RUST_BACKTRACE=1 RUST_LOG=raw_cargo_messages=trace,collector=debug,rust_sysroot=debug \
3333
cargo run -p collector --bin collector -- \
3434
profile_local llvm-lines $bindir/rustc Test \
3535
--builds Debug \
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"cargo_opts": "--lib",
3-
"runs": 1
3+
"runs": 1,
4+
"touch_file": "src/cargo/lib.rs"
45
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"supports_stable": true
2+
"supports_stable": true,
3+
"touch_file": "src/lib.rs"
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"supports_stable": true
2+
"supports_stable": true,
3+
"touch_file": "src/lib.rs"
34
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"touch_file": "src/lib.rs"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"touch_file": "src/lib.rs"
3+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"supports_stable": true
2+
"supports_stable": true,
3+
"touch_file": "src/lib.rs"
34
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"touch_file": "src/main.rs"
3+
}

collector/benchmarks/style-servo/components/style/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ fn generate_properties() {
6363
let entry = entry.unwrap();
6464
match entry.path().extension().and_then(|e| e.to_str()) {
6565
Some("mako") | Some("rs") | Some("py") | Some("zip") => {
66-
println!("cargo:rerun-if-changed={}", entry.path().display());
6766
}
6867
_ => {}
6968
}
@@ -85,7 +84,6 @@ fn generate_properties() {
8584

8685
fn main() {
8786
println!("cargo:rerun-if-changed=build.rs");
88-
println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap());
8987
generate_properties();
9088
build_gecko::generate();
9189
}

collector/benchmarks/style-servo/components/style/build_gecko.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ mod bindings {
4848
const BINDINGS_FILE: &'static str = "bindings.rs";
4949

5050
fn read_config(path: &PathBuf) -> toml::Table {
51-
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
5251
update_last_modified(&path);
5352

5453
let mut contents = String::new();
@@ -143,7 +142,6 @@ mod bindings {
143142
let mut file = File::open(&path).unwrap();
144143
let mut content = String::new();
145144
file.read_to_string(&mut content).unwrap();
146-
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
147145
added_paths.insert(path);
148146
// Find all includes and add them recursively
149147
for cap in INCLUDE_RE.captures_iter(&content) {
@@ -538,7 +536,6 @@ mod bindings {
538536
fn generate_atoms() {
539537
let script = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
540538
.join("gecko").join("regen_atoms.py");
541-
println!("cargo:rerun-if-changed={}", script.display());
542539
let status = Command::new(&*PYTHON)
543540
.arg(&script)
544541
.arg(DISTDIR_PATH.as_os_str())
@@ -588,17 +585,14 @@ mod bindings {
588585

589586
pub fn generate() {
590587
let dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("gecko/generated");
591-
println!("cargo:rerun-if-changed={}", dir.display());
592588
copy_dir(&dir, &*OUTDIR_PATH, |path| {
593-
println!("cargo:rerun-if-changed={}", path.display());
594589
}).expect("Fail to copy generated files to out dir");
595590
}
596591
}
597592

598593
pub fn generate() {
599594
use self::common::*;
600595
use std::fs;
601-
println!("cargo:rerun-if-changed=build_gecko.rs");
602596
fs::create_dir_all(&*OUTDIR_PATH).unwrap();
603597
bindings::generate();
604598
}

collector/benchmarks/style-servo/components/style/gecko/regen_atoms.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def collect_atoms(objdir):
121121
atoms = []
122122
for source in SOURCES:
123123
path = os.path.abspath(os.path.join(objdir, source.FILE))
124-
print("cargo:rerun-if-changed={}".format(path))
125124
with open(path) as f:
126125
for line in f.readlines():
127126
result = re.match(source.PATTERN, line)
@@ -242,7 +241,6 @@ def write_pseudo_elements(atoms, target_filename):
242241
pseudos.append(atom)
243242

244243
pseudo_definition_template = os.path.join(GECKO_DIR, "pseudo_element_definition.mako.rs")
245-
print("cargo:rerun-if-changed={}".format(pseudo_definition_template))
246244
contents = build.render(pseudo_definition_template, PSEUDOS=pseudos)
247245

248246
with FileAvoidWrite(target_filename) as f:

collector/benchmarks/style-servo/rust-cssparser/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ fn main() {
3636
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
3737
let tokenizer_rs = Path::new(&manifest_dir).join("src/tokenizer.rs");
3838
codegen::main(&tokenizer_rs);
39-
println!("cargo:rerun-if-changed={}", tokenizer_rs.display());
39+
println!("cargo:rerun-if-changed=build.rs");
4040
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"supports_stable": true
2+
"supports_stable": true,
3+
"touch_file": "src/lib.rs"
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"cargo_opts": "--bin token-stream-stress"
2+
"cargo_opts": "--bin token-stream-stress",
3+
"touch_file": "src/main.rs"
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"supports_stable": true
2+
"supports_stable": true,
3+
"touch_file": "src/main.rs"
34
}

collector/benchmarks/webrender-wrench/0002-change-in-dependency.patch

Lines changed: 0 additions & 24 deletions
This file was deleted.

collector/benchmarks/webrender/wrench/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ fn main() {
1111
let out_dir = env::var_os("OUT_DIR").unwrap();
1212
let out_dir = PathBuf::from(out_dir);
1313

14-
println!("cargo:rerun-if-changed=res/wrench.exe.manifest");
1514
if target.contains("windows") {
15+
println!("cargo:rerun-if-changed=res/wrench.exe.manifest");
1616
let src = PathBuf::from("res/wrench.exe.manifest");
1717
let mut dst = out_dir
1818
.parent()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"touch_file": "src/lib.rs"
3+
}

collector/src/execute.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,11 @@ impl<'a> CargoProcess<'a> {
233233
// env vars set, but it doesn't hurt to have them.
234234
.env("RUSTC", &*FAKE_RUSTC)
235235
.env("RUSTC_REAL", &self.compiler.rustc)
236-
.env(
237-
"CARGO_INCREMENTAL",
238-
&format!("{}", self.incremental as usize),
239-
)
236+
// We separately pass -Cincremental to the leaf crate --
237+
// CARGO_INCREMENTAL is cached separately for both the leaf crate
238+
// and any in-tree dependencies, and we don't want that; it wastes
239+
// time.
240+
.env("CARGO_INCREMENTAL", "0")
240241
.current_dir(cwd)
241242
.arg(subcommand)
242243
.arg("--manifest-path")
@@ -258,6 +259,13 @@ impl<'a> CargoProcess<'a> {
258259
}
259260

260261
fn run_rustc(&mut self) -> anyhow::Result<()> {
262+
log::info!(
263+
"run_rustc with incremental={}, run_kind={:?}, patch={:?}",
264+
self.incremental,
265+
self.processor_etc.as_ref().map(|v| v.1),
266+
self.processor_etc.as_ref().and_then(|v| v.3)
267+
);
268+
261269
loop {
262270
// Get the subcommand. If it's not `rustc` it must should be a
263271
// subcommand that itself invokes `rustc` (so that the `FAKE_RUSTC`
@@ -297,7 +305,7 @@ impl<'a> CargoProcess<'a> {
297305
}
298306
}
299307
cmd.args(&self.cargo_args);
300-
if log::log_enabled!(target: "raw_cargo_messages", log::Level::Trace) {
308+
if env::var_os("CARGO_RECORD_TIMING").is_some() {
301309
cmd.arg("-Zunstable-options");
302310
cmd.arg("-Ztimings");
303311
}
@@ -310,6 +318,10 @@ impl<'a> CargoProcess<'a> {
310318
// we want to wrap rustc.
311319
if let Some((ref mut processor, ..)) = self.processor_etc {
312320
let profiler = processor.profiler(self.build_kind).name();
321+
// If we're using a processor, we expect that only the crate
322+
// we're interested in benchmarking will be built, not any
323+
// dependencies.
324+
cmd.env("EXPECT_ONLY_WRAPPED_RUSTC", "1");
313325
cmd.arg("--wrap-rustc-with");
314326
cmd.arg(profiler);
315327
cmd.args(&self.rustc_args);
@@ -335,6 +347,13 @@ impl<'a> CargoProcess<'a> {
335347
}
336348
}
337349

350+
if self.incremental {
351+
cmd.arg("-C");
352+
let mut incr_arg = std::ffi::OsString::from("incremental=");
353+
incr_arg.push(self.cwd.join("incremental-state"));
354+
cmd.arg(incr_arg);
355+
}
356+
338357
log::debug!("{:?}", cmd);
339358

340359
let output = command_output(&mut cmd)?;

collector/src/rustc-fake.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ fn main() {
215215
}
216216
}
217217
} else {
218+
if env::var_os("EXPECT_ONLY_WRAPPED_RUSTC").is_some() {
219+
eprintln!("{:?} {:?}", tool, args);
220+
eprintln!("exiting -- non-wrapped rustc");
221+
std::process::exit(1);
222+
}
223+
218224
let mut cmd = Command::new(&tool);
219225
cmd.args(&args);
220226
exec(&mut cmd);

0 commit comments

Comments
 (0)