Skip to content

Commit cb1ed34

Browse files
committed
Store runtime benchmark names into SQLite
1 parent 934ceb8 commit cb1ed34

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

collector/src/bin/collector.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ enum Commands {
571571
/// How many iterations of each benchmark should be executed.
572572
#[clap(long, default_value = "5")]
573573
iterations: u32,
574+
575+
#[clap(flatten)]
576+
db: DbOption,
574577
},
575578
/// Benchmarks a local rustc
576579
BenchLocal {
@@ -703,7 +706,11 @@ fn main_result() -> anyhow::Result<i32> {
703706
let target_triple = format!("{}-unknown-linux-gnu", std::env::consts::ARCH);
704707

705708
match args.command {
706-
Commands::BenchRuntimeLocal { local, iterations } => {
709+
Commands::BenchRuntimeLocal {
710+
local,
711+
iterations,
712+
db,
713+
} => {
707714
let toolchain = get_local_toolchain(
708715
&[Profile::Opt],
709716
&local.rustc,
@@ -712,12 +719,15 @@ fn main_result() -> anyhow::Result<i32> {
712719
local.id.as_deref(),
713720
"",
714721
)?;
715-
bench_runtime(
722+
let pool = Pool::open(&db.db);
723+
let fut = bench_runtime(
724+
pool,
716725
toolchain,
717726
BenchmarkFilter::new(local.exclude, local.include),
718727
runtime_benchmark_dir,
719728
iterations,
720-
)?;
729+
);
730+
rt.block_on(fut)?;
721731
Ok(0)
722732
}
723733
Commands::BenchLocal {

collector/src/runtime/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl BenchmarkSuite {
4545
.count() as u64
4646
}
4747

48-
fn benchmark_names(&self) -> impl Iterator<Item = &str> {
48+
pub fn benchmark_names(&self) -> impl Iterator<Item = &str> {
4949
self.groups
5050
.iter()
5151
.flat_map(|suite| suite.benchmark_names.iter().map(|n| n.as_ref()))

collector/src/runtime/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@ use std::process::{Command, Stdio};
88
use thousands::Separable;
99

1010
pub use benchmark::BenchmarkFilter;
11+
use database::Pool;
1112

1213
/// Perform a series of runtime benchmarks using the provided `rustc` compiler.
1314
/// The runtime benchmarks are looked up in `benchmark_dir`, which is expected to be a path
1415
/// to a Cargo crate. All binaries built by that crate will are expected to be runtime benchmark
1516
/// groups that leverage `benchlib`.
16-
pub fn bench_runtime(
17+
pub async fn bench_runtime(
18+
db: Pool,
1719
toolchain: LocalToolchain,
1820
filter: BenchmarkFilter,
1921
benchmark_dir: PathBuf,
2022
iterations: u32,
2123
) -> anyhow::Result<()> {
2224
let suite = benchmark::discover_benchmarks(&toolchain, &benchmark_dir)?;
2325

26+
let connection = db.connection().await;
27+
for benchmark in suite.benchmark_names() {
28+
connection.record_runtime_benchmark(benchmark).await;
29+
}
30+
2431
let total_benchmark_count = suite.total_benchmark_count();
2532
let filtered = suite.filtered_benchmark_count(&filter);
2633
println!(

database/src/pool.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,19 @@ pub trait Connection: Send + Sync {
1515
async fn transaction(&mut self) -> Box<dyn Transaction + '_>;
1616

1717
async fn load_index(&mut self) -> Index;
18+
19+
/// None means that the caller doesn't know; it should be left alone if
20+
/// known or set to false if unknown.
21+
async fn record_compile_benchmark(
22+
&self,
23+
krate: &str,
24+
supports_stable: Option<bool>,
25+
category: String,
26+
);
1827
async fn get_compile_benchmarks(&self) -> Vec<CompileBenchmark>;
1928

29+
async fn record_runtime_benchmark(&self, name: &str);
30+
2031
async fn artifact_by_name(&self, artifact: &str) -> Option<ArtifactId>;
2132

2233
/// This records the duration of a collection run, i.e., collecting all of
@@ -25,14 +36,7 @@ pub trait Connection: Send + Sync {
2536

2637
async fn collection_id(&self, version: &str) -> CollectionId;
2738
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber;
28-
/// None means that the caller doesn't know; it should be left alone if
29-
/// known or set to false if unknown.
30-
async fn record_compile_benchmark(
31-
&self,
32-
krate: &str,
33-
supports_stable: Option<bool>,
34-
category: String,
35-
);
39+
3640
async fn record_statistic(
3741
&self,
3842
collection: CollectionId,

database/src/pool/postgres.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ where
922922
.unwrap();
923923
}
924924
}
925+
async fn record_runtime_benchmark(&self, _name: &str) {
926+
unimplemented!()
927+
}
925928

926929
async fn collector_start(&self, aid: ArtifactIdNumber, steps: &[String]) {
927930
// Clean up -- we'll re-insert any missing things in the loop below.

database/src/pool/sqlite.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,15 @@ impl Connection for SqliteConnection {
543543
}
544544
benchmarks
545545
}
546+
async fn record_runtime_benchmark(&self, name: &str) {
547+
self.raw_ref()
548+
.execute(
549+
"insert into runtime_benchmark (name) VALUES (?)
550+
ON CONFLICT (name) do nothing",
551+
params![name],
552+
)
553+
.unwrap();
554+
}
546555

547556
async fn get_pstats(
548557
&self,

0 commit comments

Comments
 (0)