@@ -215,6 +215,21 @@ static MIGRATIONS: &[&str] = &[
215
215
r#"
216
216
alter table pull_request_build add column commit_date timestamptz;
217
217
"# ,
218
+ r#"
219
+ create table runtime_pstat_series(
220
+ id integer primary key generated always as identity,
221
+ benchmark text not null,
222
+ metric text not null,
223
+ UNIQUE(benchmark, metric)
224
+ );
225
+ create table runtime_pstat(
226
+ series integer references runtime_pstat_series(id) on delete cascade on update cascade,
227
+ aid integer references artifact(id) on delete cascade on update cascade,
228
+ cid integer references collection(id) on delete cascade on update cascade,
229
+ value double precision not null,
230
+ PRIMARY KEY(series, aid, cid)
231
+ );
232
+ "# ,
218
233
] ;
219
234
220
235
#[ async_trait:: async_trait]
@@ -293,6 +308,10 @@ pub struct CachedStatements {
293
308
record_duration : Statement ,
294
309
in_progress_steps : Statement ,
295
310
get_benchmarks : Statement ,
311
+ insert_runtime_pstat_series : Statement ,
312
+ select_runtime_pstat_series : Statement ,
313
+ insert_runtime_pstat : Statement ,
314
+ get_runtime_pstat : Statement ,
296
315
}
297
316
298
317
pub struct PostgresTransaction < ' a > {
@@ -449,7 +468,36 @@ impl PostgresConnection {
449
468
get_benchmarks : conn. prepare ( "
450
469
select name, category
451
470
from benchmark
452
- " ) . await . unwrap ( )
471
+ " ) . await . unwrap ( ) ,
472
+ insert_runtime_pstat_series : conn. prepare ( "insert into runtime_pstat_series (benchmark, metric) VALUES ($1, $2) ON CONFLICT DO NOTHING RETURNING id" ) . await . unwrap ( ) ,
473
+ select_runtime_pstat_series : conn. prepare ( "select id from runtime_pstat_series where benchmark = $1 and metric = $2" ) . await . unwrap ( ) ,
474
+ insert_runtime_pstat : conn
475
+ . prepare ( "insert into runtime_pstat (series, aid, cid, value) VALUES ($1, $2, $3, $4)" )
476
+ . await
477
+ . unwrap ( ) ,
478
+ get_runtime_pstat : conn
479
+ . prepare ( "
480
+ WITH aids AS (
481
+ select aid, num from unnest($2::int[]) with ordinality aids(aid, num)
482
+ ),
483
+ sids AS (
484
+ select sid, idx from unnest($1::int[]) with ordinality sids(sid, idx)
485
+ )
486
+ select ARRAY(
487
+ (
488
+ select min(runtime_pstat.value) from aids
489
+ left outer join runtime_pstat
490
+ on (aids.aid = runtime_pstat.aid and runtime_pstat.series = sids.sid)
491
+ group by aids.num
492
+ order by aids.num
493
+ )
494
+ ) from
495
+ sids
496
+ group by (sids.idx, sids.sid)
497
+ order by sids.idx
498
+ " )
499
+ . await
500
+ . unwrap ( )
453
501
} ) ,
454
502
conn,
455
503
}
@@ -616,6 +664,31 @@ where
616
664
. map ( |row| row. get :: < _ , Vec < Option < f64 > > > ( 0 ) )
617
665
. collect ( )
618
666
}
667
+ async fn get_runtime_pstats (
668
+ & self ,
669
+ runtime_pstat_series_row_ids : & [ u32 ] ,
670
+ artifact_row_ids : & [ Option < crate :: ArtifactIdNumber > ] ,
671
+ ) -> Vec < Vec < Option < f64 > > > {
672
+ let runtime_pstat_series_row_ids = runtime_pstat_series_row_ids
673
+ . iter ( )
674
+ . map ( |sid| * sid as i32 )
675
+ . collect :: < Vec < _ > > ( ) ;
676
+ let artifact_row_ids = artifact_row_ids
677
+ . iter ( )
678
+ . map ( |id| id. map ( |id| id. 0 as i32 ) )
679
+ . collect :: < Vec < _ > > ( ) ;
680
+ let rows = self
681
+ . conn ( )
682
+ . query (
683
+ & self . statements ( ) . get_runtime_pstat ,
684
+ & [ & runtime_pstat_series_row_ids, & artifact_row_ids] ,
685
+ )
686
+ . await
687
+ . unwrap ( ) ;
688
+ rows. into_iter ( )
689
+ . map ( |row| row. get :: < _ , Vec < Option < f64 > > > ( 0 ) )
690
+ . collect ( )
691
+ }
619
692
async fn get_error ( & self , artifact_row_id : crate :: ArtifactIdNumber ) -> HashMap < String , String > {
620
693
let rows = self
621
694
. conn ( )
@@ -763,13 +836,47 @@ where
763
836
}
764
837
async fn record_runtime_statistic (
765
838
& self ,
766
- _collection : CollectionId ,
767
- _artifact : ArtifactIdNumber ,
768
- _benchmark : & str ,
769
- _metric : & str ,
770
- _value : f64 ,
839
+ collection : CollectionId ,
840
+ artifact : ArtifactIdNumber ,
841
+ benchmark : & str ,
842
+ metric : & str ,
843
+ value : f64 ,
771
844
) {
772
- unimplemented ! ( )
845
+ let sid = self
846
+ . conn ( )
847
+ . query_opt (
848
+ & self . statements ( ) . select_runtime_pstat_series ,
849
+ & [ & benchmark, & metric] ,
850
+ )
851
+ . await
852
+ . unwrap ( ) ;
853
+ let sid: i32 = match sid {
854
+ Some ( id) => id. get ( 0 ) ,
855
+ None => {
856
+ self . conn ( )
857
+ . query_opt (
858
+ & self . statements ( ) . insert_runtime_pstat_series ,
859
+ & [ & benchmark, & metric] ,
860
+ )
861
+ . await
862
+ . unwrap ( ) ;
863
+ self . conn ( )
864
+ . query_one (
865
+ & self . statements ( ) . select_runtime_pstat_series ,
866
+ & [ & benchmark, & metric] ,
867
+ )
868
+ . await
869
+ . unwrap ( )
870
+ . get ( 0 )
871
+ }
872
+ } ;
873
+ self . conn ( )
874
+ . execute (
875
+ & self . statements ( ) . insert_runtime_pstat ,
876
+ & [ & sid, & ( artifact. 0 as i32 ) , & { collection. 0 } , & value] ,
877
+ )
878
+ . await
879
+ . unwrap ( ) ;
773
880
}
774
881
775
882
async fn record_rustc_crate (
@@ -954,9 +1061,6 @@ where
954
1061
. unwrap ( ) ;
955
1062
}
956
1063
}
957
- async fn record_runtime_benchmark ( & self , _name : & str ) {
958
- unimplemented ! ( )
959
- }
960
1064
961
1065
async fn collector_start ( & self , aid : ArtifactIdNumber , steps : & [ String ] ) {
962
1066
// Clean up -- we'll re-insert any missing things in the loop below.
0 commit comments