Skip to content

Commit 7051619

Browse files
committed
Add runtime benchmark site query
1 parent df45b9a commit 7051619

File tree

4 files changed

+124
-18
lines changed

4 files changed

+124
-18
lines changed

database/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ pub struct Index {
411411
/// Id lookup of compile stat description ids
412412
/// For legacy reasons called `pstat_series` in the database, and so the name is kept here.
413413
pstat_series: Indexed<(Benchmark, Profile, Scenario, Metric)>,
414+
/// Id lookup of runtime stat description ids
415+
runtime_pstat_series: Indexed<(Benchmark, Metric)>,
414416
}
415417

416418
/// An index lookup
@@ -627,6 +629,15 @@ impl Index {
627629
.map(|(test_case, &row_id)| (test_case, row_id))
628630
}
629631

632+
pub fn runtime_statistic_descriptions(
633+
&self,
634+
) -> impl Iterator<Item = (&(Benchmark, Metric), StatisticalDescriptionId)> + '_ {
635+
self.runtime_pstat_series
636+
.map
637+
.iter()
638+
.map(|(test_case, &row_id)| (test_case, row_id))
639+
}
640+
630641
pub fn artifact_id_for_commit(&self, commit: &str) -> Option<ArtifactId> {
631642
self.commits()
632643
.into_iter()

database/src/pool/postgres.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,25 @@ where
556556
)
557557
})
558558
.collect(),
559+
runtime_pstat_series: self
560+
.conn()
561+
.query(
562+
"select id, benchmark, metric from runtime_pstat_series;",
563+
&[],
564+
)
565+
.await
566+
.unwrap()
567+
.into_iter()
568+
.map(|row| {
569+
(
570+
row.get::<_, i32>(0) as u32,
571+
(
572+
row.get::<_, String>(1).as_str().into(),
573+
row.get::<_, String>(2).as_str().into(),
574+
),
575+
)
576+
})
577+
.collect(),
559578
}
560579
}
561580
async fn get_compile_benchmarks(&self) -> Vec<CompileBenchmark> {

database/src/pool/sqlite.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -475,28 +475,46 @@ impl Connection for SqliteConnection {
475475
.unwrap()
476476
.map(|r| r.unwrap())
477477
.collect();
478+
let pstat_series = self
479+
.raw()
480+
.prepare("select id, crate, profile, cache, statistic from pstat_series;")
481+
.unwrap()
482+
.query_map(params![], |row| {
483+
Ok((
484+
row.get::<_, i32>(0)? as u32,
485+
(
486+
Benchmark::from(row.get::<_, String>(1)?.as_str()),
487+
Profile::from_str(row.get::<_, String>(2)?.as_str()).unwrap(),
488+
row.get::<_, String>(3)?.as_str().parse().unwrap(),
489+
row.get::<_, String>(4)?.as_str().into(),
490+
),
491+
))
492+
})
493+
.unwrap()
494+
.map(|r| r.unwrap())
495+
.collect();
496+
let runtime_pstat_series = self
497+
.raw()
498+
.prepare("select id, benchmark, metric from runtime_pstat_series;")
499+
.unwrap()
500+
.query_map(params![], |row| {
501+
Ok((
502+
row.get::<_, i32>(0)? as u32,
503+
(
504+
row.get::<_, String>(1)?.as_str().into(),
505+
row.get::<_, String>(2)?.as_str().into(),
506+
),
507+
))
508+
})
509+
.unwrap()
510+
.map(|r| r.unwrap())
511+
.collect();
478512
Index {
479513
commits,
480514
artifacts,
481515
errors,
482-
pstat_series: self
483-
.raw()
484-
.prepare("select id, crate, profile, cache, statistic from pstat_series;")
485-
.unwrap()
486-
.query_map(params![], |row| {
487-
Ok((
488-
row.get::<_, i32>(0)? as u32,
489-
(
490-
Benchmark::from(row.get::<_, String>(1)?.as_str()),
491-
Profile::from_str(row.get::<_, String>(2)?.as_str()).unwrap(),
492-
row.get::<_, String>(3)?.as_str().parse().unwrap(),
493-
row.get::<_, String>(4)?.as_str().into(),
494-
),
495-
))
496-
})
497-
.unwrap()
498-
.map(|r| r.unwrap())
499-
.collect(),
516+
pstat_series,
517+
runtime_pstat_series,
500518
}
501519
}
502520

site/src/selector.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pub trait BenchmarkQuery: Debug {
189189
) -> Vec<(Self::TestCase, database::Metric, u32)>;
190190
}
191191

192+
// Compile benchmarks querying
192193
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
193194
pub struct CompileBenchmarkQuery {
194195
benchmark: Selector<String>,
@@ -278,6 +279,63 @@ pub struct CompileTestCase {
278279

279280
impl TestCase for CompileTestCase {}
280281

282+
// Runtime benchmarks querying
283+
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
284+
pub struct RuntimeBenchmarkQuery {
285+
benchmark: Selector<String>,
286+
metric: Selector<database::Metric>,
287+
}
288+
289+
impl RuntimeBenchmarkQuery {
290+
pub fn benchmark(mut self, selector: Selector<String>) -> Self {
291+
self.benchmark = selector;
292+
self
293+
}
294+
295+
pub fn metric(mut self, selector: Selector<Metric>) -> Self {
296+
self.metric = selector.map(|v| v.as_str().into());
297+
self
298+
}
299+
300+
pub fn all_for_metric(metric: Metric) -> Self {
301+
Self {
302+
benchmark: Selector::All,
303+
metric: Selector::One(metric.as_str().into()),
304+
}
305+
}
306+
}
307+
308+
impl Default for RuntimeBenchmarkQuery {
309+
fn default() -> Self {
310+
Self {
311+
benchmark: Selector::All,
312+
metric: Selector::All,
313+
}
314+
}
315+
}
316+
317+
impl BenchmarkQuery for RuntimeBenchmarkQuery {
318+
type TestCase = RuntimeTestCase;
319+
320+
fn get_statistic_descriptions(
321+
&self,
322+
index: &Index,
323+
) -> Vec<(Self::TestCase, database::Metric, u32)> {
324+
index
325+
.runtime_statistic_descriptions()
326+
.filter(|(&(b, m), _)| self.benchmark.matches(b) && self.metric.matches(m))
327+
.map(|(&(benchmark, metric), sid)| (RuntimeTestCase { benchmark }, metric, sid))
328+
.collect()
329+
}
330+
}
331+
332+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
333+
pub struct RuntimeTestCase {
334+
pub benchmark: Benchmark,
335+
}
336+
337+
impl TestCase for RuntimeTestCase {}
338+
281339
impl SiteCtxt {
282340
pub async fn statistic_series<Q: BenchmarkQuery>(
283341
&self,

0 commit comments

Comments
 (0)