@@ -2,25 +2,31 @@ use collector::Bound;
2
2
use std:: collections:: HashMap ;
3
3
use std:: sync:: Arc ;
4
4
5
- use crate :: api:: graph :: GraphKind ;
6
- use crate :: api:: { graph, ServerResult } ;
5
+ use crate :: api:: graphs :: GraphKind ;
6
+ use crate :: api:: { graph, graphs , ServerResult } ;
7
7
use crate :: db:: { self , ArtifactId , Benchmark , Profile , Scenario } ;
8
8
use crate :: interpolate:: IsInterpolated ;
9
9
use crate :: load:: SiteCtxt ;
10
10
use crate :: selector:: { Query , Selector , SeriesResponse , Tag } ;
11
11
12
+ pub async fn handle_graph ( body : graph:: Request , ctxt : & SiteCtxt ) -> ServerResult < graph:: Response > {
13
+ log:: info!( "handle_graph({:?})" , body) ;
14
+
15
+ create_graph ( body, ctxt) . await
16
+ }
17
+
12
18
pub async fn handle_graphs (
13
- body : graph :: Request ,
19
+ body : graphs :: Request ,
14
20
ctxt : & SiteCtxt ,
15
- ) -> ServerResult < Arc < graph :: Response > > {
16
- log:: info!( "handle_graph ({:?})" , body) ;
21
+ ) -> ServerResult < Arc < graphs :: Response > > {
22
+ log:: info!( "handle_graphs ({:?})" , body) ;
17
23
18
24
let is_default_query = body
19
- == graph :: Request {
25
+ == graphs :: Request {
20
26
start : Bound :: None ,
21
27
end : Bound :: None ,
22
28
stat : String :: from ( "instructions:u" ) ,
23
- kind : graph :: GraphKind :: Raw ,
29
+ kind : graphs :: GraphKind :: Raw ,
24
30
} ;
25
31
26
32
if is_default_query {
@@ -30,21 +36,41 @@ pub async fn handle_graphs(
30
36
}
31
37
}
32
38
33
- let resp = graph_response ( body, ctxt) . await ?;
39
+ let resp = create_graphs ( body, ctxt) . await ?;
34
40
35
41
if is_default_query {
36
42
ctxt. landing_page . store ( Arc :: new ( Some ( resp. clone ( ) ) ) ) ;
37
43
}
38
44
39
45
Ok ( resp)
40
46
}
47
+ async fn create_graph ( body : graph:: Request , ctxt : & SiteCtxt ) -> ServerResult < graph:: Response > {
48
+ let artifact_ids = artifact_ids_for_range ( ctxt, body. start , body. end ) ;
49
+ let mut series_iterator = ctxt
50
+ . statistic_series (
51
+ Query :: new ( )
52
+ . set :: < String > ( Tag :: Benchmark , Selector :: One ( body. benchmark ) )
53
+ . set :: < String > ( Tag :: Profile , Selector :: One ( body. profile ) )
54
+ . set :: < String > ( Tag :: Scenario , Selector :: One ( body. scenario ) )
55
+ . set :: < String > ( Tag :: Metric , Selector :: One ( body. metric ) ) ,
56
+ Arc :: new ( artifact_ids) ,
57
+ )
58
+ . await ?
59
+ . into_iter ( )
60
+ . map ( SeriesResponse :: interpolate) ;
61
+
62
+ let result = series_iterator. next ( ) . unwrap ( ) ;
63
+ let graph_series = graph_series ( result. series , body. kind ) ;
64
+ Ok ( graph:: Response {
65
+ series : graph_series,
66
+ } )
67
+ }
41
68
42
- async fn graph_response (
43
- body : graph :: Request ,
69
+ async fn create_graphs (
70
+ body : graphs :: Request ,
44
71
ctxt : & SiteCtxt ,
45
- ) -> ServerResult < Arc < graph:: Response > > {
46
- let range = ctxt. data_range ( body. start ..=body. end ) ;
47
- let commits: Arc < Vec < _ > > = Arc :: new ( range. into_iter ( ) . map ( |c| c. into ( ) ) . collect ( ) ) ;
72
+ ) -> ServerResult < Arc < graphs:: Response > > {
73
+ let artifact_ids = Arc :: new ( artifact_ids_for_range ( ctxt, body. start , body. end ) ) ;
48
74
let mut benchmarks = HashMap :: new ( ) ;
49
75
50
76
let interpolated_responses: Vec < _ > = ctxt
@@ -54,7 +80,7 @@ async fn graph_response(
54
80
. set :: < String > ( Tag :: Profile , Selector :: All )
55
81
. set :: < String > ( Tag :: Scenario , Selector :: All )
56
82
. set :: < String > ( Tag :: Metric , Selector :: One ( body. stat ) ) ,
57
- commits . clone ( ) ,
83
+ artifact_ids . clone ( ) ,
58
84
)
59
85
. await ?
60
86
. into_iter ( )
@@ -79,8 +105,8 @@ async fn graph_response(
79
105
. insert ( scenario, graph_series) ;
80
106
}
81
107
82
- Ok ( Arc :: new ( graph :: Response {
83
- commits : Arc :: try_unwrap ( commits )
108
+ Ok ( Arc :: new ( graphs :: Response {
109
+ commits : Arc :: try_unwrap ( artifact_ids )
84
110
. unwrap ( )
85
111
. into_iter ( )
86
112
. map ( |c| match c {
@@ -92,13 +118,18 @@ async fn graph_response(
92
118
} ) )
93
119
}
94
120
121
+ fn artifact_ids_for_range ( ctxt : & SiteCtxt , start : Bound , end : Bound ) -> Vec < ArtifactId > {
122
+ let range = ctxt. data_range ( start..=end) ;
123
+ range. into_iter ( ) . map ( |c| c. into ( ) ) . collect ( )
124
+ }
125
+
95
126
/// Creates a summary "benchmark" that averages the results of all other
96
127
/// test cases per profile type
97
128
fn create_summary (
98
129
ctxt : & SiteCtxt ,
99
130
interpolated_responses : & [ SeriesResponse < Vec < ( ( ArtifactId , Option < f64 > ) , IsInterpolated ) > > ] ,
100
131
graph_kind : GraphKind ,
101
- ) -> ServerResult < HashMap < Profile , HashMap < String , graph :: Series > > > {
132
+ ) -> ServerResult < HashMap < Profile , HashMap < String , graphs :: Series > > > {
102
133
let mut baselines = HashMap :: new ( ) ;
103
134
let mut summary_benchmark = HashMap :: new ( ) ;
104
135
let summary_query_cases = iproduct ! (
@@ -152,8 +183,8 @@ fn create_summary(
152
183
fn graph_series (
153
184
points : impl Iterator < Item = ( ( ArtifactId , Option < f64 > ) , IsInterpolated ) > ,
154
185
kind : GraphKind ,
155
- ) -> graph :: Series {
156
- let mut graph_series = graph :: Series {
186
+ ) -> graphs :: Series {
187
+ let mut graph_series = graphs :: Series {
157
188
points : Vec :: new ( ) ,
158
189
interpolated_indices : Default :: default ( ) ,
159
190
} ;
0 commit comments