Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["The Rust Compiler Team"]
name = "collector"
version = "0.1.0"
edition = "2021"
edition = "2024"
description = "Collects Rust performance data"
rust-version = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion collector/benchlib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "benchlib"
version = "0.1.0"
edition = "2021"
edition = "2024"
description = "Library for defining and measuring benchmarks of Rust code"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion collector/benchlib/src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::{parse_cli, Args, BenchmarkArgs, ProfileArgs};
use crate::cli::{Args, BenchmarkArgs, ProfileArgs, parse_cli};
use crate::comm::messages::{BenchmarkMessage, BenchmarkResult, BenchmarkStats};
use crate::comm::output_message;
use crate::measure::benchmark_function;
Expand Down
41 changes: 20 additions & 21 deletions collector/src/artifact_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ impl ArtifactStats {

let mut stats: Option<Self> = None;
for member in archive.members().flatten() {
if let Ok(name) = std::str::from_utf8(member.name()) {
if name.ends_with(".rcgu.o") {
if let Ok(data) = member.data(&*data) {
let entry_stats = Self::from_bytes(data)
.with_context(|| format!("Cannot parse archive member `{name}`"))?;
stats = match stats {
Some(old_stats) => Some(old_stats.merge(entry_stats)),
None => Some(entry_stats),
};
}
}
if let Ok(name) = std::str::from_utf8(member.name())
&& name.ends_with(".rcgu.o")
&& let Ok(data) = member.data(&*data)
{
let entry_stats = Self::from_bytes(data)
.with_context(|| format!("Cannot parse archive member `{name}`"))?;
stats = match stats {
Some(old_stats) => Some(old_stats.merge(entry_stats)),
None => Some(entry_stats),
};
}
}
Ok(stats.unwrap_or_default())
Expand Down Expand Up @@ -224,16 +223,16 @@ pub fn compile_and_get_stats(
filenames,
..
} = artifact;
if let Some(executable) = executable {
if target.is_bin() {
let stats = ArtifactStats::from_dynamic_object(executable.as_std_path())
.with_context(|| format!("Cannot parse executable stats from {executable}"))?;
archives.push(ArtifactWithStats {
path: executable.into_std_path_buf(),
target_name: target.name.clone(),
stats,
});
}
if let Some(executable) = executable
&& target.is_bin()
{
let stats = ArtifactStats::from_dynamic_object(executable.as_std_path())
.with_context(|| format!("Cannot parse executable stats from {executable}"))?;
archives.push(ArtifactWithStats {
path: executable.into_std_path_buf(),
target_name: target.name.clone(),
stats,
});
}
for library in filenames {
// We only care about local packages
Expand Down
6 changes: 3 additions & 3 deletions collector/src/benchmark_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

mod compile_benchmarks;

use crate::compile::benchmark::target::Target;
use crate::compile::benchmark::BenchmarkName;
use crate::compile::benchmark::target::Target;

/// Represents a single set of master/try benchmarks.
#[derive(Debug)]
Expand Down Expand Up @@ -227,10 +227,10 @@ pub fn get_benchmark_set(id: BenchmarkSetId) -> BenchmarkSet {

#[cfg(test)]
mod tests {
use crate::benchmark_set::{get_benchmark_sets_for_target, BenchmarkSet, BenchmarkSetMember};
use crate::benchmark_set::{BenchmarkSet, BenchmarkSetMember, get_benchmark_sets_for_target};
use crate::compile::benchmark::target::Target;
use crate::compile::benchmark::{
get_compile_benchmarks, BenchmarkName, CompileBenchmarkFilter,
BenchmarkName, CompileBenchmarkFilter, get_compile_benchmarks,
};
use std::collections::HashSet;
use std::path::Path;
Expand Down
6 changes: 1 addition & 5 deletions collector/src/bin/bootstrap-rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ fn run() -> i32 {

let status = cmd.status().expect("spawned");

if status.success() {
0
} else {
1
}
if status.success() { 0 } else { 1 }
}

fn main() {
Expand Down
45 changes: 24 additions & 21 deletions collector/src/bin/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clap::builder::TypedValueParser;
use clap::{Arg, Parser};
use collector::compare::compare_artifacts;
use hashbrown::HashSet;
use humansize::{format_size, BINARY};
use humansize::{BINARY, format_size};
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use std::cmp::{Ordering, Reverse};
use std::collections::HashMap;
Expand All @@ -30,37 +30,37 @@ use tabled::settings::{Alignment, Color, Modify, Width};
use tokio::runtime::Runtime;

use collector::artifact_stats::{
compile_and_get_stats, ArtifactStats, ArtifactWithStats, CargoProfile,
ArtifactStats, ArtifactWithStats, CargoProfile, compile_and_get_stats,
};
use collector::benchmark_set::{get_benchmark_set, BenchmarkSetId, BenchmarkSetMember};
use collector::codegen::{codegen_diff, CodegenType};
use collector::benchmark_set::{BenchmarkSetId, BenchmarkSetMember, get_benchmark_set};
use collector::codegen::{CodegenType, codegen_diff};
use collector::compile::benchmark::category::Category;
use collector::compile::benchmark::codegen_backend::CodegenBackend;
use collector::compile::benchmark::frontend_threads::FrontendThreads;
use collector::compile::benchmark::profile::Profile;
use collector::compile::benchmark::scenario::Scenario;
use collector::compile::benchmark::target::Target;
use collector::compile::benchmark::{
compile_benchmark_dir, get_compile_benchmarks, ArtifactType, Benchmark, BenchmarkName,
CompileBenchmarkFilter,
ArtifactType, Benchmark, BenchmarkName, CompileBenchmarkFilter, compile_benchmark_dir,
get_compile_benchmarks,
};
use collector::compile::execute::bencher::BenchProcessor;
use collector::compile::execute::profiler::{ProfileProcessor, Profiler};
use collector::runtime::{
bench_runtime, get_runtime_benchmark_groups, prepare_runtime_benchmark_suite,
runtime_benchmark_dir, BenchmarkSuite, BenchmarkSuiteCompilation, CargoIsolationMode,
RuntimeBenchmarkFilter, RuntimeProfiler, DEFAULT_RUNTIME_ITERATIONS,
BenchmarkSuite, BenchmarkSuiteCompilation, CargoIsolationMode, DEFAULT_RUNTIME_ITERATIONS,
RuntimeBenchmarkFilter, RuntimeProfiler, bench_runtime, get_runtime_benchmark_groups,
prepare_runtime_benchmark_suite, runtime_benchmark_dir,
};
use collector::runtime::{profile_runtime, RuntimeCompilationOpts};
use collector::runtime::{RuntimeCompilationOpts, profile_runtime};
use collector::toolchain::{
create_toolchain_from_published_version, get_local_toolchain, Sysroot, SysrootDownloadError,
Toolchain, ToolchainConfig,
Sysroot, SysrootDownloadError, Toolchain, ToolchainConfig,
create_toolchain_from_published_version, get_local_toolchain,
};
use collector::utils::cachegrind::cachegrind_diff;
use collector::utils::{is_installed, wait_for_future};
use collector::{
command_output, utils, CollectorCtx, CollectorStepBuilder, LocalSelfProfileStorage,
S3SelfProfileStorage, SelfProfileStorage,
CollectorCtx, CollectorStepBuilder, LocalSelfProfileStorage, S3SelfProfileStorage,
SelfProfileStorage, command_output, utils,
};
use database::{
ArtifactId, ArtifactIdNumber, BenchmarkJob, BenchmarkJobConclusion, CollectorConfig, Commit,
Expand Down Expand Up @@ -175,7 +175,10 @@ fn check_measureme_installed() -> Result<(), String> {
if not_installed.is_empty() {
Ok(())
} else {
Err(format!("To run this command you need {0} on your PATH. To install run `cargo install --git https://github.com/rust-lang/measureme --branch stable {0}`\n", not_installed.join(" ")))
Err(format!(
"To run this command you need {0} on your PATH. To install run `cargo install --git https://github.com/rust-lang/measureme --branch stable {0}`\n",
not_installed.join(" ")
))
}
}

Expand Down Expand Up @@ -1621,7 +1624,7 @@ async fn run_benchmark_job(
job.target().as_str(),
job.backend().as_str(),
job.profile().as_str()
)))
)));
}
Err(SysrootDownloadError::IO(error)) => return Err(error.into()),
};
Expand Down Expand Up @@ -2434,11 +2437,11 @@ async fn record_toolchain_sizes(
path: Option<&Path>,
target: database::Target,
) {
if let Some(path) = path {
if let Ok(size) = fs::metadata(path).map(|m| m.len()) {
conn.record_artifact_size(aid, component, size, target)
.await;
}
if let Some(path) = path
&& let Ok(size) = fs::metadata(path).map(|m| m.len())
{
conn.record_artifact_size(aid, component, size, target)
.await;
}
}

Expand Down
4 changes: 3 additions & 1 deletion collector/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ pub fn codegen_diff(
group: BenchmarkGroupCrate,
) -> anyhow::Result<()> {
if !check_cargo_asm() {
return Err(anyhow::anyhow!("`cargo-show-asm` does not seem to be installed. Run `cargo install cargo-show-asm` first."));
return Err(anyhow::anyhow!(
"`cargo-show-asm` does not seem to be installed. Run `cargo install cargo-show-asm` first."
));
}

// List functions and their indices from the baseline compiler
Expand Down
2 changes: 1 addition & 1 deletion collector/src/compare/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Context;
use database::selector::{BenchmarkQuery, CompileBenchmarkQuery, CompileTestCase};
use database::{metric::Metric, ArtifactId, Commit, Connection, Index};
use database::{ArtifactId, Commit, Connection, Index, metric::Metric};
use ratatui::prelude::Stylize;
use ratatui::widgets::{Cell, List, ListState, Paragraph, Row, Table, TableState};
use ratatui::{
Expand Down
12 changes: 6 additions & 6 deletions collector/src/compile/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::compile::benchmark::target::Target;
use crate::compile::execute::{CargoProcess, Processor};
use crate::toolchain::Toolchain;
use crate::utils::wait_for_future;
use anyhow::{bail, Context};
use anyhow::{Context, bail};
use database::selector::CompileTestCase;
use log::debug;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -138,10 +138,10 @@ impl Benchmark {
for entry in std::fs::read_dir(&path)? {
let entry = entry?;
let path = entry.path();
if let Some(ext) = path.extension() {
if ext == "patch" {
patches.push(path.clone());
}
if let Some(ext) = path.extension()
&& ext == "patch"
{
patches.push(path.clone());
}
}

Expand Down Expand Up @@ -814,7 +814,7 @@ fn substring_matches(

#[cfg(test)]
mod tests {
use crate::compile::benchmark::{get_compile_benchmarks, CompileBenchmarkFilter};
use crate::compile::benchmark::{CompileBenchmarkFilter, get_compile_benchmarks};
use std::path::Path;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion collector/src/compile/benchmark/target.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use database::{intern_target_name, TargetName};
use database::{TargetName, intern_target_name};
use std::{fmt, str::FromStr};

/// Target representing an Rust target triple, for a full list of targets and
Expand Down
16 changes: 8 additions & 8 deletions collector/src/compile/execute/bencher.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use crate::compile::benchmark::BenchmarkName;
use crate::compile::benchmark::codegen_backend::CodegenBackend;
use crate::compile::benchmark::profile::Profile;
use crate::compile::benchmark::scenario::Scenario;
use crate::compile::benchmark::target::Target;
use crate::compile::benchmark::BenchmarkName;
use crate::compile::execute;
use crate::compile::execute::{
rustc, DeserializeStatError, PerfTool, ProcessOutputData, Processor, Retry, SelfProfileFiles,
Stats,
DeserializeStatError, PerfTool, ProcessOutputData, Processor, Retry, SelfProfileFiles, Stats,
rustc,
};
use crate::self_profile::SelfProfileId;
use crate::toolchain::Toolchain;
use crate::utils::git::get_rustc_perf_commit;
use crate::{CollectorCtx, SelfProfileStorage};
use database::CollectionId;
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use futures::stream::FuturesUnordered;
use std::future::Future;
use std::pin::Pin;
use std::process::Command;
Expand Down Expand Up @@ -251,10 +251,10 @@ impl Processor for BenchProcessor<'_> {
// Buffer up to 10 self-profile stores at a time.
let mut futures = JoinSet::new();
for profile in self.self_profiles.drain(..) {
if futures.len() == 10 {
if let Err(error) = futures.join_next().await.unwrap().unwrap() {
log::error!("Failed to store self-profile result: {error:?}");
}
if futures.len() == 10
&& let Err(error) = futures.join_next().await.unwrap().unwrap()
{
log::error!("Failed to store self-profile result: {error:?}");
}

let id = SelfProfileId::Simple {
Expand Down
19 changes: 13 additions & 6 deletions collector/src/compile/execute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Execute benchmarks.

use crate::compile::benchmark::BenchmarkName;
use crate::compile::benchmark::codegen_backend::CodegenBackend;
use crate::compile::benchmark::frontend_threads::FrontendThreads;
use crate::compile::benchmark::patch::Patch;
use crate::compile::benchmark::profile::Profile;
use crate::compile::benchmark::scenario::Scenario;
use crate::compile::benchmark::target::Target;
use crate::compile::benchmark::BenchmarkName;
use crate::toolchain::Toolchain;
use crate::utils::fs::EnsureImmutableFile;
use crate::{async_command_output, command_output, utils};
Expand Down Expand Up @@ -47,9 +47,9 @@ impl PerfTool {
// What cargo subcommand do we need to run for this profiler? If not
// `rustc`, must be a subcommand that itself invokes `rustc`.
fn cargo_subcommand(&self, profile: Profile) -> Option<&'static str> {
use PerfTool::*;
use bencher::Bencher::*;
use profiler::Profiler::*;
use PerfTool::*;
match self {
BenchTool(PerfStat)
| BenchTool(PerfStatSelfProfile)
Expand Down Expand Up @@ -91,9 +91,9 @@ impl PerfTool {
}

fn is_scenario_allowed(&self, scenario: Scenario) -> bool {
use PerfTool::*;
use bencher::Bencher::*;
use profiler::Profiler::*;
use PerfTool::*;
match self {
BenchTool(PerfStat)
| BenchTool(PerfStatSelfProfile)
Expand Down Expand Up @@ -368,7 +368,11 @@ impl<'a> CargoProcess<'a> {
self.backend,
self.target,
self.frontend_threads.get(),
if needs_final { "benchmark" } else { "dependencies" }
if needs_final {
"benchmark"
} else {
"dependencies"
}
);

loop {
Expand Down Expand Up @@ -405,7 +409,7 @@ impl<'a> CargoProcess<'a> {
return Err(anyhow::anyhow!(
"this perf tool doesn't support the {:?} profile",
self.profile
))
));
}
Some(sub) => sub,
}
Expand All @@ -418,7 +422,10 @@ impl<'a> CargoProcess<'a> {
let mut cmd = self.base_command(self.cwd, cargo_subcommand);
cmd.arg("-p").arg(self.get_pkgid(self.cwd)?);

assert!(!self.rustc_args.iter().any(|arg| arg.contains("-Zthreads")), "rustc_args should not contain -Zthreads, set frontend_threads in perf-config.json instead");
assert!(
!self.rustc_args.iter().any(|arg| arg.contains("-Zthreads")),
"rustc_args should not contain -Zthreads, set frontend_threads in perf-config.json instead"
);
cmd.env(
"RUSTC_THREAD_COUNT",
self.frontend_threads.get().to_string(),
Expand Down
8 changes: 4 additions & 4 deletions collector/src/runtime/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ pub fn get_runtime_benchmark_groups(
.ok_or_else(|| anyhow::anyhow!("Cannot get filename of {}", path.display()))?
.to_string();

if let Some(ref group) = group {
if group != &name {
continue;
}
if let Some(ref group) = group
&& group != &name
{
continue;
}

groups.push(BenchmarkGroupCrate { name, path });
Expand Down
Loading
Loading