Skip to content

Commit b625127

Browse files
committed
Store benchmark category into the database
1 parent 17f20a6 commit b625127

File tree

6 files changed

+47
-19
lines changed

6 files changed

+47
-19
lines changed

collector/src/execute.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ fn default_runs() -> usize {
110110
3
111111
}
112112

113+
#[derive(Debug, Clone, serde::Deserialize)]
114+
#[serde(rename_all = "lowercase")]
115+
enum BenchmarkCategory {
116+
Primary,
117+
Secondary
118+
}
119+
120+
impl Default for BenchmarkCategory {
121+
fn default() -> Self {
122+
Self::Secondary
123+
}
124+
}
125+
113126
/// This is the internal representation of an individual benchmark's
114127
/// perf-config.json file.
115128
#[derive(Debug, Clone, serde::Deserialize)]
@@ -130,6 +143,9 @@ struct BenchmarkConfig {
130143
/// directory that `Cargo.toml` is in.
131144
#[serde(default)]
132145
touch_file: Option<String>,
146+
147+
#[serde(default)]
148+
category: BenchmarkCategory
133149
}
134150

135151
impl Default for BenchmarkConfig {
@@ -142,6 +158,7 @@ impl Default for BenchmarkConfig {
142158
runs: default_runs(),
143159
supports_stable: false,
144160
touch_file: None,
161+
category: BenchmarkCategory::Secondary
145162
}
146163
}
147164
}
@@ -1239,6 +1256,13 @@ impl Benchmark {
12391256
self.config.supports_stable
12401257
}
12411258

1259+
pub fn category_name(&self) -> &str {
1260+
match self.config.category {
1261+
BenchmarkCategory::Primary => "primary",
1262+
BenchmarkCategory::Secondary => "secondary"
1263+
}
1264+
}
1265+
12421266
#[cfg(windows)]
12431267
fn copy(from: &Path, to: &Path) -> anyhow::Result<()> {
12441268
collector::robocopy(from, to, &[])

collector/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ fn bench(
188188
let mut measure_and_record =
189189
|benchmark_name: &BenchmarkName,
190190
benchmark_supports_stable: bool,
191+
benchmark_category: &str,
191192
print_intro: &dyn Fn(),
192193
measure: &dyn Fn(&mut BenchProcessor) -> anyhow::Result<()>| {
193194
let is_fresh =
@@ -200,7 +201,7 @@ fn bench(
200201
let mut tx = rt.block_on(conn.transaction());
201202
rt.block_on(
202203
tx.conn()
203-
.record_benchmark(&benchmark_name.0, Some(benchmark_supports_stable)),
204+
.record_benchmark(&benchmark_name.0, Some(benchmark_supports_stable), benchmark_category),
204205
);
205206
print_intro();
206207

@@ -237,6 +238,7 @@ fn bench(
237238
measure_and_record(
238239
&benchmark.name,
239240
benchmark.supports_stable(),
241+
benchmark.category_name(),
240242
&|| {
241243
eprintln!(
242244
"{}",
@@ -252,6 +254,7 @@ fn bench(
252254
measure_and_record(
253255
&BenchmarkName("rustc".to_string()),
254256
/* supports_stable */ false,
257+
"primary",
255258
&|| eprintln!("Special benchmark commencing (due to `--bench-rustc`)"),
256259
&|processor| processor.measure_rustc(compiler).context("measure rustc"),
257260
);

database/src/bin/import-sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn main() {
4141
for &(benchmark, profile, scenario, metric) in sqlite_idx.all_statistic_descriptions() {
4242
if benchmarks.insert(benchmark) {
4343
postgres_conn
44-
.record_benchmark(benchmark.as_str(), None)
44+
.record_benchmark(benchmark.as_str(), None, "") // TODO
4545
.await;
4646
}
4747

database/src/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub trait Connection: Send + Sync {
2626
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber;
2727
/// None means that the caller doesn't know; it should be left alone if
2828
/// known or set to false if unknown.
29-
async fn record_benchmark(&self, krate: &str, supports_stable: Option<bool>);
29+
async fn record_benchmark(&self, krate: &str, supports_stable: Option<bool>, category: &str);
3030
async fn record_statistic(
3131
&self,
3232
collection: CollectionId,

database/src/pool/postgres.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -966,35 +966,35 @@ where
966966
.await
967967
.unwrap();
968968
}
969-
async fn record_benchmark(&self, benchmark: &str, supports_stable: Option<bool>) {
969+
async fn record_benchmark(&self, benchmark: &str, supports_stable: Option<bool>, category: &str) {
970970
if let Some(r) = self
971971
.conn()
972972
.query_opt(
973-
"select stabilized from benchmark where name = $1",
973+
"select stabilized, category from benchmark where name = $1",
974974
&[&benchmark],
975975
)
976976
.await
977977
.unwrap()
978978
{
979-
if Some(r.get::<_, bool>(0)) == supports_stable {
979+
if Some(r.get::<_, bool>(0)) == supports_stable && r.get::<_, &str>(1) == category {
980980
return;
981981
}
982982
}
983983
if let Some(stable) = supports_stable {
984984
self.conn()
985985
.execute(
986-
"insert into benchmark (name, stabilized) VALUES ($1, $2)
987-
ON CONFLICT (name) DO UPDATE SET stabilized = EXCLUDED.stabilized",
988-
&[&benchmark, &stable],
986+
"insert into benchmark (name, stabilized, category) VALUES ($1, $2, $3)
987+
ON CONFLICT (name) DO UPDATE SET stabilized = EXCLUDED.stabilized, category = EXCLUDED.category",
988+
&[&benchmark, &stable, &category],
989989
)
990990
.await
991991
.unwrap();
992992
} else {
993993
self.conn()
994994
.execute(
995-
"insert into benchmark (name, stabilized) VALUES ($1, $2)
996-
ON CONFLICT DO NOTHING",
997-
&[&benchmark, &false],
995+
"insert into benchmark (name, stabilized, category) VALUES ($1, $2, $3)
996+
ON CONFLICT (name) DO UPDATE SET category = EXCLUDED.category",
997+
&[&benchmark, &false, &category],
998998
)
999999
.await
10001000
.unwrap();

database/src/pool/sqlite.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ static MIGRATIONS: &[Migration] = &[
317317
alter table benchmark_new rename to benchmark;
318318
"#,
319319
),
320+
Migration::new("alter table benchmark add column category text not null"),
320321
];
321322

322323
#[async_trait::async_trait]
@@ -863,21 +864,21 @@ impl Connection for SqliteConnection {
863864
)
864865
.unwrap();
865866
}
866-
async fn record_benchmark(&self, benchmark: &str, supports_stable: Option<bool>) {
867+
async fn record_benchmark(&self, benchmark: &str, supports_stable: Option<bool>, category: &str) {
867868
if let Some(stable) = supports_stable {
868869
self.raw_ref()
869870
.execute(
870-
"insert into benchmark (name, stabilized) VALUES (?, ?)
871-
ON CONFLICT (name) do update set stabilized = excluded.stabilized",
872-
params![benchmark, stable],
871+
"insert into benchmark (name, stabilized, category) VALUES (?, ?, ?)
872+
ON CONFLICT (name) do update set stabilized = excluded.stabilized, category = excluded.category",
873+
params![benchmark, stable, category],
873874
)
874875
.unwrap();
875876
} else {
876877
self.raw_ref()
877878
.execute(
878-
"insert into benchmark (name, stabilized) VALUES (?, ?)
879-
ON CONFLICT DO NOTHING",
880-
params![benchmark, false],
879+
"insert into benchmark (name, stabilized, category) VALUES (?, ?, ?)
880+
ON CONFLICT (name) do update set category = excluded.category",
881+
params![benchmark, false, category],
881882
)
882883
.unwrap();
883884
}

0 commit comments

Comments
 (0)