Skip to content

Commit 346318f

Browse files
committed
Stor
1 parent 5539158 commit 346318f

File tree

7 files changed

+62
-39
lines changed

7 files changed

+62
-39
lines changed

collector/src/execute.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{Compiler, Profile, Scenario};
44
use anyhow::{bail, Context};
55
use collector::command_output;
66
use collector::etw_parser;
7-
use database::{PatchName, QueryLabel};
7+
use database::{Category, PatchName, QueryLabel};
88
use futures::stream::FuturesUnordered;
99
use futures::stream::StreamExt;
1010
use std::collections::HashMap;
@@ -110,27 +110,6 @@ fn default_runs() -> usize {
110110
3
111111
}
112112

113-
#[derive(Debug, Clone, serde::Deserialize)]
114-
#[serde(rename_all = "lowercase")]
115-
pub enum Category {
116-
Primary,
117-
Secondary,
118-
}
119-
120-
impl Default for Category {
121-
fn default() -> Self {
122-
Self::Secondary
123-
}
124-
}
125-
126-
impl fmt::Display for Category {
127-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
128-
match self {
129-
Category::Primary => f.write_str("primary"),
130-
Category::Secondary => f.write_str("secondary"),
131-
}
132-
}
133-
}
134113
/// This is the internal representation of an individual benchmark's
135114
/// perf-config.json file.
136115
#[derive(Debug, Clone, serde::Deserialize)]

collector/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use anyhow::{bail, Context};
44
use clap::Parser;
5-
use database::{ArtifactId, Commit};
5+
use database::{ArtifactId, Category, Commit};
66
use log::debug;
77
use std::collections::HashSet;
88
use std::fs;
@@ -15,7 +15,6 @@ use tokio::runtime::Runtime;
1515
mod execute;
1616
mod sysroot;
1717

18-
use crate::execute::Category;
1918
use execute::{BenchProcessor, Benchmark, BenchmarkName, ProfileProcessor, Profiler};
2019
use sysroot::Sysroot;
2120

@@ -189,7 +188,7 @@ fn bench(
189188
let mut measure_and_record =
190189
|benchmark_name: &BenchmarkName,
191190
benchmark_supports_stable: bool,
192-
benchmark_category: &str,
191+
benchmark_category: Category,
193192
print_intro: &dyn Fn(),
194193
measure: &dyn Fn(&mut BenchProcessor) -> anyhow::Result<()>| {
195194
let is_fresh =
@@ -240,7 +239,7 @@ fn bench(
240239
measure_and_record(
241240
&benchmark.name,
242241
benchmark.supports_stable(),
243-
&benchmark.category().to_string(),
242+
benchmark.category().clone(),
244243
&|| {
245244
eprintln!(
246245
"{}",
@@ -256,7 +255,7 @@ fn bench(
256255
measure_and_record(
257256
&BenchmarkName("rustc".to_string()),
258257
/* supports_stable */ false,
259-
&Category::Primary.to_string(),
258+
Category::Primary,
260259
&|| eprintln!("Special benchmark commencing (due to `--bench-rustc`)"),
261260
&|processor| processor.measure_rustc(compiler).context("measure rustc"),
262261
);

database/src/bin/import-sqlite.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use database::{Lookup, Pool};
1+
use database::{Category, Lookup, Pool};
22
use std::collections::HashSet;
33

44
#[tokio::main]
@@ -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, "") // TODO
44+
.record_benchmark(benchmark.as_str(), None, Category::Secondary)
4545
.await;
4646
}
4747

database/src/lib.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,5 +767,38 @@ impl fmt::Display for CollectionId {
767767
#[derive(Debug, Clone, Serialize)]
768768
pub struct BenchmarkData {
769769
name: String,
770-
category: String,
770+
category: Category,
771+
}
772+
773+
#[derive(Debug, Clone, Serialize, Deserialize)]
774+
#[serde(rename_all = "lowercase")]
775+
pub enum Category {
776+
Primary,
777+
Secondary,
778+
}
779+
780+
impl Default for Category {
781+
fn default() -> Self {
782+
Self::Secondary
783+
}
784+
}
785+
786+
impl fmt::Display for Category {
787+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
788+
match self {
789+
Category::Primary => f.write_str("primary"),
790+
Category::Secondary => f.write_str("secondary"),
791+
}
792+
}
793+
}
794+
impl std::str::FromStr for Category {
795+
type Err = anyhow::Error;
796+
797+
fn from_str(input: &str) -> Result<Self, Self::Err> {
798+
match input {
799+
"primary" => Ok(Category::Primary),
800+
"secondary" => Ok(Category::Primary),
801+
_ => Err(anyhow::anyhow!("Invalid category {input}")),
802+
}
803+
}
771804
}

database/src/pool.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ArtifactId, ArtifactIdNumber, BenchmarkData};
1+
use crate::{ArtifactId, ArtifactIdNumber, BenchmarkData, Category};
22
use crate::{CollectionId, Index, Profile, QueryDatum, QueuedCommit, Scenario, Step};
33
use chrono::{DateTime, Utc};
44
use hashbrown::HashMap;
@@ -27,7 +27,12 @@ pub trait Connection: Send + Sync {
2727
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber;
2828
/// None means that the caller doesn't know; it should be left alone if
2929
/// known or set to false if unknown.
30-
async fn record_benchmark(&self, krate: &str, supports_stable: Option<bool>, category: &str);
30+
async fn record_benchmark(
31+
&self,
32+
krate: &str,
33+
supports_stable: Option<bool>,
34+
category: Category,
35+
);
3136
async fn record_statistic(
3237
&self,
3338
collection: CollectionId,

database/src/pool/postgres.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkData, CollectionId, Commit, Date, Index,
4-
Profile, QueuedCommit, Scenario,
3+
ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkData, Category, CollectionId, Commit, Date,
4+
Index, Profile, QueuedCommit, Scenario,
55
};
66
use anyhow::Context as _;
77
use chrono::{DateTime, TimeZone, Utc};
88
use hashbrown::HashMap;
99
use native_tls::{Certificate, TlsConnector};
1010
use postgres_native_tls::MakeTlsConnector;
1111
use std::convert::TryFrom;
12+
use std::str::FromStr;
1213
use std::sync::Arc;
1314
use std::time::Duration;
1415
use tokio_postgres::GenericClient;
@@ -611,7 +612,10 @@ where
611612
.map(|r| {
612613
let name: String = r.get(0);
613614
let category: String = r.get(1);
614-
BenchmarkData { name, category }
615+
BenchmarkData {
616+
name,
617+
category: Category::from_str(&category).unwrap(),
618+
}
615619
})
616620
.collect()
617621
}
@@ -990,8 +994,9 @@ where
990994
&self,
991995
benchmark: &str,
992996
supports_stable: Option<bool>,
993-
category: &str,
997+
category: Category,
994998
) {
999+
let category = category.to_string();
9951000
if let Some(r) = self
9961001
.conn()
9971002
.query_opt(

database/src/pool/sqlite.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
2-
use crate::{ArtifactId, Benchmark, BenchmarkData, CollectionId, Commit, Date, Profile};
2+
use crate::{ArtifactId, Benchmark, BenchmarkData, Category, CollectionId, Commit, Date, Profile};
33
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
44
use chrono::{DateTime, TimeZone, Utc};
55
use hashbrown::HashMap;
66
use rusqlite::params;
77
use rusqlite::OptionalExtension;
88
use std::convert::TryFrom;
99
use std::path::PathBuf;
10+
use std::str::FromStr;
1011
use std::sync::Mutex;
1112
use std::sync::Once;
1213
use std::time::Duration;
@@ -513,7 +514,7 @@ impl Connection for SqliteConnection {
513514
.query_map([], |row| {
514515
Ok(BenchmarkData {
515516
name: row.get(0)?,
516-
category: row.get(1)?,
517+
category: Category::from_str(&row.get::<_, String>(1)?).unwrap(),
517518
})
518519
})
519520
.unwrap();
@@ -888,8 +889,9 @@ impl Connection for SqliteConnection {
888889
&self,
889890
benchmark: &str,
890891
supports_stable: Option<bool>,
891-
category: &str,
892+
category: Category,
892893
) {
894+
let category = category.to_string();
893895
if let Some(stable) = supports_stable {
894896
self.raw_ref()
895897
.execute(

0 commit comments

Comments
 (0)