@@ -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
}
@@ -522,23 +570,31 @@ where
522
570
)
523
571
} )
524
572
. collect ( ) ,
525
- errors : self
573
+ pstat_series : self
526
574
. conn ( )
527
- . query ( "select id, crate from error_series" , & [ ] )
575
+ . query (
576
+ "select id, crate, profile, cache, statistic from pstat_series;" ,
577
+ & [ ] ,
578
+ )
528
579
. await
529
580
. unwrap ( )
530
581
. into_iter ( )
531
582
. map ( |row| {
532
583
(
533
584
row. get :: < _ , i32 > ( 0 ) as u32 ,
534
- row. get :: < _ , String > ( 1 ) . as_str ( ) . into ( ) ,
585
+ (
586
+ Benchmark :: from ( row. get :: < _ , String > ( 1 ) . as_str ( ) ) ,
587
+ Profile :: from_str ( row. get :: < _ , String > ( 2 ) . as_str ( ) ) . unwrap ( ) ,
588
+ row. get :: < _ , String > ( 3 ) . as_str ( ) . parse ( ) . unwrap ( ) ,
589
+ row. get :: < _ , String > ( 4 ) . as_str ( ) . into ( ) ,
590
+ ) ,
535
591
)
536
592
} )
537
593
. collect ( ) ,
538
- pstat_series : self
594
+ runtime_pstat_series : self
539
595
. conn ( )
540
596
. query (
541
- "select id, crate, profile, cache, statistic from pstat_series ;" ,
597
+ "select id, benchmark, metric from runtime_pstat_series ;" ,
542
598
& [ ] ,
543
599
)
544
600
. await
@@ -548,10 +604,8 @@ where
548
604
(
549
605
row. get :: < _ , i32 > ( 0 ) as u32 ,
550
606
(
551
- Benchmark :: from ( row. get :: < _ , String > ( 1 ) . as_str ( ) ) ,
552
- Profile :: from_str ( row. get :: < _ , String > ( 2 ) . as_str ( ) ) . unwrap ( ) ,
553
- row. get :: < _ , String > ( 3 ) . as_str ( ) . parse ( ) . unwrap ( ) ,
554
- row. get :: < _ , String > ( 4 ) . as_str ( ) . into ( ) ,
607
+ row. get :: < _ , String > ( 1 ) . as_str ( ) . into ( ) ,
608
+ row. get :: < _ , String > ( 2 ) . as_str ( ) . into ( ) ,
555
609
) ,
556
610
)
557
611
} )
@@ -597,6 +651,31 @@ where
597
651
. map ( |row| row. get :: < _ , Vec < Option < f64 > > > ( 0 ) )
598
652
. collect ( )
599
653
}
654
+ async fn get_runtime_pstats (
655
+ & self ,
656
+ runtime_pstat_series_row_ids : & [ u32 ] ,
657
+ artifact_row_ids : & [ Option < crate :: ArtifactIdNumber > ] ,
658
+ ) -> Vec < Vec < Option < f64 > > > {
659
+ let runtime_pstat_series_row_ids = runtime_pstat_series_row_ids
660
+ . iter ( )
661
+ . map ( |sid| * sid as i32 )
662
+ . collect :: < Vec < _ > > ( ) ;
663
+ let artifact_row_ids = artifact_row_ids
664
+ . iter ( )
665
+ . map ( |id| id. map ( |id| id. 0 as i32 ) )
666
+ . collect :: < Vec < _ > > ( ) ;
667
+ let rows = self
668
+ . conn ( )
669
+ . query (
670
+ & self . statements ( ) . get_runtime_pstat ,
671
+ & [ & runtime_pstat_series_row_ids, & artifact_row_ids] ,
672
+ )
673
+ . await
674
+ . unwrap ( ) ;
675
+ rows. into_iter ( )
676
+ . map ( |row| row. get :: < _ , Vec < Option < f64 > > > ( 0 ) )
677
+ . collect ( )
678
+ }
600
679
async fn get_error ( & self , artifact_row_id : crate :: ArtifactIdNumber ) -> HashMap < String , String > {
601
680
let rows = self
602
681
. conn ( )
@@ -744,13 +823,47 @@ where
744
823
}
745
824
async fn record_runtime_statistic (
746
825
& self ,
747
- _collection : CollectionId ,
748
- _artifact : ArtifactIdNumber ,
749
- _benchmark : & str ,
750
- _metric : & str ,
751
- _value : f64 ,
826
+ collection : CollectionId ,
827
+ artifact : ArtifactIdNumber ,
828
+ benchmark : & str ,
829
+ metric : & str ,
830
+ value : f64 ,
752
831
) {
753
- unimplemented ! ( )
832
+ let sid = self
833
+ . conn ( )
834
+ . query_opt (
835
+ & self . statements ( ) . select_runtime_pstat_series ,
836
+ & [ & benchmark, & metric] ,
837
+ )
838
+ . await
839
+ . unwrap ( ) ;
840
+ let sid: i32 = match sid {
841
+ Some ( id) => id. get ( 0 ) ,
842
+ None => {
843
+ self . conn ( )
844
+ . query_opt (
845
+ & self . statements ( ) . insert_runtime_pstat_series ,
846
+ & [ & benchmark, & metric] ,
847
+ )
848
+ . await
849
+ . unwrap ( ) ;
850
+ self . conn ( )
851
+ . query_one (
852
+ & self . statements ( ) . select_runtime_pstat_series ,
853
+ & [ & benchmark, & metric] ,
854
+ )
855
+ . await
856
+ . unwrap ( )
857
+ . get ( 0 )
858
+ }
859
+ } ;
860
+ self . conn ( )
861
+ . execute (
862
+ & self . statements ( ) . insert_runtime_pstat ,
863
+ & [ & sid, & ( artifact. 0 as i32 ) , & { collection. 0 } , & value] ,
864
+ )
865
+ . await
866
+ . unwrap ( ) ;
754
867
}
755
868
756
869
async fn record_rustc_crate (
@@ -935,9 +1048,6 @@ where
935
1048
. unwrap ( ) ;
936
1049
}
937
1050
}
938
- async fn record_runtime_benchmark ( & self , _name : & str ) {
939
- unimplemented ! ( )
940
- }
941
1051
942
1052
async fn collector_start ( & self , aid : ArtifactIdNumber , steps : & [ String ] ) {
943
1053
// Clean up -- we'll re-insert any missing things in the loop below.
0 commit comments