Skip to content

Commit 23db0cf

Browse files
committed
Add target to runtime benchmarks
1 parent f111973 commit 23db0cf

File tree

9 files changed

+91
-24
lines changed

9 files changed

+91
-24
lines changed

collector/src/bin/collector.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,21 @@ struct RuntimeBenchmarkConfig {
121121
runtime_suite: BenchmarkSuite,
122122
filter: RuntimeBenchmarkFilter,
123123
iterations: u32,
124+
target: Target,
124125
}
125126

126127
impl RuntimeBenchmarkConfig {
127-
fn new(suite: BenchmarkSuite, filter: RuntimeBenchmarkFilter, iterations: u32) -> Self {
128+
fn new(
129+
suite: BenchmarkSuite,
130+
filter: RuntimeBenchmarkFilter,
131+
iterations: u32,
132+
target: Target,
133+
) -> Self {
128134
Self {
129135
runtime_suite: suite.filter(&filter),
130136
filter,
131137
iterations,
138+
target,
132139
}
133140
}
134141
}
@@ -860,8 +867,9 @@ fn main_result() -> anyhow::Result<i32> {
860867
purge,
861868
} => {
862869
log_db(&db);
863-
let toolchain =
864-
get_local_toolchain_for_runtime_benchmarks(&local, &require_host_target_tuple())?;
870+
871+
let host_tuple = require_host_target_tuple();
872+
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &host_tuple)?;
865873
let pool = Pool::open(&db.db);
866874

867875
let isolation_mode = if no_isolate {
@@ -899,6 +907,7 @@ fn main_result() -> anyhow::Result<i32> {
899907
runtime_suite,
900908
RuntimeBenchmarkFilter::new(local.exclude, local.include),
901909
iterations,
910+
Target::from_str(&host_tuple).expect("Found unexpected host target"),
902911
);
903912
rt.block_on(run_benchmarks(conn.as_mut(), shared, None, Some(config)))?;
904913
Ok(0)
@@ -1189,6 +1198,7 @@ fn main_result() -> anyhow::Result<i32> {
11891198
runtime_suite,
11901199
filter: RuntimeBenchmarkFilter::keep_all(),
11911200
iterations: DEFAULT_RUNTIME_ITERATIONS,
1201+
target: Target::default(),
11921202
};
11931203
let shared = SharedBenchmarkConfig {
11941204
artifact_id,
@@ -1806,6 +1816,7 @@ async fn create_benchmark_configs(
18061816
runtime_suite,
18071817
filter: RuntimeBenchmarkFilter::keep_all(),
18081818
iterations: DEFAULT_RUNTIME_ITERATIONS,
1819+
target: job.target().into(),
18091820
})
18101821
} else {
18111822
None
@@ -2232,6 +2243,7 @@ async fn run_benchmarks(
22322243
&collector,
22332244
runtime.filter,
22342245
runtime.iterations,
2246+
runtime.target,
22352247
)
22362248
.await
22372249
.context("Runtime benchmarks failed")
@@ -2306,6 +2318,7 @@ async fn bench_published_artifact(
23062318
runtime_suite,
23072319
RuntimeBenchmarkFilter::keep_all(),
23082320
DEFAULT_RUNTIME_ITERATIONS,
2321+
Target::default(),
23092322
)),
23102323
)
23112324
.await

collector/src/runtime/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{command_output, CollectorCtx};
2020
mod benchmark;
2121
mod profile;
2222

23+
use crate::compile::benchmark::target::Target;
2324
pub use benchmark::RuntimeCompilationOpts;
2425
pub use profile::{profile_runtime, RuntimeProfiler};
2526

@@ -35,6 +36,7 @@ pub async fn bench_runtime(
3536
collector: &CollectorCtx,
3637
filter: RuntimeBenchmarkFilter,
3738
iterations: u32,
39+
target: Target,
3840
) -> anyhow::Result<()> {
3941
let filtered = suite.filtered_benchmark_count(&filter);
4042
println!("Executing {filtered} benchmarks\n");
@@ -74,6 +76,7 @@ pub async fn bench_runtime(
7476
tx.conn(),
7577
collector.artifact_row_id,
7678
&rustc_perf_version,
79+
target,
7780
result,
7881
)
7982
.await;
@@ -126,13 +129,15 @@ async fn record_stats(
126129
conn: &dyn Connection,
127130
artifact_id: ArtifactIdNumber,
128131
rustc_perf_version: &str,
132+
target: Target,
129133
result: BenchmarkResult,
130134
) {
131135
async fn record<'a>(
132136
conn: &'a dyn Connection,
133137
artifact_id: ArtifactIdNumber,
134138
collection_id: CollectionId,
135139
result: &'a BenchmarkResult,
140+
target: Target,
136141
value: Option<u64>,
137142
metric: &'a str,
138143
) {
@@ -142,6 +147,7 @@ async fn record_stats(
142147
artifact_id,
143148
&result.name,
144149
metric,
150+
target.into(),
145151
value as f64,
146152
)
147153
.await;
@@ -156,6 +162,7 @@ async fn record_stats(
156162
artifact_id,
157163
collection_id,
158164
&result,
165+
target,
159166
stat.instructions,
160167
"instructions:u",
161168
)
@@ -165,6 +172,7 @@ async fn record_stats(
165172
artifact_id,
166173
collection_id,
167174
&result,
175+
target,
168176
stat.cycles,
169177
"cycles:u",
170178
)
@@ -174,6 +182,7 @@ async fn record_stats(
174182
artifact_id,
175183
collection_id,
176184
&result,
185+
target,
177186
stat.branch_misses,
178187
"branch-misses",
179188
)
@@ -183,6 +192,7 @@ async fn record_stats(
183192
artifact_id,
184193
collection_id,
185194
&result,
195+
target,
186196
stat.cache_misses,
187197
"cache-misses",
188198
)
@@ -192,6 +202,7 @@ async fn record_stats(
192202
artifact_id,
193203
collection_id,
194204
&result,
205+
target,
195206
Some(stat.wall_time.as_nanos() as u64),
196207
"wall-time",
197208
)

database/src/bin/import-sqlite.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async fn main() {
8282
}
8383
}
8484

85-
for (&(benchmark, metric), id) in sqlite_idx.runtime_statistic_descriptions() {
85+
for (&(benchmark, target, metric), id) in sqlite_idx.runtime_statistic_descriptions() {
8686
let stat = sqlite_conn
8787
.get_runtime_pstats(&[id], &[Some(sqlite_aid)])
8888
.await
@@ -92,7 +92,14 @@ async fn main() {
9292
.unwrap();
9393
if let Some(stat) = stat {
9494
postgres_conn
95-
.record_runtime_statistic(cid, postgres_aid, &benchmark, metric.as_str(), stat)
95+
.record_runtime_statistic(
96+
cid,
97+
postgres_aid,
98+
&benchmark,
99+
metric.as_str(),
100+
target,
101+
stat,
102+
)
96103
.await;
97104
}
98105
}

database/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ pub struct Index {
522522
/// For legacy reasons called `pstat_series` in the database, and so the name is kept here.
523523
pstat_series: Indexed<(Benchmark, Profile, Scenario, CodegenBackend, Target, Metric)>,
524524
/// Id lookup of runtime stat description ids
525-
runtime_pstat_series: Indexed<(Benchmark, Metric)>,
525+
runtime_pstat_series: Indexed<(Benchmark, Target, Metric)>,
526526
}
527527

528528
/// An index lookup
@@ -725,7 +725,7 @@ impl Index {
725725
self.runtime_pstat_series
726726
.map
727727
.keys()
728-
.map(|(_, metric)| metric)
728+
.map(|(_, _, metric)| metric)
729729
.collect::<std::collections::HashSet<_>>()
730730
.into_iter()
731731
.map(|s| s.to_string())
@@ -752,7 +752,7 @@ impl Index {
752752

753753
pub fn runtime_statistic_descriptions(
754754
&self,
755-
) -> impl Iterator<Item = (&(Benchmark, Metric), StatisticalDescriptionId)> + '_ {
755+
) -> impl Iterator<Item = (&(Benchmark, Target, Metric), StatisticalDescriptionId)> + '_ {
756756
self.runtime_pstat_series
757757
.map
758758
.iter()

database/src/pool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub trait Connection: Send + Sync {
6464
artifact: ArtifactIdNumber,
6565
benchmark: &str,
6666
metric: &str,
67+
target: Target,
6768
value: f64,
6869
);
6970
/// Records a self-profile artifact in S3.

database/src/pool/postgres.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ static MIGRATIONS: &[&str] = &[
432432
benchmark_set
433433
);
434434
"#,
435+
// Add target to runtime_pstat_series
436+
r#"
437+
ALTER TABLE runtime_pstat_series ADD target TEXT NOT NULL DEFAULT 'x86_64-unknown-linux-gnu';
438+
ALTER TABLE runtime_pstat_series DROP CONSTRAINT runtime_pstat_series_benchmark_metric_key;
439+
ALTER TABLE runtime_pstat_series ADD CONSTRAINT runtime_test_case UNIQUE(benchmark, target, metric);
440+
"#,
435441
];
436442

437443
#[async_trait::async_trait]
@@ -660,8 +666,8 @@ impl PostgresConnection {
660666
select name, category
661667
from benchmark
662668
").await.unwrap(),
663-
insert_runtime_pstat_series: conn.prepare("insert into runtime_pstat_series (benchmark, metric) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING id").await.unwrap(),
664-
select_runtime_pstat_series: conn.prepare("select id from runtime_pstat_series where benchmark = $1 and metric = $2").await.unwrap(),
669+
insert_runtime_pstat_series: conn.prepare("insert into runtime_pstat_series (benchmark, target, metric) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING RETURNING id").await.unwrap(),
670+
select_runtime_pstat_series: conn.prepare("select id from runtime_pstat_series where benchmark = $1 and target = $2 and metric = $3").await.unwrap(),
665671
insert_runtime_pstat: conn
666672
.prepare("insert into runtime_pstat (series, aid, cid, value) VALUES ($1, $2, $3, $4)")
667673
.await
@@ -883,7 +889,7 @@ where
883889
runtime_pstat_series: self
884890
.conn()
885891
.query(
886-
"select id, benchmark, metric from runtime_pstat_series;",
892+
"select id, benchmark, target, metric from runtime_pstat_series;",
887893
&[],
888894
)
889895
.await
@@ -893,8 +899,9 @@ where
893899
(
894900
row.get::<_, i32>(0) as u32,
895901
(
896-
row.get::<_, String>(1).as_str().into(),
897-
row.get::<_, String>(2).as_str().into(),
902+
row.get::<_, &str>(1).into(),
903+
Target::from_str(row.get::<_, &str>(2)).unwrap(),
904+
row.get::<_, &str>(3).into(),
898905
),
899906
)
900907
})
@@ -1123,13 +1130,15 @@ where
11231130
artifact: ArtifactIdNumber,
11241131
benchmark: &str,
11251132
metric: &str,
1133+
target: Target,
11261134
value: f64,
11271135
) {
1136+
let target = target.to_string();
11281137
let sid = self
11291138
.conn()
11301139
.query_opt(
11311140
&self.statements().select_runtime_pstat_series,
1132-
&[&benchmark, &metric],
1141+
&[&benchmark, &target, &metric],
11331142
)
11341143
.await
11351144
.unwrap();
@@ -1139,14 +1148,14 @@ where
11391148
self.conn()
11401149
.query_opt(
11411150
&self.statements().insert_runtime_pstat_series,
1142-
&[&benchmark, &metric],
1151+
&[&benchmark, &target, &metric],
11431152
)
11441153
.await
11451154
.unwrap();
11461155
self.conn()
11471156
.query_one(
11481157
&self.statements().select_runtime_pstat_series,
1149-
&[&benchmark, &metric],
1158+
&[&benchmark, &target, &metric],
11501159
)
11511160
.await
11521161
.unwrap()

database/src/pool/sqlite.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,21 @@ static MIGRATIONS: &[Migration] = &[
431431
CREATE INDEX error_artifact_idx ON error(aid);
432432
"#,
433433
),
434+
// Add runtime target as a unique constraint, defaulting to 'x86_64-unknown-linux-gnu'
435+
Migration::without_foreign_key_constraints(
436+
r#"
437+
create table runtime_pstat_series_with_target(
438+
id integer primary key not null,
439+
benchmark text not null,
440+
target text not null default 'x86_64-unknown-linux-gnu',
441+
metric text not null,
442+
UNIQUE(benchmark, target, metric)
443+
);
444+
insert into runtime_pstat_series_with_target select id, benchmark, 'x86_64-unknown-linux-gnu', metric from runtime_pstat_series;
445+
drop table runtime_pstat_series;
446+
alter table runtime_pstat_series_with_target rename to runtime_pstat_series;
447+
"#,
448+
),
434449
];
435450

436451
#[async_trait::async_trait]
@@ -579,14 +594,15 @@ impl Connection for SqliteConnection {
579594
.collect();
580595
let runtime_pstat_series = self
581596
.raw()
582-
.prepare("select id, benchmark, metric from runtime_pstat_series;")
597+
.prepare("select id, benchmark, target, metric from runtime_pstat_series;")
583598
.unwrap()
584599
.query_map(params![], |row| {
585600
Ok((
586601
row.get::<_, i32>(0)? as u32,
587602
(
588603
row.get::<_, String>(1)?.as_str().into(),
589-
row.get::<_, String>(2)?.as_str().into(),
604+
Target::from_str(row.get::<_, String>(2)?.as_str()).unwrap(),
605+
row.get::<_, String>(3)?.as_str().into(),
590606
),
591607
))
592608
})
@@ -750,19 +766,21 @@ impl Connection for SqliteConnection {
750766
artifact: ArtifactIdNumber,
751767
benchmark: &str,
752768
metric: &str,
769+
target: Target,
753770
value: f64,
754771
) {
772+
let target = target.to_string();
755773
self.raw_ref()
756774
.execute(
757-
"insert or ignore into runtime_pstat_series (benchmark, metric) VALUES (?, ?)",
758-
params![&benchmark, &metric,],
775+
"insert or ignore into runtime_pstat_series (benchmark, target, metric) VALUES (?, ?, ?)",
776+
params![&benchmark, &target, &metric],
759777
)
760778
.unwrap();
761779
let sid: i32 = self
762780
.raw_ref()
763781
.query_row(
764-
"select id from runtime_pstat_series where benchmark = ? and metric = ?",
765-
params![&benchmark, &metric,],
782+
"select id from runtime_pstat_series where benchmark = ? and target = ? and metric = ?",
783+
params![&benchmark, &target, &metric],
766784
|r| r.get(0),
767785
)
768786
.unwrap();

0 commit comments

Comments
 (0)