Skip to content

Commit 58dceae

Browse files
authored
Merge pull request #2285 from Kobzol/runtime-benchmarks-target
Add target to runtime benchmarks
2 parents b1def84 + a2367af commit 58dceae

File tree

20 files changed

+190
-61
lines changed

20 files changed

+190
-61
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/bin/postgres-to-sqlite.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ impl Table for RuntimePstatSeries {
397397
}
398398

399399
fn postgres_select_statement(&self, _since_weeks_ago: Option<u32>) -> String {
400-
"select id, benchmark, metric from ".to_string() + self.name()
400+
"SELECT id, benchmark, target, metric FROM ".to_string() + self.name()
401401
}
402402

403403
fn sqlite_insert_statement(&self) -> &'static str {
404-
"insert into runtime_pstat_series (id, benchmark, metric) VALUES (?, ?, ?)"
404+
"INSERT INTO runtime_pstat_series (id, benchmark, target, metric) VALUES (?, ?, ?, ?)"
405405
}
406406

407407
fn sqlite_execute_insert(&self, statement: &mut rusqlite::Statement, row: tokio_postgres::Row) {
@@ -410,6 +410,7 @@ impl Table for RuntimePstatSeries {
410410
row.get::<_, i32>(0),
411411
row.get::<_, &str>(1),
412412
row.get::<_, &str>(2),
413+
row.get::<_, &str>(3),
413414
])
414415
.unwrap();
415416
}

database/src/bin/sqlite-to-postgres.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ struct RuntimePstatSeries;
543543
struct RuntimePstatSeriesRow<'a> {
544544
id: i32,
545545
benchmark: &'a str,
546+
target: &'a str,
546547
metric: &'a str,
547548
}
548549

@@ -552,11 +553,11 @@ impl Table for RuntimePstatSeries {
552553
}
553554

554555
fn sqlite_attributes() -> &'static str {
555-
"id, benchmark, metric"
556+
"id, benchmark, target, metric"
556557
}
557558

558559
fn postgres_attributes() -> &'static str {
559-
"id, benchmark, metric"
560+
"id, benchmark, target, metric"
560561
}
561562

562563
fn postgres_generated_id_attribute() -> Option<&'static str> {
@@ -568,7 +569,8 @@ impl Table for RuntimePstatSeries {
568569
.serialize(RuntimePstatSeriesRow {
569570
id: row.get(0).unwrap(),
570571
benchmark: row.get_ref(1).unwrap().as_str().unwrap(),
571-
metric: row.get_ref(2).unwrap().as_str().unwrap(),
572+
target: row.get_ref(2).unwrap().as_str().unwrap(),
573+
metric: row.get_ref(3).unwrap().as_str().unwrap(),
572574
})
573575
.unwrap();
574576
}

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()

0 commit comments

Comments
 (0)