@@ -25,7 +25,6 @@ use crate::db::{ArtifactId, Profile, Scenario};
25
25
use crate :: interpolate:: Interpolate ;
26
26
use crate :: load:: SiteCtxt ;
27
27
28
- use async_trait:: async_trait;
29
28
use collector:: Bound ;
30
29
use database:: { Benchmark , Commit , Index , Lookup , Metric , QueryLabel } ;
31
30
@@ -268,13 +267,6 @@ impl<T> SeriesResponse<T> {
268
267
}
269
268
}
270
269
271
- pub trait Series : Sized
272
- where
273
- Self : Iterator < Item = ( ArtifactId , <Self as Series >:: Element ) > ,
274
- {
275
- type Element : Sized ;
276
- }
277
-
278
270
#[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
279
271
pub struct Path {
280
272
path : Vec < PathComponent > ,
@@ -381,46 +373,6 @@ impl Query {
381
373
}
382
374
}
383
375
384
- #[ async_trait]
385
- pub trait SeriesElement : Sized {
386
- async fn query < ' a > (
387
- ctxt : & ' a SiteCtxt ,
388
- artifact_ids : Arc < Vec < ArtifactId > > ,
389
- query : Query ,
390
- ) -> Result < Vec < SeriesResponse < Box < dyn Iterator < Item = ( ArtifactId , Self ) > + Send + ' a > > > , String > ;
391
- }
392
-
393
- fn handle_results < ' a , E > (
394
- results : Vec <
395
- Result < Vec < SeriesResponse < Box < dyn Iterator < Item = ( ArtifactId , E ) > + Send + ' a > > > , String > ,
396
- > ,
397
- ) -> Result < Vec < SeriesResponse < Box < dyn Iterator < Item = ( ArtifactId , E ) > + Send + ' a > > > , String > {
398
- let mut ok = None ;
399
- let mut errs = Vec :: new ( ) ;
400
- for res in results {
401
- match ( res, ok. is_some ( ) ) {
402
- ( Ok ( r) , false ) => {
403
- ok = Some ( r) ;
404
- }
405
- ( Ok ( _) , true ) => panic ! ( "two series successfully expanded" ) ,
406
- ( Err ( e) , _) => errs. push ( e) ,
407
- }
408
- }
409
-
410
- ok. ok_or_else ( || {
411
- format ! (
412
- "Failed to process query; fix one of these errors: {}" ,
413
- errs. into_iter( ) . fold( String :: new( ) , |mut acc, err| {
414
- if !acc. is_empty( ) {
415
- acc. push_str( "; or " ) ;
416
- }
417
- acc. push_str( & err) ;
418
- acc
419
- } )
420
- )
421
- } )
422
- }
423
-
424
376
#[ derive( Debug , Clone ) ]
425
377
pub struct SelfProfileData {
426
378
pub query_data : Vec < QueryData > ,
@@ -454,88 +406,29 @@ impl QueryData {
454
406
}
455
407
}
456
408
457
- #[ async_trait]
458
- impl SeriesElement for Option < SelfProfileData > {
459
- async fn query < ' a > (
460
- ctxt : & ' a SiteCtxt ,
461
- artifact_ids : Arc < Vec < ArtifactId > > ,
409
+ impl SiteCtxt {
410
+ pub async fn statistic_series (
411
+ & self ,
462
412
query : Query ,
463
- ) -> Result <
464
- Vec <
465
- SeriesResponse <
466
- Box < dyn Iterator < Item = ( ArtifactId , Option < SelfProfileData > ) > + Send + ' a > ,
467
- > ,
468
- > ,
469
- String ,
470
- > {
471
- let results = vec ! [ SelfProfile :: expand_query( artifact_ids, ctxt, query. clone( ) )
472
- . await
473
- . map( |sr| {
474
- sr. into_iter( )
475
- . map( |sr| {
476
- sr. map( |r| {
477
- Box :: new( r)
478
- as Box <
479
- dyn Iterator <Item = ( ArtifactId , Option <SelfProfileData >) >
480
- + Send ,
481
- >
482
- } )
483
- } )
484
- . collect( )
485
- } ) ] ;
486
- handle_results ( results)
487
- }
488
- }
489
-
490
- #[ async_trait]
491
- impl SeriesElement for Option < f64 > {
492
- async fn query < ' a > (
493
- ctxt : & ' a SiteCtxt ,
494
413
artifact_ids : Arc < Vec < ArtifactId > > ,
495
- query : Query ,
496
- ) -> Result <
497
- Vec < SeriesResponse < Box < dyn Iterator < Item = ( ArtifactId , Option < f64 > ) > + Send + ' a > > > ,
498
- String ,
499
- > {
500
- let results = vec ! [
501
- StatisticSeries :: expand_query( artifact_ids. clone( ) , ctxt, query. clone( ) )
502
- . await
503
- . map( |sr| {
504
- sr. into_iter( )
505
- . map( |sr| {
506
- sr. map( |r| {
507
- Box :: new( r)
508
- as Box <dyn Iterator <Item = ( ArtifactId , Option <f64 >) > + Send >
509
- } )
510
- } )
511
- . collect( )
512
- } ) ,
513
- SelfProfileQueryTime :: expand_query( artifact_ids. clone( ) , ctxt, query. clone( ) )
514
- . await
515
- . map( |sr| {
516
- sr. into_iter( )
517
- . map( |sr| {
518
- sr. map( |r| {
519
- Box :: new( r)
520
- as Box <dyn Iterator <Item = ( ArtifactId , Option <f64 >) > + Send >
521
- } )
522
- } )
523
- . collect( )
524
- } ) ,
525
- ] ;
414
+ ) -> Result < Vec < SeriesResponse < StatisticSeries > > , String > {
415
+ StatisticSeries :: execute_query ( artifact_ids. clone ( ) , self , query. clone ( ) ) . await
416
+ }
526
417
527
- handle_results ( results)
418
+ pub async fn self_profile (
419
+ & self ,
420
+ query : Query ,
421
+ artifact_ids : Arc < Vec < ArtifactId > > ,
422
+ ) -> Result < Vec < SeriesResponse < SelfProfile > > , String > {
423
+ SelfProfile :: execute_query ( artifact_ids, self , query. clone ( ) ) . await
528
424
}
529
- }
530
425
531
- impl SiteCtxt {
532
- pub async fn query < ' a , E : SeriesElement > (
533
- & ' a self ,
426
+ pub async fn self_profile_query_time (
427
+ & self ,
534
428
query : Query ,
535
429
artifact_ids : Arc < Vec < ArtifactId > > ,
536
- ) -> Result < Vec < SeriesResponse < Box < dyn Iterator < Item = ( ArtifactId , E ) > + Send + ' a > > > , String >
537
- {
538
- E :: query ( self , artifact_ids, query) . await
430
+ ) -> Result < Vec < SeriesResponse < SelfProfileQueryTime > > , String > {
431
+ SelfProfileQueryTime :: execute_query ( artifact_ids, self , query. clone ( ) ) . await
539
432
}
540
433
}
541
434
@@ -544,12 +437,8 @@ pub struct StatisticSeries {
544
437
points : std:: vec:: IntoIter < Option < f64 > > ,
545
438
}
546
439
547
- impl Series for StatisticSeries {
548
- type Element = Option < f64 > ;
549
- }
550
-
551
440
impl StatisticSeries {
552
- async fn expand_query (
441
+ async fn execute_query (
553
442
artifact_ids : Arc < Vec < ArtifactId > > ,
554
443
ctxt : & SiteCtxt ,
555
444
mut query : Query ,
@@ -710,25 +599,8 @@ impl SelfProfile {
710
599
points : res. into_iter ( ) ,
711
600
}
712
601
}
713
- }
714
-
715
- impl Iterator for SelfProfile {
716
- type Item = ( ArtifactId , Option < SelfProfileData > ) ;
717
- fn next ( & mut self ) -> Option < Self :: Item > {
718
- Some ( ( self . artifact_ids . next ( ) ?, self . points . next ( ) . unwrap ( ) ) )
719
- }
720
-
721
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
722
- self . artifact_ids . size_hint ( )
723
- }
724
- }
725
-
726
- impl Series for SelfProfile {
727
- type Element = Option < SelfProfileData > ;
728
- }
729
602
730
- impl SelfProfile {
731
- async fn expand_query (
603
+ async fn execute_query (
732
604
artifact_ids : Arc < Vec < ArtifactId > > ,
733
605
ctxt : & SiteCtxt ,
734
606
mut query : Query ,
@@ -765,6 +637,17 @@ impl SelfProfile {
765
637
}
766
638
}
767
639
640
+ impl Iterator for SelfProfile {
641
+ type Item = ( ArtifactId , Option < SelfProfileData > ) ;
642
+ fn next ( & mut self ) -> Option < Self :: Item > {
643
+ Some ( ( self . artifact_ids . next ( ) ?, self . points . next ( ) . unwrap ( ) ) )
644
+ }
645
+
646
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
647
+ self . artifact_ids . size_hint ( )
648
+ }
649
+ }
650
+
768
651
pub struct SelfProfileQueryTime {
769
652
artifact_ids : ArtifactIdIter ,
770
653
points : std:: vec:: IntoIter < Option < f64 > > ,
@@ -802,25 +685,8 @@ impl SelfProfileQueryTime {
802
685
points : res. into_iter ( ) ,
803
686
}
804
687
}
805
- }
806
-
807
- impl Iterator for SelfProfileQueryTime {
808
- type Item = ( ArtifactId , Option < f64 > ) ;
809
- fn next ( & mut self ) -> Option < Self :: Item > {
810
- Some ( ( self . artifact_ids . next ( ) ?, self . points . next ( ) . unwrap ( ) ) )
811
- }
812
688
813
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
814
- self . artifact_ids . size_hint ( )
815
- }
816
- }
817
-
818
- impl Series for SelfProfileQueryTime {
819
- type Element = Option < f64 > ;
820
- }
821
-
822
- impl SelfProfileQueryTime {
823
- async fn expand_query (
689
+ async fn execute_query (
824
690
artifact_ids : Arc < Vec < ArtifactId > > ,
825
691
ctxt : & SiteCtxt ,
826
692
mut query : Query ,
@@ -834,35 +700,35 @@ impl SelfProfileQueryTime {
834
700
let index = ctxt. index . load ( ) ;
835
701
let mut series = index
836
702
. all_query_series ( )
837
- . filter ( |tup| {
838
- benchmark. matches ( tup. 0 )
839
- && profile. matches ( tup. 1 )
840
- && scenario. matches ( tup. 2 )
841
- && ql. matches ( tup. 3 )
703
+ . filter ( |& & ( b, p, s, q) | {
704
+ benchmark. matches ( b) && profile. matches ( p) && scenario. matches ( s) && ql. matches ( q)
842
705
} )
843
706
. collect :: < Vec < _ > > ( ) ;
844
707
845
708
series. sort_unstable ( ) ;
846
709
847
710
let mut res = Vec :: with_capacity ( series. len ( ) ) ;
848
- for path in series {
711
+ for & ( b , p , s , q ) in series {
849
712
res. push ( SeriesResponse {
850
- series : SelfProfileQueryTime :: new (
851
- artifact_ids. clone ( ) ,
852
- ctxt,
853
- path. 0 ,
854
- path. 1 ,
855
- path. 2 ,
856
- path. 3 ,
857
- )
858
- . await ,
713
+ series : SelfProfileQueryTime :: new ( artifact_ids. clone ( ) , ctxt, b, p, s, q) . await ,
859
714
path : Path :: new ( )
860
- . set ( PathComponent :: Benchmark ( path . 0 ) )
861
- . set ( PathComponent :: Profile ( path . 1 ) )
862
- . set ( PathComponent :: Scenario ( path . 2 ) )
863
- . set ( PathComponent :: QueryLabel ( path . 3 ) ) ,
715
+ . set ( PathComponent :: Benchmark ( b ) )
716
+ . set ( PathComponent :: Profile ( p ) )
717
+ . set ( PathComponent :: Scenario ( s ) )
718
+ . set ( PathComponent :: QueryLabel ( q ) ) ,
864
719
} ) ;
865
720
}
866
721
Ok ( res)
867
722
}
868
723
}
724
+
725
+ impl Iterator for SelfProfileQueryTime {
726
+ type Item = ( ArtifactId , Option < f64 > ) ;
727
+ fn next ( & mut self ) -> Option < Self :: Item > {
728
+ Some ( ( self . artifact_ids . next ( ) ?, self . points . next ( ) . unwrap ( ) ) )
729
+ }
730
+
731
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
732
+ self . artifact_ids . size_hint ( )
733
+ }
734
+ }
0 commit comments