diff --git a/collector/Cargo.toml b/collector/Cargo.toml index d0e6254d49..2de2e379a9 100644 --- a/collector/Cargo.toml +++ b/collector/Cargo.toml @@ -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 } diff --git a/collector/benchlib/Cargo.toml b/collector/benchlib/Cargo.toml index 4c12a9a1c4..36f125a105 100644 --- a/collector/benchlib/Cargo.toml +++ b/collector/benchlib/Cargo.toml @@ -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 diff --git a/collector/benchlib/src/benchmark.rs b/collector/benchlib/src/benchmark.rs index 061c7e3471..fbf653adb5 100644 --- a/collector/benchlib/src/benchmark.rs +++ b/collector/benchlib/src/benchmark.rs @@ -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; diff --git a/collector/src/artifact_stats.rs b/collector/src/artifact_stats.rs index cd2b477899..8ad8e4c299 100644 --- a/collector/src/artifact_stats.rs +++ b/collector/src/artifact_stats.rs @@ -50,17 +50,16 @@ impl ArtifactStats { let mut stats: Option = 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()) @@ -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 diff --git a/collector/src/benchmark_set/mod.rs b/collector/src/benchmark_set/mod.rs index ee704a16f8..a11af5be0a 100644 --- a/collector/src/benchmark_set/mod.rs +++ b/collector/src/benchmark_set/mod.rs @@ -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)] @@ -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; diff --git a/collector/src/bin/bootstrap-rustc.rs b/collector/src/bin/bootstrap-rustc.rs index 8a63eb1557..800f079da0 100644 --- a/collector/src/bin/bootstrap-rustc.rs +++ b/collector/src/bin/bootstrap-rustc.rs @@ -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() { diff --git a/collector/src/bin/collector.rs b/collector/src/bin/collector.rs index 6ba72960be..04cf8f9a9c 100644 --- a/collector/src/bin/collector.rs +++ b/collector/src/bin/collector.rs @@ -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; @@ -30,10 +30,10 @@ 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; @@ -41,26 +41,26 @@ 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, @@ -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(" ") + )) } } @@ -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()), }; @@ -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; } } diff --git a/collector/src/codegen.rs b/collector/src/codegen.rs index 510f1c1e5f..7d2f510717 100644 --- a/collector/src/codegen.rs +++ b/collector/src/codegen.rs @@ -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 diff --git a/collector/src/compare/mod.rs b/collector/src/compare/mod.rs index f2ec2d35af..f626cd90b9 100644 --- a/collector/src/compare/mod.rs +++ b/collector/src/compare/mod.rs @@ -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::{ diff --git a/collector/src/compile/benchmark/mod.rs b/collector/src/compile/benchmark/mod.rs index 6a5785564d..d89370f9ca 100644 --- a/collector/src/compile/benchmark/mod.rs +++ b/collector/src/compile/benchmark/mod.rs @@ -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}; @@ -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()); } } @@ -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] diff --git a/collector/src/compile/benchmark/target.rs b/collector/src/compile/benchmark/target.rs index db808ee40a..6d4236b32d 100644 --- a/collector/src/compile/benchmark/target.rs +++ b/collector/src/compile/benchmark/target.rs @@ -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 diff --git a/collector/src/compile/execute/bencher.rs b/collector/src/compile/execute/bencher.rs index 433a8c2188..ff5f122b07 100644 --- a/collector/src/compile/execute/bencher.rs +++ b/collector/src/compile/execute/bencher.rs @@ -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; @@ -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 { diff --git a/collector/src/compile/execute/mod.rs b/collector/src/compile/execute/mod.rs index 296a748d3f..078fc96187 100644 --- a/collector/src/compile/execute/mod.rs +++ b/collector/src/compile/execute/mod.rs @@ -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}; @@ -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) @@ -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) @@ -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 { @@ -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, } @@ -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(), diff --git a/collector/src/runtime/benchmark.rs b/collector/src/runtime/benchmark.rs index b525010a61..b6511725b8 100644 --- a/collector/src/runtime/benchmark.rs +++ b/collector/src/runtime/benchmark.rs @@ -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 }); diff --git a/collector/src/runtime/mod.rs b/collector/src/runtime/mod.rs index 4602883ea4..2d79864fb8 100644 --- a/collector/src/runtime/mod.rs +++ b/collector/src/runtime/mod.rs @@ -9,22 +9,22 @@ use thousands::Separable; use benchlib::benchmark::passes_filter; use benchlib::comm::messages::{BenchmarkMessage, BenchmarkResult, BenchmarkStats}; pub use benchmark::{ - get_runtime_benchmark_groups, prepare_runtime_benchmark_suite, runtime_benchmark_dir, BenchmarkGroup, BenchmarkGroupCrate, BenchmarkSuite, BenchmarkSuiteCompilation, - CargoIsolationMode, RuntimeBenchmarkFilter, + CargoIsolationMode, RuntimeBenchmarkFilter, get_runtime_benchmark_groups, + prepare_runtime_benchmark_suite, runtime_benchmark_dir, }; use database::{ArtifactIdNumber, CollectionId, Connection}; use crate::runtime_group_step_name; use crate::utils::git::get_rustc_perf_commit; -use crate::{command_output, CollectorCtx}; +use crate::{CollectorCtx, command_output}; mod benchmark; mod profile; use crate::compile::benchmark::target::Target; pub use benchmark::RuntimeCompilationOpts; -pub use profile::{profile_runtime, RuntimeProfiler}; +pub use profile::{RuntimeProfiler, profile_runtime}; pub const DEFAULT_RUNTIME_ITERATIONS: u32 = 5; diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index ad3fc21e84..e352447d17 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -1,6 +1,6 @@ use crate::compile::benchmark::codegen_backend::CodegenBackend; use crate::compile::benchmark::profile::Profile; -use anyhow::{anyhow, Context}; +use anyhow::{Context, anyhow}; use log::debug; use reqwest::StatusCode; use std::ffi::OsStr; @@ -625,9 +625,9 @@ pub fn get_local_toolchain( Some(clippy) } else { anyhow::bail!( - "'Clippy' build specified but '--clippy' not specified and no 'clippy-driver' found \ + "'Clippy' build specified but '--clippy' not specified and no 'clippy-driver' found \ next to 'rustc'" - ); + ); } } else { // No `clippy` provided, but none needed. diff --git a/collector/src/utils/fs.rs b/collector/src/utils/fs.rs index a381152cae..c87a1a21cd 100644 --- a/collector/src/utils/fs.rs +++ b/collector/src/utils/fs.rs @@ -62,11 +62,11 @@ pub fn touch_all(path: &Path) -> anyhow::Result<()> { return false; } - if let Some(extn) = path.extension() { - if extn.to_str() == Some("rs") { - // Don't touch build scripts, which confuses the wrapped rustc. - return path.file_name() != Some(OsStr::new("build.rs")); - } + if let Some(extn) = path.extension() + && extn.to_str() == Some("rs") + { + // Don't touch build scripts, which confuses the wrapped rustc. + return path.file_name() != Some(OsStr::new("build.rs")); } false diff --git a/collector/src/utils/read2.rs b/collector/src/utils/read2.rs index 987bccff29..a2d333147e 100644 --- a/collector/src/utils/read2.rs +++ b/collector/src/utils/read2.rs @@ -105,9 +105,9 @@ mod imp { use std::process::{ChildStderr, ChildStdout}; use std::slice; + use miow::Overlapped; use miow::iocp::{CompletionPort, CompletionStatus}; use miow::pipe::NamedPipe; - use miow::Overlapped; use windows_sys::Win32::Foundation::ERROR_BROKEN_PIPE; struct Pipe<'a> { @@ -160,15 +160,15 @@ mod imp { unsafe fn new(p: P, dst: &'a mut Vec) -> Pipe<'a> { Pipe { dst, - pipe: NamedPipe::from_raw_handle(p.into_raw_handle()), + pipe: unsafe { NamedPipe::from_raw_handle(p.into_raw_handle()) }, overlapped: Overlapped::zero(), done: false, } } unsafe fn read(&mut self) -> io::Result<()> { - let dst = slice_to_end(self.dst); - match self.pipe.read_overlapped(dst, self.overlapped.raw()) { + let dst = unsafe { slice_to_end(self.dst) }; + match unsafe { self.pipe.read_overlapped(dst, self.overlapped.raw()) } { Ok(_) => Ok(()), Err(e) => { if e.raw_os_error() == Some(ERROR_BROKEN_PIPE as i32) { @@ -183,7 +183,7 @@ mod imp { unsafe fn complete(&mut self, status: &CompletionStatus) { let prev = self.dst.len(); - self.dst.set_len(prev + status.bytes_transferred() as usize); + unsafe { self.dst.set_len(prev + status.bytes_transferred() as usize) }; if status.bytes_transferred() == 0 { self.done = true; } @@ -197,6 +197,6 @@ mod imp { if v.capacity() == v.len() { v.reserve(1); } - slice::from_raw_parts_mut(v.as_mut_ptr().add(v.len()), v.capacity() - v.len()) + unsafe { slice::from_raw_parts_mut(v.as_mut_ptr().add(v.len()), v.capacity() - v.len()) } } } diff --git a/database/Cargo.toml b/database/Cargo.toml index 14ef20f60b..6840855f9e 100644 --- a/database/Cargo.toml +++ b/database/Cargo.toml @@ -2,7 +2,7 @@ name = "database" version = "0.1.0" authors = ["Mark Rousskov "] -edition = "2021" +edition = "2024" [dependencies] anyhow = { workspace = true } diff --git a/database/src/bin/postgres-to-sqlite.rs b/database/src/bin/postgres-to-sqlite.rs index f49deb37f4..b781e78f8e 100644 --- a/database/src/bin/postgres-to-sqlite.rs +++ b/database/src/bin/postgres-to-sqlite.rs @@ -4,8 +4,8 @@ //! transactions, and will likely fail if used on a populated database. use chrono::{DateTime, Utc}; -use clap::{builder::PossibleValuesParser, ArgAction}; -use database::pool::{postgres, sqlite, ConnectionManager}; +use clap::{ArgAction, builder::PossibleValuesParser}; +use database::pool::{ConnectionManager, postgres, sqlite}; use futures_util::StreamExt; use rusqlite::params; use std::time::Instant; diff --git a/database/src/bin/sqlite-to-postgres.rs b/database/src/bin/sqlite-to-postgres.rs index 151cf33ebf..96e67e641a 100644 --- a/database/src/bin/sqlite-to-postgres.rs +++ b/database/src/bin/sqlite-to-postgres.rs @@ -5,7 +5,7 @@ use bytes::{BufMut, Bytes, BytesMut}; use chrono::{DateTime, TimeZone, Utc}; -use database::pool::{postgres, sqlite, ConnectionManager}; +use database::pool::{ConnectionManager, postgres, sqlite}; use futures_util::sink::SinkExt; use hashbrown::HashMap; use serde::{Serialize, Serializer}; @@ -718,21 +718,21 @@ async fn copy( // while the table is locked, and sequences themselves can't be locked. This // program is designed to run on a fresh Postgres database anyway, so it's // not too big of a concern. - if count > 0 { - if let Some(generated_id_attr) = T::postgres_generated_id_attribute() { - postgres - .execute( - &format!( - "select setval( + if count > 0 + && let Some(generated_id_attr) = T::postgres_generated_id_attribute() + { + postgres + .execute( + &format!( + "select setval( pg_get_serial_sequence($1, $2), coalesce(max({generated_id_attr}) + 1, 1), false) from {table}" - ) as &str, - &[&table, &generated_id_attr], - ) - .await - .unwrap(); - } + ) as &str, + &[&table, &generated_id_attr], + ) + .await + .unwrap(); } let elapsed = start.elapsed(); diff --git a/database/src/metric.rs b/database/src/metric.rs index 0cfe13c162..b69f363b68 100644 --- a/database/src/metric.rs +++ b/database/src/metric.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use serde::{de::IntoDeserializer, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::IntoDeserializer}; /// This enum contains all "known" metrics coming from rustc or profiling tools that we know /// (and care) about. diff --git a/database/src/pool.rs b/database/src/pool.rs index fc9de52fb2..74c9214701 100644 --- a/database/src/pool.rs +++ b/database/src/pool.rs @@ -374,14 +374,14 @@ where let mut slots = self.connections.lock().unwrap_or_else(|e| e.into_inner()); slots.pop() }; - if let Some(mut c) = conn { - if self.manager.is_valid(&mut c).await { - return ManagedConnection { - conn: Some(c), - permit, - connections: self.connections.clone(), - }; - } + if let Some(mut c) = conn + && self.manager.is_valid(&mut c).await + { + return ManagedConnection { + conn: Some(c), + permit, + connections: self.connections.clone(), + }; } let conn = self.manager.open().await; @@ -419,9 +419,9 @@ impl Pool { mod tests { use super::*; use crate::metric::Metric; - use crate::tests::builder::{job, CollectorBuilder, RequestBuilder}; + use crate::tests::builder::{CollectorBuilder, RequestBuilder, job}; use crate::tests::run_postgres_test; - use crate::{tests::run_db_test, BenchmarkRequestType, Commit, CommitType, Date}; + use crate::{BenchmarkRequestType, Commit, CommitType, Date, tests::run_db_test}; use chrono::Utc; use std::collections::BTreeSet; use std::str::FromStr; @@ -677,10 +677,11 @@ mod tests { let req = BenchmarkRequest::create_try_without_artifacts(42, "", "", "", ""); db.insert_benchmark_request(&req).await.unwrap(); - assert!(db - .attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now()) - .await - .unwrap()); + assert!( + db.attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now()) + .await + .unwrap() + ); let req_db = db .load_pending_benchmark_requests() @@ -724,10 +725,11 @@ mod tests { ); db.insert_benchmark_request(&req).await.unwrap(); - assert!(db - .attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now()) - .await - .unwrap()); + assert!( + db.attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now()) + .await + .unwrap() + ); let loaded = db .load_pending_benchmark_requests() @@ -752,10 +754,11 @@ mod tests { run_postgres_test(|ctx| async { let db = ctx.db(); - assert!(!db - .attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now()) - .await - .unwrap()); + assert!( + !db.attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now()) + .await + .unwrap() + ); Ok(ctx) }) @@ -851,11 +854,12 @@ mod tests { CommitType::Try, ))) .await; - assert!(db - .get_compile_test_cases_with_measurements(&artifact2) - .await - .unwrap() - .is_empty()); + assert!( + db.get_compile_test_cases_with_measurements(&artifact2) + .await + .unwrap() + .is_empty() + ); Ok(ctx) }) .await; @@ -1015,10 +1019,11 @@ mod tests { db.insert_benchmark_request(&benchmark_request) .await .unwrap(); - assert!(db - .maybe_mark_benchmark_request_as_completed("sha-1") - .await - .unwrap()); + assert!( + db.maybe_mark_benchmark_request_as_completed("sha-1") + .await + .unwrap() + ); Ok(ctx) }) .await; @@ -1316,22 +1321,24 @@ mod tests { .unwrap(); db.purge_artifact(&ArtifactId::Tag("foo".to_string())).await; - assert!(!db - .load_benchmark_request_index() - .await - .unwrap() - .contains_tag("foo")); + assert!( + !db.load_benchmark_request_index() + .await + .unwrap() + .contains_tag("foo") + ); let collector = ctx.add_collector(CollectorBuilder::default()).await; - assert!(db - .dequeue_benchmark_job( + assert!( + db.dequeue_benchmark_job( collector.name(), collector.target(), collector.benchmark_set(), ) .await .unwrap() - .is_none()); + .is_none() + ); Ok(ctx) }) diff --git a/database/src/pool/postgres.rs b/database/src/pool/postgres.rs index 3a9efd93b6..00f519c714 100644 --- a/database/src/pool/postgres.rs +++ b/database/src/pool/postgres.rs @@ -3,23 +3,22 @@ use crate::pool::{ }; use crate::selector::{CompileTestCase, RuntimeTestCase}; use crate::{ - parse_benchmarks, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJob, - BenchmarkJobConclusion, BenchmarkJobKind, BenchmarkJobStatus, BenchmarkRequest, - BenchmarkRequestIndex, BenchmarkRequestInsertResult, BenchmarkRequestStatus, - BenchmarkRequestType, BenchmarkRequestWithErrors, BenchmarkSet, CodegenBackend, CollectionId, - CollectorConfig, Commit, CommitType, CompileBenchmark, Date, FrontendThreads, Index, - PendingBenchmarkRequests, Profile, Scenario, Target, BENCHMARK_JOB_STATUS_FAILURE_STR, + ArtifactId, ArtifactIdNumber, BENCHMARK_JOB_STATUS_FAILURE_STR, BENCHMARK_JOB_STATUS_IN_PROGRESS_STR, BENCHMARK_JOB_STATUS_QUEUED_STR, BENCHMARK_JOB_STATUS_SUCCESS_STR, BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR, BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR, BENCHMARK_REQUEST_STATUS_COMPLETED_STR, BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR, BENCHMARK_REQUEST_STATUS_WAITING_FOR_ARTIFACTS_STR, - BENCHMARK_REQUEST_TRY_STR, + BENCHMARK_REQUEST_TRY_STR, Benchmark, BenchmarkJob, BenchmarkJobConclusion, BenchmarkJobKind, + BenchmarkJobStatus, BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestInsertResult, + BenchmarkRequestStatus, BenchmarkRequestType, BenchmarkRequestWithErrors, BenchmarkSet, + CodegenBackend, CollectionId, CollectorConfig, Commit, CommitType, CompileBenchmark, Date, + FrontendThreads, Index, PendingBenchmarkRequests, Profile, Scenario, Target, parse_benchmarks, }; use anyhow::Context as _; use chrono::{DateTime, TimeZone, Utc}; use hashbrown::{HashMap, HashSet}; -use rustls::pki_types::pem::PemObject; use rustls::pki_types::CertificateDer; +use rustls::pki_types::pem::PemObject; use rustls::{ClientConfig, RootCertStore}; use std::str::FromStr; use std::sync::Arc; @@ -807,8 +806,7 @@ impl PostgresConnection { } // `tag` should be kept as the first column -const BENCHMARK_REQUEST_COLUMNS: &str = - "tag, parent_sha, pr, commit_type, status, created_at, completed_at, backends, profiles, commit_date, duration_ms, targets, benchmarks"; +const BENCHMARK_REQUEST_COLUMNS: &str = "tag, parent_sha, pr, commit_type, status, created_at, completed_at, backends, profiles, commit_date, duration_ms, targets, benchmarks"; /// Parse a benchmark job out of a row. /// Expects to be used with `SELECT * FROM job_queue`. @@ -1288,10 +1286,10 @@ where ) .await .unwrap() + && Some(r.get::<_, bool>(0)) == supports_stable + && r.get::<_, &str>(1) == category { - if Some(r.get::<_, bool>(0)) == supports_stable && r.get::<_, &str>(1) == category { - return; - } + return; } if let Some(stable) = supports_stable { self.conn() @@ -1545,7 +1543,9 @@ where // We cannot use this function to mark requests as complete, as // we need to know if all jobs are complete first. if matches!(status, BenchmarkRequestStatus::Completed { .. }) { - panic!("Please use `mark_benchmark_request_as_completed(...)` to complete benchmark_requests"); + panic!( + "Please use `mark_benchmark_request_as_completed(...)` to complete benchmark_requests" + ); } let status_str = status.as_str(); @@ -1617,10 +1617,10 @@ where for row in rows { let parent_done = row.get::<_, Option>(0); let request = row_to_benchmark_request(&row, Some(1)); - if let Some(true) = parent_done { - if let Some(parent) = request.parent_sha() { - completed_parent_tags.insert(parent.to_string()); - } + if let Some(true) = parent_done + && let Some(parent) = request.parent_sha() + { + completed_parent_tags.insert(parent.to_string()); } requests.push(request); } diff --git a/database/src/pool/sqlite.rs b/database/src/pool/sqlite.rs index 2c1480960c..9076095e44 100644 --- a/database/src/pool/sqlite.rs +++ b/database/src/pool/sqlite.rs @@ -12,8 +12,8 @@ use crate::{ use crate::{ArtifactIdNumber, Index}; use chrono::{DateTime, TimeZone, Utc}; use hashbrown::{HashMap, HashSet}; -use rusqlite::params; use rusqlite::OptionalExtension; +use rusqlite::params; use std::path::PathBuf; use std::str::FromStr; use std::sync::Mutex; diff --git a/database/src/selector.rs b/database/src/selector.rs index d4157075b4..46ae848dfb 100644 --- a/database/src/selector.rs +++ b/database/src/selector.rs @@ -28,8 +28,8 @@ use std::{ }; use crate::{ - interpolate::Interpolate, metric::Metric, ArtifactId, ArtifactIdIter, Benchmark, - CodegenBackend, Connection, FrontendThreads, Index, Lookup, Profile, Scenario, Target, + ArtifactId, ArtifactIdIter, Benchmark, CodegenBackend, Connection, FrontendThreads, Index, + Lookup, Profile, Scenario, Target, interpolate::Interpolate, metric::Metric, }; #[derive(Debug)] @@ -284,7 +284,7 @@ impl BenchmarkQuery for CompileBenchmarkQuery { let mut statistic_descriptions: Vec<_> = index .compile_statistic_descriptions() .filter( - |(&(b, p, s, backend, target, frontend_threads, metric), _)| { + |&(&(b, p, s, backend, target, frontend_threads, metric), _)| { self.benchmark.matches(b) && self.profile.matches(p) && self.scenario.matches(s) @@ -430,7 +430,7 @@ impl BenchmarkQuery for RuntimeBenchmarkQuery { ) -> Result>, String> { let mut statistic_descriptions: Vec<_> = index .runtime_statistic_descriptions() - .filter(|(&(b, t, m), _)| { + .filter(|&(&(b, t, m), _)| { self.benchmark.matches(b) && self.target.matches(t) && self.metric.matches(m) }) .map(|(&(benchmark, target, _), sid)| (RuntimeTestCase { benchmark, target }, sid)) diff --git a/database/src/tests/builder.rs b/database/src/tests/builder.rs index 44793399c7..38e73b3b5e 100644 --- a/database/src/tests/builder.rs +++ b/database/src/tests/builder.rs @@ -101,10 +101,11 @@ impl RequestBuilder { } // At this point all jobs of the request should be properly completed, so we can also // complete the request itself - assert!(db - .maybe_mark_benchmark_request_as_completed(&tag) - .await - .unwrap()); + assert!( + db.maybe_mark_benchmark_request_as_completed(&tag) + .await + .unwrap() + ); drop(to_complete); self } diff --git a/database/src/tests/mod.rs b/database/src/tests/mod.rs index 3ef24090ef..457fe828fb 100644 --- a/database/src/tests/mod.rs +++ b/database/src/tests/mod.rs @@ -4,8 +4,8 @@ pub mod builder; use chrono::Utc; use std::future::Future; -use tokio_postgres::config::Host; use tokio_postgres::Config; +use tokio_postgres::config::Host; use crate::pool::postgres::make_client; use crate::tests::builder::CollectorBuilder; diff --git a/intern/Cargo.toml b/intern/Cargo.toml index 115117b36b..42092f7d20 100644 --- a/intern/Cargo.toml +++ b/intern/Cargo.toml @@ -2,7 +2,7 @@ name = "intern" version = "0.1.0" authors = ["Mark Rousskov "] -edition = "2021" +edition = "2024" [dependencies] hashbrown = { workspace = true } diff --git a/intern/src/lib.rs b/intern/src/lib.rs index ebde3d1420..81ecd071d7 100644 --- a/intern/src/lib.rs +++ b/intern/src/lib.rs @@ -153,7 +153,7 @@ pub fn intern(value: &str) -> T { return o; } - let (ref mut set, ref mut arena) = &mut *guard; + let (set, arena) = &mut *guard; assert_eq!(set.len(), INTERNED.0.load().len()); let allocated = unsafe { diff --git a/site/Cargo.toml b/site/Cargo.toml index 916cc97def..a5b0bc2443 100644 --- a/site/Cargo.toml +++ b/site/Cargo.toml @@ -6,7 +6,7 @@ authors = [ ] name = "site" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] anyhow = { workspace = true } diff --git a/site/src/api.rs b/site/src/api.rs index 9ba2cf7dc1..f6d4839f9b 100644 --- a/site/src/api.rs +++ b/site/src/api.rs @@ -4,8 +4,8 @@ //! //! The responses are calculated in the server.rs file. -use serde::de::{DeserializeOwned, Error}; use serde::Deserializer; +use serde::de::{DeserializeOwned, Error}; use std::fmt::Formatter; use std::marker::PhantomData; use std::result::Result as StdResult; @@ -269,7 +269,7 @@ pub mod toolchain { pub mod comparison { use crate::benchmark_metadata::ProfileMetadata; use collector::Bound; - use database::{metric::Metric, Date}; + use database::{Date, metric::Metric}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/site/src/benchmark_metadata/mod.rs b/site/src/benchmark_metadata/mod.rs index a6bf8e5cd0..1294fffa48 100644 --- a/site/src/benchmark_metadata/mod.rs +++ b/site/src/benchmark_metadata/mod.rs @@ -3,8 +3,8 @@ use std::sync::LazyLock; use hashbrown::HashMap; use rust_embed::RustEmbed; -use collector::compile::benchmark::category::Category; use collector::compile::benchmark::BenchmarkConfig; +use collector::compile::benchmark::category::Category; use crate::benchmark_metadata::metadata::SERIALIZED_SUITE_NAME; diff --git a/site/src/comparison.rs b/site/src/comparison.rs index 7f1a989a2c..51e0a315d3 100644 --- a/site/src/comparison.rs +++ b/site/src/comparison.rs @@ -6,14 +6,14 @@ use crate::api; use crate::github; use crate::load::SiteCtxt; -use collector::compile::benchmark::category::Category; use collector::Bound; +use collector::compile::benchmark::category::Category; +use database::{ArtifactId, Benchmark, Lookup}; use database::{ + Target, metric::Metric, selector::{self, BenchmarkQuery, CompileBenchmarkQuery, RuntimeBenchmarkQuery, TestCase}, - Target, }; -use database::{ArtifactId, Benchmark, Lookup}; use serde::Serialize; use crate::api::comparison::CompileBenchmarkMetadata; @@ -1275,11 +1275,7 @@ impl TestResultComparison { // How many times the threshold this change is. let factor = change.abs() / threshold; - if factor.is_finite() { - factor - } else { - 0.0 - } + if factor.is_finite() { factor } else { 0.0 } } /// Whether the comparison is relevant or not. diff --git a/site/src/github.rs b/site/src/github.rs index bd2e49b252..2d12b4b956 100644 --- a/site/src/github.rs +++ b/site/src/github.rs @@ -266,7 +266,7 @@ async fn send_request( Err(e) => { return Err(anyhow::anyhow!("response = {:?}", response) .context(e) - .into()) + .into()); } } Ok(response.json::().await?) diff --git a/site/src/github/comparison_summary.rs b/site/src/github/comparison_summary.rs index c400ff08fa..bd4fa740d4 100644 --- a/site/src/github/comparison_summary.rs +++ b/site/src/github/comparison_summary.rs @@ -1,12 +1,12 @@ use crate::comparison::{ - deserves_attention_icount, write_summary_table, ArtifactComparison, ArtifactComparisonSummary, - Direction, + ArtifactComparison, ArtifactComparisonSummary, Direction, deserves_attention_icount, + write_summary_table, }; use crate::load::SiteCtxt; -use database::{metric::Metric, QueuedCommit}; +use database::{QueuedCommit, metric::Metric}; -use crate::github::triage::{is_triage_run, update_triage_body, TriageBuild}; +use crate::github::triage::{TriageBuild, is_triage_run, update_triage_body}; use crate::github::{COMMENT_MARK_TEMPORARY, RUST_REPO_GITHUB_API_URL}; use humansize::BINARY; use std::fmt::Write; @@ -71,10 +71,12 @@ pub async fn post_comparison_comment( PerfRunSource::TryBuild }; - let body = summarize_run(ctxt, commit, source) + if let Some(body) = summarize_run(ctxt, commit, source) .await - .unwrap_or_else(|error| error); - client.post_comment(pr, body).await; + .unwrap_or_else(Some) + { + client.post_comment(pr, body).await; + } Ok(()) } @@ -132,7 +134,7 @@ async fn summarize_run( ctxt: &SiteCtxt, commit: QueuedCommit, source: PerfRunSource, -) -> Result { +) -> Result, String> { let benchmark_map = ctxt.get_benchmark_category_map().await; let mut message = String::new(); @@ -193,6 +195,15 @@ async fn summarize_run( let is_regression = deserves_attention && matches!(direction, Direction::Regression | Direction::Mixed); + // Don't post a summary for perf runs that are a part of triage runs, that don't deserve attention + // We skip this because it's just another noisy ping, + // and only posting it when the results are relevant means people will pay more attention to it if it is posted + if let PerfRunSource::TriageBuild(_) = &source + && !deserves_attention + { + return Ok(None); + } + writeln!( &mut message, "### Overall result: {}{}\n", @@ -234,7 +245,7 @@ async fn summarize_run( write!(&mut message, "\n{bootstrap}").unwrap(); write!(&mut message, "\n{artifact_size}").unwrap(); - Ok(message) + Ok(Some(message)) } pub async fn metrics_result( diff --git a/site/src/github/triage.rs b/site/src/github/triage.rs index 86e9b99ed9..8e6d350c97 100644 --- a/site/src/github/triage.rs +++ b/site/src/github/triage.rs @@ -3,8 +3,8 @@ use crate::github::comparison_summary::calculate_metric_comparison; use crate::load::SiteCtxt; use crate::request_handlers::parse_unrolled_build_message; use anyhow::bail; -use database::metric::Metric; use database::QueuedCommit; +use database::metric::Metric; pub struct TriageBuild { pub rollup_pr_number: u32, @@ -78,7 +78,9 @@ pub async fn changed_benchmarks_in_rollup( .find(|commit| commit.pr.is_some_and(|pr| pr == rollup)) .cloned() else { - bail!("The `@rust-timer triage` command can only be executed in merged rollups. If this is a merged rollup, it might be too old.") + bail!( + "The `@rust-timer triage` command can only be executed in merged rollups. If this is a merged rollup, it might be too old." + ) }; drop(master_commits); @@ -275,12 +277,14 @@ NEW BODY3 #[test] fn test_update_not_in_there() { let mut body = BEFORE_BODY.to_string(); - assert!(update_triage_body( - &mut body, - 1234, - "NEW BODY1\nNEW BODY2\nNEW BODY3\n".to_string() - ) - .is_err()); + assert!( + update_triage_body( + &mut body, + 1234, + "NEW BODY1\nNEW BODY2\nNEW BODY3\n".to_string() + ) + .is_err() + ); } #[test] diff --git a/site/src/job_queue/mod.rs b/site/src/job_queue/mod.rs index 33836c6695..bb7921c257 100644 --- a/site/src/job_queue/mod.rs +++ b/site/src/job_queue/mod.rs @@ -6,7 +6,7 @@ use crate::load::SiteCtxt; use anyhow::Context; use chrono::Utc; use collector::benchmark_set::{ - get_benchmark_sets_for_target, BENCHMARK_SET_RUNTIME_BENCHMARKS, BENCHMARK_SET_RUSTC, + BENCHMARK_SET_RUNTIME_BENCHMARKS, BENCHMARK_SET_RUSTC, get_benchmark_sets_for_target, }; use database::pool::{JobEnqueueResult, Transaction}; use database::{ @@ -676,10 +676,11 @@ mod tests { .await .unwrap(); - assert!(db - .maybe_mark_benchmark_request_as_completed(request_tag) - .await - .unwrap()); + assert!( + db.maybe_mark_benchmark_request_as_completed(request_tag) + .await + .unwrap() + ); } async fn mark_as_completed( @@ -829,10 +830,11 @@ mod tests { ctx.insert_try_request(112049).await; let db = ctx.db(); - assert!(db - .attach_shas_to_try_benchmark_request(112049, "60ce", "1f88", Utc::now()) - .await - .unwrap()); + assert!( + db.attach_shas_to_try_benchmark_request(112049, "60ce", "1f88", Utc::now()) + .await + .unwrap() + ); ctx.insert_master_request("2038", "1f88", 148350).await; let queue = build_queue(db).await?; diff --git a/site/src/job_queue/utils.rs b/site/src/job_queue/utils.rs index f025ac3e5d..ba349833f9 100644 --- a/site/src/job_queue/utils.rs +++ b/site/src/job_queue/utils.rs @@ -148,10 +148,10 @@ mod tests { #[test] fn skips_unconsumable_channels() { // nightly never returns Anything - assert!(parse_release_string( - "static.rust-lang.org/dist/2016-05-31/channel-rust-nightly.toml" - ) - .is_none()); + assert!( + parse_release_string("static.rust-lang.org/dist/2016-05-31/channel-rust-nightly.toml") + .is_none() + ); // versioned-beta artefacts are skipped too for should_ignore in [ diff --git a/site/src/request_handlers/dashboard.rs b/site/src/request_handlers/dashboard.rs index 928da1d9cf..f589495715 100644 --- a/site/src/request_handlers/dashboard.rs +++ b/site/src/request_handlers/dashboard.rs @@ -1,11 +1,11 @@ use std::str::FromStr; use std::sync::{Arc, LazyLock}; -use crate::api::{dashboard, ServerResult}; +use crate::api::{ServerResult, dashboard}; use crate::benchmark_metadata::get_stable_benchmark_names; use crate::load::SiteCtxt; -use database::{self, metric::Metric, ArtifactId, Profile, Scenario}; -use database::{selector, Target}; +use database::{self, ArtifactId, Profile, Scenario, metric::Metric}; +use database::{Target, selector}; pub async fn handle_dashboard( query: dashboard::Request, diff --git a/site/src/request_handlers/github.rs b/site/src/request_handlers/github.rs index 44a5b9367d..25367dc2c0 100644 --- a/site/src/request_handlers/github.rs +++ b/site/src/request_handlers/github.rs @@ -1,6 +1,6 @@ -use crate::api::{github, ServerResult}; +use crate::api::{ServerResult, github}; use crate::github::{ - client, enqueue_sha, parse_homu_comment, COMMENT_MARK_TEMPORARY, RUST_REPO_GITHUB_API_URL, + COMMENT_MARK_TEMPORARY, RUST_REPO_GITHUB_API_URL, client, enqueue_sha, parse_homu_comment, }; use crate::load::SiteCtxt; use std::fmt::Write; @@ -9,12 +9,12 @@ use crate::api::github::Issue; use crate::benchmark_metadata::get_compile_benchmarks_metadata; use crate::github::client::{Client, Commit, GraphQLClient}; use crate::github::triage::{ - changed_benchmarks_in_rollup, find_and_parse_unrolled_build_comment, triage_body_end_marker, - triage_body_start_marker, TRIAGE_MARKER, + TRIAGE_MARKER, changed_benchmarks_in_rollup, find_and_parse_unrolled_build_comment, + triage_body_end_marker, triage_body_start_marker, }; use database::{ - parse_backends, parse_benchmarks, parse_profiles, parse_targets, BenchmarkRequest, - BenchmarkRequestInsertResult, CodegenBackend, Profile, Target, + BenchmarkRequest, BenchmarkRequestInsertResult, CodegenBackend, Profile, Target, + parse_backends, parse_benchmarks, parse_profiles, parse_targets, }; use futures::stream::{FuturesUnordered, StreamExt}; use hashbrown::HashMap; @@ -55,35 +55,35 @@ async fn handle_issue(ctxt: Arc, issue: github::Issue, comment: github } let gh_client = client::Client::from_ctxt(&ctxt, RUST_REPO_GITHUB_API_URL.to_owned()); - if comment.body.contains(" homu: ") { - if let Some(sha) = parse_homu_comment(&comment.body).await { - let commit = match gh_client.get_commit(&sha).await { - Ok(commit) => commit, - Err(error) => { - gh_client - .post_comment( - issue.number, - format!("Cannot fetch commit `{sha}` info: {error:?}"), - ) - .await; - return; - } - }; + if comment.body.contains(" homu: ") + && let Some(sha) = parse_homu_comment(&comment.body).await + { + let commit = match gh_client.get_commit(&sha).await { + Ok(commit) => commit, + Err(error) => { + gh_client + .post_comment( + issue.number, + format!("Cannot fetch commit `{sha}` info: {error:?}"), + ) + .await; + return; + } + }; - match enqueue_sha(&ctxt, commit, issue.number).await { - Ok(Some(mut msg)) => { - msg.push_str(&format!("\n{COMMENT_MARK_TEMPORARY}")); - gh_client.post_comment(issue.number, msg).await; - } - Ok(None) => { - // A try build without @rust-timer queue finished - } - Err(err) => { - gh_client.post_comment(issue.number, err).await; - } + match enqueue_sha(&ctxt, commit, issue.number).await { + Ok(Some(mut msg)) => { + msg.push_str(&format!("\n{COMMENT_MARK_TEMPORARY}")); + gh_client.post_comment(issue.number, msg).await; + } + Ok(None) => { + // A try build without @rust-timer queue finished + } + Err(err) => { + gh_client.post_comment(issue.number, err).await; } - return; } + return; } // Do not react to @rust-timer commands sent by the bors GitHub App @@ -457,8 +457,15 @@ pub fn parse_unrolled_build_message(commit_message: &str) -> Result>(); - let ["Unrolled", "build", "for", member_pr_number, "in", "rollup", rollup_pr_number] = - words[..] + let [ + "Unrolled", + "build", + "for", + member_pr_number, + "in", + "rollup", + rollup_pr_number, + ] = words[..] else { return Err(format!( "Unexpected commit name `{first_line}`, could not parse commit title. Is the commit an unrolled build?" diff --git a/site/src/request_handlers/graph.rs b/site/src/request_handlers/graph.rs index e6d32308c5..a934574dcf 100644 --- a/site/src/request_handlers/graph.rs +++ b/site/src/request_handlers/graph.rs @@ -6,7 +6,7 @@ use collector::{Bound, SelfProfileId}; use crate::api::detail_sections::CompilationSections; use crate::api::graphs::GraphKind; -use crate::api::{detail_graphs, detail_sections, graphs, runtime_detail_graphs, ServerResult}; +use crate::api::{ServerResult, detail_graphs, detail_sections, graphs, runtime_detail_graphs}; use crate::load::SiteCtxt; use crate::self_profile::fetch_self_profile; @@ -14,7 +14,7 @@ use database::selector::{ CompileBenchmarkQuery, CompileTestCase, RuntimeBenchmarkQuery, Selector, SeriesResponse, }; use database::{self, ArtifactId, CodegenBackend, Profile, Scenario, Target}; -use database::{interpolate::IsInterpolated, FrontendThreads}; +use database::{FrontendThreads, interpolate::IsInterpolated}; /// Returns data for before/after graphs when comparing a single test result comparison /// for a compile-time benchmark. @@ -218,10 +218,8 @@ pub async fn handle_graphs( frontend_threads: None, }; - if is_default_query { - if let Some(resp) = &**ctxt.landing_page.load() { - return Ok(resp.clone()); - } + if is_default_query && let Some(resp) = &**ctxt.landing_page.load() { + return Ok(resp.clone()); } let resp = Arc::new(create_graphs(request, &ctxt).await?); diff --git a/site/src/request_handlers/self_profile.rs b/site/src/request_handlers/self_profile.rs index 9b1f86aab4..ec1c451706 100644 --- a/site/src/request_handlers/self_profile.rs +++ b/site/src/request_handlers/self_profile.rs @@ -1,17 +1,17 @@ use crate::api::self_profile::ArtifactSizeDelta; -use crate::api::{self_profile, self_profile_processed, self_profile_raw, ServerResult}; +use crate::api::{ServerResult, self_profile, self_profile_processed, self_profile_raw}; use crate::load::SiteCtxt; use crate::self_profile::fetch_self_profile; -use crate::server::{maybe_compressed_response, Response, ResponseHeaders}; +use crate::server::{Response, ResponseHeaders, maybe_compressed_response}; use brotli::enc::BrotliEncoderParams; -use collector::compile::benchmark::BenchmarkName; use collector::SelfProfileId; -use database::{metric::Metric, CommitType, FrontendThreads}; -use database::{selector, CodegenBackend, Target}; +use collector::compile::benchmark::BenchmarkName; use database::{ArtifactId, Profile}; +use database::{CodegenBackend, Target, selector}; +use database::{CommitType, FrontendThreads, metric::Metric}; use headers::{ContentType, Header}; -use hyper::body::Bytes; use hyper::StatusCode; +use hyper::body::Bytes; use std::collections::HashSet; use std::sync::Arc; use std::time::Instant; diff --git a/site/src/request_handlers/toolchain.rs b/site/src/request_handlers/toolchain.rs index ca48eaa111..f5f0d6b493 100644 --- a/site/src/request_handlers/toolchain.rs +++ b/site/src/request_handlers/toolchain.rs @@ -1,6 +1,6 @@ use futures::stream::{FuturesOrdered, StreamExt}; -use crate::api::{toolchain, ServerResult}; +use crate::api::{ServerResult, toolchain}; use crate::load::SiteCtxt; use database::{ArtifactId, Target}; diff --git a/site/src/selector.rs b/site/src/selector.rs index 610c2e084c..b9dc52bb74 100644 --- a/site/src/selector.rs +++ b/site/src/selector.rs @@ -1,9 +1,9 @@ use crate::load::SiteCtxt; use collector::Bound; +use database::ArtifactId; use database::selector::StatisticSeries; use database::selector::{BenchmarkQuery, SeriesResponse}; -use database::ArtifactId; use database::{Commit, Index}; use std::ops::RangeInclusive; diff --git a/site/src/self_profile.rs b/site/src/self_profile.rs index 8f748d2795..562272cfb5 100644 --- a/site/src/self_profile.rs +++ b/site/src/self_profile.rs @@ -3,7 +3,7 @@ use crate::api::detail_sections::CompilationSection; use crate::api::self_profile::ArtifactSize; -use crate::api::{self_profile, ServerResult}; +use crate::api::{ServerResult, self_profile}; use crate::load::SiteCtxt; use analyzeme::ProfilingData; use anyhow::Context; diff --git a/site/src/self_profile/crox.rs b/site/src/self_profile/crox.rs index 12f537cdeb..1f53b038d5 100644 --- a/site/src/self_profile/crox.rs +++ b/site/src/self_profile/crox.rs @@ -144,10 +144,10 @@ pub fn generate(data: ProfilingData, opt: Opt) -> anyhow::Result> { .filter(|e| e.timestamp().is_some_and(|t| !t.is_instant())) { let duration = event.duration().unwrap(); - if let Some(minimum_duration) = opt.minimum_duration { - if duration.as_micros() < minimum_duration { - continue; - } + if let Some(minimum_duration) = opt.minimum_duration + && duration.as_micros() < minimum_duration + { + continue; } let full_event = data.to_full_event(&event); let crox_event = Event { diff --git a/site/src/self_profile/flamegraph.rs b/site/src/self_profile/flamegraph.rs index bbd237d703..a64337f54f 100644 --- a/site/src/self_profile/flamegraph.rs +++ b/site/src/self_profile/flamegraph.rs @@ -1,6 +1,6 @@ -use analyzeme::{collapse_stacks, ProfilingData}; +use analyzeme::{ProfilingData, collapse_stacks}; use anyhow::Context; -use inferno::flamegraph::{from_lines, Options as FlamegraphOptions}; +use inferno::flamegraph::{Options as FlamegraphOptions, from_lines}; #[derive(serde::Deserialize, Debug)] pub struct Opt {} diff --git a/site/src/server.rs b/site/src/server.rs index 93aa0b12e9..b5738f0d3d 100644 --- a/site/src/server.rs +++ b/site/src/server.rs @@ -1,5 +1,5 @@ -use brotli::enc::BrotliEncoderParams; use brotli::BrotliCompress; +use brotli::enc::BrotliEncoderParams; use hmac::{Hmac, Mac}; use sha2::Sha256; use std::collections::HashMap; @@ -12,18 +12,18 @@ use std::{fmt, str}; use headers::{CacheControl, ContentType, ETag, HeaderMapExt, IfNoneMatch}; use http::header::CACHE_CONTROL; use http_body_util::{BodyExt, Full, Limited}; -use hyper::body::{Bytes, Incoming}; use hyper::StatusCode; +use hyper::body::{Bytes, Incoming}; use hyper_util::rt::TokioIo; use log::{error, info}; use parking_lot::RwLock; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use uuid::Uuid; pub use crate::api::{ - self, comparison, dashboard, github, graphs, info, self_profile, status, toolchain, triage, - ServerResult, + self, ServerResult, comparison, dashboard, github, graphs, info, self_profile, status, + toolchain, triage, }; use crate::load::{Config, SiteCtxt}; use crate::request_handlers; @@ -334,7 +334,7 @@ async fn serve_req(server: Server, req: Request) -> Result return Err(ServerError(format!("failed to read body: {err}"))), }; @@ -359,7 +359,7 @@ async fn serve_req(server: Server, req: Request) -> Result Opt .header(CACHE_CONTROL, "max-age=60, stale-while-revalidate=86400"); // tell client to use cached response for one day, but revalidate in background if older than one minute let if_none_match = req.headers().typed_get::(); - if let Some(if_none_match) = if_none_match { - if !if_none_match.precondition_passes(&etag) { - return Some(not_modified(response)); // tell client that the resource was not modified and to use cached response - } + if let Some(if_none_match) = if_none_match + && !if_none_match.precondition_passes(&etag) + { + return Some(not_modified(response)); // tell client that the resource was not modified and to use cached response } async fn resolve_template(path: &str) -> Vec {