Skip to content

Commit c4ea20b

Browse files
committed
Record more metrics of runtime benchmarks into the DB
1 parent 0fcb3f8 commit c4ea20b

File tree

3 files changed

+75
-16
lines changed

3 files changed

+75
-16
lines changed

collector/src/bin/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn main_result() -> anyhow::Result<i32> {
734734
let pool = Pool::open(&db.db);
735735

736736
let fut = bench_runtime(
737-
pool,
737+
&pool,
738738
ArtifactId::Tag(toolchain.id.clone()),
739739
toolchain,
740740
BenchmarkFilter::new(local.exclude, local.include),

collector/src/runtime/mod.rs

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
mod benchmark;
22

33
use crate::toolchain::LocalToolchain;
4+
use std::future::Future;
45
use std::io::{BufRead, BufReader};
56
use std::path::{Path, PathBuf};
67
use std::process::{Command, Stdio};
78
use thousands::Separable;
89

910
use benchlib::comm::messages::{BenchmarkMessage, BenchmarkResult, BenchmarkStats};
1011
pub use benchmark::BenchmarkFilter;
11-
use database::{ArtifactId, ArtifactIdNumber, Connection, Pool};
12+
use database::{ArtifactId, ArtifactIdNumber, CollectionId, Connection, Pool};
1213

1314
use crate::utils::git::get_rustc_perf_commit;
1415

1516
/// Perform a series of runtime benchmarks using the provided `rustc` compiler.
1617
/// The runtime benchmarks are looked up in `benchmark_dir`, which is expected to be a path
17-
/// to a Cargo crate. All binaries built by that crate will are expected to be runtime benchmark
18-
/// groups that leverage `benchlib`.
18+
/// to a Cargo crate. All binaries built by that crate are expected to be runtime benchmark
19+
/// groups that use `benchlib`.
1920
pub async fn bench_runtime(
20-
db: Pool,
21+
db: &Pool,
2122
artifact_id: ArtifactId,
2223
toolchain: LocalToolchain,
2324
filter: BenchmarkFilter,
@@ -80,19 +81,76 @@ async fn record_stats(
8081
rustc_perf_version: &str,
8182
result: BenchmarkResult,
8283
) {
83-
for stat in result.stats {
84+
fn record<'a>(
85+
conn: &'a Box<dyn Connection>,
86+
artifact_id: ArtifactIdNumber,
87+
collection_id: CollectionId,
88+
result: &'a BenchmarkResult,
89+
value: Option<u64>,
90+
metric: &'a str,
91+
) -> impl Future<Output = ()> + 'a {
92+
async move {
93+
if let Some(value) = value {
94+
conn.record_runtime_statistic(
95+
collection_id,
96+
artifact_id,
97+
&result.name,
98+
metric,
99+
value as f64,
100+
)
101+
.await;
102+
}
103+
}
104+
}
105+
106+
for stat in &result.stats {
84107
let collection_id = conn.collection_id(rustc_perf_version).await;
85108

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-
}
109+
record(
110+
conn,
111+
artifact_id,
112+
collection_id,
113+
&result,
114+
stat.instructions,
115+
"instructions:u",
116+
)
117+
.await;
118+
record(
119+
conn,
120+
artifact_id,
121+
collection_id,
122+
&result,
123+
stat.cycles,
124+
"cycles:u",
125+
)
126+
.await;
127+
record(
128+
conn,
129+
artifact_id,
130+
collection_id,
131+
&result,
132+
stat.branch_misses,
133+
"branch-misses",
134+
)
135+
.await;
136+
record(
137+
conn,
138+
artifact_id,
139+
collection_id,
140+
&result,
141+
stat.cache_misses,
142+
"cache-misses",
143+
)
144+
.await;
145+
record(
146+
conn,
147+
artifact_id,
148+
collection_id,
149+
&result,
150+
Some(stat.wall_time.as_nanos() as u64),
151+
"wall-time",
152+
)
153+
.await;
96154
}
97155
}
98156

database/src/pool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub trait Connection: Send + Sync {
3434
/// the statistics for a particular artifact.
3535
async fn record_duration(&self, artifact: ArtifactIdNumber, duration: Duration);
3636

37+
/// One collection corresponds to all gathered metrics for a single iteration of a test case.
3738
async fn collection_id(&self, version: &str) -> CollectionId;
3839
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber;
3940

0 commit comments

Comments
 (0)