Skip to content

Commit 581a35b

Browse files
committed
Send benchmark data (currently category) from DB to the compare site
1 parent 541347e commit 581a35b

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

database/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,9 @@ impl fmt::Display for CollectionId {
763763
write!(f, "{}", self.0)
764764
}
765765
}
766+
767+
#[derive(Debug, Clone, Serialize)]
768+
pub struct BenchmarkData {
769+
name: String,
770+
category: String
771+
}

database/src/pool.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ArtifactId, ArtifactIdNumber};
1+
use crate::{ArtifactId, ArtifactIdNumber, BenchmarkData};
22
use crate::{CollectionId, Index, Profile, QueryDatum, QueuedCommit, Scenario, Step};
33
use chrono::{DateTime, Utc};
44
use hashbrown::HashMap;
@@ -15,6 +15,7 @@ pub trait Connection: Send + Sync {
1515
async fn transaction(&mut self) -> Box<dyn Transaction + '_>;
1616

1717
async fn load_index(&mut self) -> Index;
18+
async fn get_benchmarks(&self) -> Vec<BenchmarkData>;
1819

1920
async fn artifact_by_name(&self, artifact: &str) -> Option<ArtifactId>;
2021

database/src/pool/postgres.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
2-
use crate::{
3-
ArtifactId, ArtifactIdNumber, Benchmark, CollectionId, Commit, Date, Index, Profile,
4-
QueuedCommit, Scenario,
5-
};
2+
use crate::{ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkData, CollectionId, Commit, Date, Index, Profile, QueuedCommit, Scenario};
63
use anyhow::Context as _;
74
use chrono::{DateTime, TimeZone, Utc};
85
use hashbrown::HashMap;
@@ -282,6 +279,7 @@ pub struct CachedStatements {
282279
collection_id: Statement,
283280
record_duration: Statement,
284281
in_progress_steps: Statement,
282+
get_benchmarks: Statement,
285283
}
286284

287285
pub struct PostgresTransaction<'a> {
@@ -456,6 +454,10 @@ impl PostgresConnection {
456454
))::int4
457455
from collector_progress where aid = $1 order by step
458456
").await.unwrap(),
457+
get_benchmarks: conn.prepare("
458+
select name, category
459+
from benchmark
460+
").await.unwrap()
459461
}),
460462
conn,
461463
}
@@ -596,6 +598,23 @@ where
596598
.collect(),
597599
}
598600
}
601+
async fn get_benchmarks(&self) -> Vec<BenchmarkData> {
602+
let rows = self.conn()
603+
.query(&self.statements().get_benchmarks, &[])
604+
.await
605+
.unwrap();
606+
rows.into_iter()
607+
.map(|r| {
608+
let name: String = r.get(0);
609+
let category: String = r.get(1);
610+
BenchmarkData {
611+
name,
612+
category
613+
}
614+
})
615+
.collect()
616+
}
617+
599618
async fn get_pstats(
600619
&self,
601620
pstat_series_row_ids: &[u32],

database/src/pool/sqlite.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
2-
use crate::{ArtifactId, Benchmark, CollectionId, Commit, Date, Profile};
2+
use crate::{ArtifactId, Benchmark, BenchmarkData, CollectionId, Commit, Date, Profile};
33
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
44
use chrono::{DateTime, TimeZone, Utc};
55
use hashbrown::HashMap;
@@ -504,6 +504,20 @@ impl Connection for SqliteConnection {
504504
}
505505
}
506506

507+
async fn get_benchmarks(&self) -> Vec<BenchmarkData> {
508+
let conn = self.raw_ref();
509+
let mut query = conn.prepare_cached("select name, category from benchmark").unwrap();
510+
let rows = query.query_map([], |row| Ok(BenchmarkData {
511+
name: row.get(0)?,
512+
category: row.get(1)?
513+
})).unwrap();
514+
let mut benchmarks = Vec::new();
515+
for row in rows {
516+
benchmarks.push(row.unwrap());
517+
}
518+
benchmarks
519+
}
520+
507521
async fn get_pstats(
508522
&self,
509523
series: &[u32],

site/src/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub mod bootstrap {
128128

129129
pub mod comparison {
130130
use collector::Bound;
131-
use database::Date;
131+
use database::{BenchmarkData, Date};
132132
use serde::{Deserialize, Serialize};
133133
use std::collections::HashMap;
134134

@@ -156,6 +156,7 @@ pub mod comparison {
156156
/// If `a` and `b` are adjacent artifacts (i.e., `a` is the parent of
157157
/// `b`).
158158
pub is_contiguous: bool,
159+
pub benchmark_data: Vec<BenchmarkData>,
159160
}
160161

161162
#[derive(Debug, Clone, Serialize)]

site/src/comparison.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ pub async fn handle_compare(
109109
let prev = comparison.prev(&master_commits);
110110
let next = comparison.next(&master_commits);
111111
let is_contiguous = comparison.is_contiguous(&*conn, &master_commits).await;
112+
let benchmark_map = conn.get_benchmarks().await;
113+
112114
let comparisons = comparison
113115
.statistics
114116
.into_iter()
@@ -135,6 +137,7 @@ pub async fn handle_compare(
135137
new_errors,
136138
next,
137139
is_contiguous,
140+
benchmark_data: benchmark_map
138141
})
139142
}
140143

0 commit comments

Comments
 (0)