Skip to content

Commit 2f20131

Browse files
authored
Merge pull request #1697 from Kobzol/codegen-diff
Runtime benchmark codegen diff
2 parents 57def45 + cc0100d commit 2f20131

File tree

10 files changed

+403
-12
lines changed

10 files changed

+403
-12
lines changed

Cargo.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ rayon = "1.5.2"
3535
cargo_metadata = "0.15.0"
3636
thousands = "0.2.0"
3737
rustc-demangle = { version = "0.1", features = ["std"] }
38+
similar = "2.2"
39+
console = "0.15"
3840

3941
benchlib = { path = "benchlib" }
4042

collector/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,16 @@ It is also possible to profile runtime benchmarks using the following command:
490490
Currently, a `<PROFILER>` can be `cachegrind`, which will run the runtime benchmark under
491491
`Cachegrind`.
492492

493+
## Codegen diff
494+
You can use the `codegen_diff` command to display the assembly, LLVM IR or MIR difference between two
495+
versions of `rustc` for individual functions of a single runtime benchmark group:
496+
497+
```
498+
./target/release/collector codegen_diff <asm|asm-source|llvm|mir> <benchmark-name> <rustc> <rustc2>
499+
```
500+
501+
Codegen diff is currently only implemented for runtime benchmarks.
502+
493503
## How `rustc` wrapping works
494504
When a crate is benchmarked or profiled, the real `rustc` is replaced with the `rustc-fake` binary,
495505
which parses commands passed from the `collector` and invokes the actual profiling or benchmarking

collector/runtime-benchmarks/raytracer/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/runtime-benchmarks/raytracer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "raytrace"
2+
name = "raytracer-bench"
33
version = "0.1.0"
44
authors = ["Jason Orendorff <[email protected]>"]
55
edition = "2021"

collector/src/bin/collector.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use anyhow::Context;
44
use clap::builder::{PossibleValue, TypedValueParser};
55
use clap::{Arg, Parser, ValueEnum};
66
use collector::api::next_artifact::NextArtifact;
7+
use collector::codegen::{codegen_diff, CodegenType};
78
use collector::compile::benchmark::category::Category;
89
use collector::compile::benchmark::profile::Profile;
910
use collector::compile::benchmark::scenario::Scenario;
@@ -31,9 +32,9 @@ use tokio::runtime::Runtime;
3132
use collector::compile::execute::bencher::BenchProcessor;
3233
use collector::compile::execute::profiler::{ProfileProcessor, Profiler};
3334
use collector::runtime::{
34-
bench_runtime, prepare_runtime_benchmark_suite, runtime_benchmark_dir, BenchmarkFilter,
35-
BenchmarkSuite, BenchmarkSuiteCompilation, CargoIsolationMode, RuntimeProfiler,
36-
DEFAULT_RUNTIME_ITERATIONS,
35+
bench_runtime, get_runtime_benchmark_groups, prepare_runtime_benchmark_suite,
36+
runtime_benchmark_dir, BenchmarkFilter, BenchmarkSuite, BenchmarkSuiteCompilation,
37+
CargoIsolationMode, RuntimeProfiler, DEFAULT_RUNTIME_ITERATIONS,
3738
};
3839
use collector::runtime::{profile_runtime, RuntimeCompilationOpts};
3940
use collector::toolchain::{
@@ -452,6 +453,21 @@ enum Commands {
452453
benchmark: String,
453454
},
454455

456+
/// Displays the diff between assembly, LLVM or MIR for a runtime benchmark group.
457+
CodegenDiff {
458+
/// Profiler to use
459+
codegen_type: CodegenType,
460+
461+
/// Runtime benchmark group to diff (name of a directory in `collector/runtime-benchmarks`)
462+
group: String,
463+
464+
/// The path to the local rustc used to compile the runtime benchmark
465+
rustc1: String,
466+
467+
/// The path to a second rustc used to compile with the baseline
468+
rustc2: String,
469+
},
470+
455471
/// Benchmarks a local rustc
456472
BenchLocal {
457473
#[command(flatten)]
@@ -659,7 +675,7 @@ fn main_result() -> anyhow::Result<i32> {
659675
// generated profiles.
660676
RuntimeCompilationOpts::default().debug_info("1"),
661677
)?
662-
.suite;
678+
.extract_suite();
663679
Ok::<_, anyhow::Error>((toolchain, suite))
664680
};
665681

@@ -692,6 +708,37 @@ fn main_result() -> anyhow::Result<i32> {
692708

693709
Ok(0)
694710
}
711+
Commands::CodegenDiff {
712+
codegen_type,
713+
group,
714+
rustc1: rustc,
715+
rustc2,
716+
} => {
717+
let get_toolchain = |rustc: &str, id: &str| {
718+
let toolchain = get_local_toolchain(
719+
&[Profile::Opt],
720+
rustc,
721+
None,
722+
None,
723+
None,
724+
id,
725+
target_triple.clone(),
726+
)?;
727+
Ok::<_, anyhow::Error>(toolchain)
728+
};
729+
730+
let toolchain1 = get_toolchain(&rustc, "1")?;
731+
let toolchain2 = get_toolchain(&rustc2, "2")?;
732+
733+
let mut benchmark_groups =
734+
get_runtime_benchmark_groups(&runtime_benchmark_dir, Some(group))?;
735+
let group = benchmark_groups.pop().unwrap();
736+
assert!(benchmark_groups.is_empty());
737+
738+
codegen_diff(codegen_type, toolchain1, toolchain2, group)?;
739+
Ok(0)
740+
}
741+
695742
Commands::BenchLocal {
696743
local,
697744
opts,

0 commit comments

Comments
 (0)