Skip to content

Commit 3db1557

Browse files
committed
Store runtime benchmark results into the DB
1 parent cb1ed34 commit 3db1557

File tree

9 files changed

+107
-29
lines changed

9 files changed

+107
-29
lines changed

collector/src/bin/collector.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,10 @@ fn main_result() -> anyhow::Result<i32> {
720720
"",
721721
)?;
722722
let pool = Pool::open(&db.db);
723+
723724
let fut = bench_runtime(
724725
pool,
726+
ArtifactId::Tag(toolchain.id.clone()),
725727
toolchain,
726728
BenchmarkFilter::new(local.exclude, local.include),
727729
runtime_benchmark_dir,

collector/src/execute/bencher.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::execute::{
77
SelfProfileFiles, Stats, Upload,
88
};
99
use crate::toolchain::Compiler;
10-
use anyhow::Context;
10+
use crate::utils::git::get_rustc_perf_commit;
1111
use futures::stream::FuturesUnordered;
1212
use futures::StreamExt;
1313
use std::path::PathBuf;
@@ -81,17 +81,7 @@ impl<'a> BenchProcessor<'a> {
8181
profile: Profile,
8282
stats: (Stats, Option<SelfProfile>, Option<SelfProfileFiles>),
8383
) {
84-
let version = String::from_utf8(
85-
Command::new("git")
86-
.arg("rev-parse")
87-
.arg("HEAD")
88-
.output()
89-
.context("git rev-parse HEAD")
90-
.unwrap()
91-
.stdout,
92-
)
93-
.context("utf8")
94-
.unwrap();
84+
let version = get_rustc_perf_commit();
9585

9686
let collection = self.rt.block_on(self.conn.collection_id(&version));
9787
let profile = match profile {

collector/src/execute/rustc.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! having to think about how to deduplicate results.
99
1010
use crate::toolchain::Compiler;
11+
use crate::utils::git::get_rustc_perf_commit;
1112
use anyhow::Context;
1213
use database::ArtifactId;
1314
use std::env;
@@ -140,17 +141,7 @@ fn record(
140141
}
141142
}
142143

143-
let version = String::from_utf8(
144-
Command::new("git")
145-
.arg("rev-parse")
146-
.arg("HEAD")
147-
.output()
148-
.context("git rev-parse HEAD")
149-
.unwrap()
150-
.stdout,
151-
)
152-
.context("utf8")
153-
.unwrap();
144+
let version = get_rustc_perf_commit();
154145
let collection = rt.block_on(conn.collection_id(&version));
155146

156147
for (krate, timing) in timing_data {

collector/src/runtime/mod.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
mod benchmark;
22

33
use crate::toolchain::LocalToolchain;
4-
use benchlib::comm::messages::{BenchmarkMessage, BenchmarkResult, BenchmarkStats};
54
use std::io::{BufRead, BufReader};
65
use std::path::{Path, PathBuf};
76
use std::process::{Command, Stdio};
87
use thousands::Separable;
98

9+
use benchlib::comm::messages::{BenchmarkMessage, BenchmarkResult, BenchmarkStats};
1010
pub use benchmark::BenchmarkFilter;
11-
use database::Pool;
11+
use database::{ArtifactId, ArtifactIdNumber, Connection, Pool};
12+
13+
use crate::utils::git::get_rustc_perf_commit;
1214

1315
/// Perform a series of runtime benchmarks using the provided `rustc` compiler.
1416
/// The runtime benchmarks are looked up in `benchmark_dir`, which is expected to be a path
1517
/// to a Cargo crate. All binaries built by that crate will are expected to be runtime benchmark
1618
/// groups that leverage `benchlib`.
1719
pub async fn bench_runtime(
1820
db: Pool,
21+
artifact_id: ArtifactId,
1922
toolchain: LocalToolchain,
2023
filter: BenchmarkFilter,
2124
benchmark_dir: PathBuf,
2225
iterations: u32,
2326
) -> anyhow::Result<()> {
2427
let suite = benchmark::discover_benchmarks(&toolchain, &benchmark_dir)?;
2528

26-
let connection = db.connection().await;
29+
let conn = db.connection().await;
2730
for benchmark in suite.benchmark_names() {
28-
connection.record_runtime_benchmark(benchmark).await;
31+
conn.record_runtime_benchmark(benchmark).await;
2932
}
3033

34+
let artifact_id = conn.artifact_id(&artifact_id).await;
35+
3136
let total_benchmark_count = suite.total_benchmark_count();
3237
let filtered = suite.filtered_benchmark_count(&filter);
3338
println!(
@@ -36,6 +41,8 @@ pub async fn bench_runtime(
3641
total_benchmark_count - filtered
3742
);
3843

44+
let rustc_perf_version = get_rustc_perf_commit();
45+
3946
let mut benchmark_index = 0;
4047
for binary in suite.groups {
4148
for message in execute_runtime_benchmark_binary(&binary.binary, &filter, iterations)? {
@@ -55,7 +62,9 @@ pub async fn bench_runtime(
5562
benchmark_index,
5663
filtered
5764
);
65+
5866
print_stats(&result);
67+
record_stats(&conn, artifact_id, &rustc_perf_version, result).await;
5968
}
6069
}
6170
}
@@ -64,6 +73,29 @@ pub async fn bench_runtime(
6473
Ok(())
6574
}
6675

76+
/// Records the results (stats) of a benchmark into the database.
77+
async fn record_stats(
78+
conn: &Box<dyn Connection>,
79+
artifact_id: ArtifactIdNumber,
80+
rustc_perf_version: &str,
81+
result: BenchmarkResult,
82+
) {
83+
for stat in result.stats {
84+
let collection_id = conn.collection_id(rustc_perf_version).await;
85+
86+
if let Some(value) = stat.instructions {
87+
conn.record_runtime_statistic(
88+
collection_id,
89+
artifact_id,
90+
&result.name,
91+
"instructions:u",
92+
value as f64,
93+
)
94+
.await;
95+
}
96+
}
97+
}
98+
6799
/// Starts executing a single runtime benchmark group defined in a binary crate located in
68100
/// `runtime-benchmarks`. The binary is expected to use benchlib's `BenchmarkGroup` to execute
69101
/// a set of runtime benchmarks and print `BenchmarkMessage`s encoded as JSON, one per line.
@@ -94,8 +126,7 @@ fn execute_runtime_benchmark_binary(
94126

95127
let reader = BufReader::new(stdout);
96128
let iterator = reader.lines().map(|line| {
97-
line.and_then(|line| Ok(serde_json::from_str::<BenchmarkMessage>(&line)?))
98-
.map_err(|err| err.into())
129+
Ok(line.and_then(|line| Ok(serde_json::from_str::<BenchmarkMessage>(&line)?))?)
99130
});
100131
Ok(iterator)
101132
}

collector/src/utils/git.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use anyhow::Context;
2+
use std::process::Command;
3+
4+
pub fn get_rustc_perf_commit() -> String {
5+
String::from_utf8(
6+
Command::new("git")
7+
.arg("rev-parse")
8+
.arg("HEAD")
9+
.output()
10+
.context("git rev-parse HEAD")
11+
.unwrap()
12+
.stdout,
13+
)
14+
.context("utf8")
15+
.unwrap()
16+
}

collector/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod fs;
2+
pub mod git;
23
pub mod read2;

database/src/pool.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ pub trait Connection: Send + Sync {
4747
metric: &str,
4848
value: f64,
4949
);
50+
async fn record_runtime_statistic(
51+
&self,
52+
collection: CollectionId,
53+
artifact: ArtifactIdNumber,
54+
benchmark: &str,
55+
metric: &str,
56+
value: f64,
57+
);
5058
/// Records a self-profile artifact in S3.
5159
///
5260
/// The upload is a separate step (which may fail or be canceled, but that's

database/src/pool/postgres.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,16 @@ where
739739
.await
740740
.unwrap();
741741
}
742+
async fn record_runtime_statistic(
743+
&self,
744+
_collection: CollectionId,
745+
_artifact: ArtifactIdNumber,
746+
_benchmark: &str,
747+
_metric: &str,
748+
_value: f64,
749+
) {
750+
unimplemented!()
751+
}
742752

743753
async fn record_rustc_crate(
744754
&self,

database/src/pool/sqlite.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,35 @@ impl Connection for SqliteConnection {
734734
)
735735
.unwrap();
736736
}
737+
async fn record_runtime_statistic(
738+
&self,
739+
collection: CollectionId,
740+
artifact: ArtifactIdNumber,
741+
benchmark: &str,
742+
metric: &str,
743+
value: f64,
744+
) {
745+
self.raw_ref()
746+
.execute(
747+
"insert or ignore into runtime_pstat_series (benchmark, metric) VALUES (?, ?)",
748+
params![&benchmark, &metric,],
749+
)
750+
.unwrap();
751+
let sid: i32 = self
752+
.raw_ref()
753+
.query_row(
754+
"select id from runtime_pstat_series where benchmark = ? and metric = ?",
755+
params![&benchmark, &metric,],
756+
|r| r.get(0),
757+
)
758+
.unwrap();
759+
self.raw_ref()
760+
.execute(
761+
"insert into runtime_pstat (series, aid, cid, value) VALUES (?, ?, ?, ?)",
762+
params![&sid, &artifact.0, &collection.0, &value],
763+
)
764+
.unwrap();
765+
}
737766

738767
async fn record_rustc_crate(
739768
&self,

0 commit comments

Comments
 (0)