@@ -2,25 +2,34 @@ 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 (
13
+ request : graph:: Request ,
14
+ ctxt : Arc < SiteCtxt > ,
15
+ ) -> ServerResult < graph:: Response > {
16
+ log:: info!( "handle_graph({:?})" , request) ;
17
+
18
+ create_graph ( request, ctxt) . await
19
+ }
20
+
12
21
pub async fn handle_graphs (
13
- body : graph :: Request ,
14
- ctxt : & SiteCtxt ,
15
- ) -> ServerResult < Arc < graph :: Response > > {
16
- log:: info!( "handle_graph ({:?})" , body ) ;
22
+ request : graphs :: Request ,
23
+ ctxt : Arc < SiteCtxt > ,
24
+ ) -> ServerResult < Arc < graphs :: Response > > {
25
+ log:: info!( "handle_graphs ({:?})" , request ) ;
17
26
18
- let is_default_query = body
19
- == graph :: Request {
27
+ let is_default_query = request
28
+ == graphs :: Request {
20
29
start : Bound :: None ,
21
30
end : Bound :: None ,
22
31
stat : String :: from ( "instructions:u" ) ,
23
- kind : graph :: GraphKind :: Raw ,
32
+ kind : graphs :: GraphKind :: Raw ,
24
33
} ;
25
34
26
35
if is_default_query {
@@ -30,7 +39,7 @@ pub async fn handle_graphs(
30
39
}
31
40
}
32
41
33
- let resp = graph_response ( body , ctxt) . await ?;
42
+ let resp = create_graphs ( request , & ctxt) . await ?;
34
43
35
44
if is_default_query {
36
45
ctxt. landing_page . store ( Arc :: new ( Some ( resp. clone ( ) ) ) ) ;
@@ -39,12 +48,36 @@ pub async fn handle_graphs(
39
48
Ok ( resp)
40
49
}
41
50
42
- async fn graph_response (
43
- body : graph:: Request ,
51
+ async fn create_graph (
52
+ request : graph:: Request ,
53
+ ctxt : Arc < SiteCtxt > ,
54
+ ) -> ServerResult < graph:: Response > {
55
+ let artifact_ids = artifact_ids_for_range ( & ctxt, request. start , request. end ) ;
56
+ let mut series_iterator = ctxt
57
+ . statistic_series (
58
+ Query :: new ( )
59
+ . set :: < String > ( Tag :: Benchmark , Selector :: One ( request. benchmark ) )
60
+ . set :: < String > ( Tag :: Profile , Selector :: One ( request. profile ) )
61
+ . set :: < String > ( Tag :: Scenario , Selector :: One ( request. scenario ) )
62
+ . set :: < String > ( Tag :: Metric , Selector :: One ( request. metric ) ) ,
63
+ Arc :: new ( artifact_ids) ,
64
+ )
65
+ . await ?
66
+ . into_iter ( )
67
+ . map ( SeriesResponse :: interpolate) ;
68
+
69
+ let result = series_iterator. next ( ) . unwrap ( ) ;
70
+ let graph_series = graph_series ( result. series , request. kind ) ;
71
+ Ok ( graph:: Response {
72
+ series : graph_series,
73
+ } )
74
+ }
75
+
76
+ async fn create_graphs (
77
+ request : graphs:: Request ,
44
78
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 ( ) ) ;
79
+ ) -> ServerResult < Arc < graphs:: Response > > {
80
+ let artifact_ids = Arc :: new ( artifact_ids_for_range ( ctxt, request. start , request. end ) ) ;
48
81
let mut benchmarks = HashMap :: new ( ) ;
49
82
50
83
let interpolated_responses: Vec < _ > = ctxt
@@ -53,23 +86,23 @@ async fn graph_response(
53
86
. set :: < String > ( Tag :: Benchmark , Selector :: All )
54
87
. set :: < String > ( Tag :: Profile , Selector :: All )
55
88
. set :: < String > ( Tag :: Scenario , Selector :: All )
56
- . set :: < String > ( Tag :: Metric , Selector :: One ( body . stat ) ) ,
57
- commits . clone ( ) ,
89
+ . set :: < String > ( Tag :: Metric , Selector :: One ( request . stat ) ) ,
90
+ artifact_ids . clone ( ) ,
58
91
)
59
92
. await ?
60
93
. into_iter ( )
61
94
. map ( |sr| sr. interpolate ( ) . map ( |series| series. collect :: < Vec < _ > > ( ) ) )
62
95
. collect ( ) ;
63
96
64
- let summary_benchmark = create_summary ( ctxt, & interpolated_responses, body . kind ) ?;
97
+ let summary_benchmark = create_summary ( ctxt, & interpolated_responses, request . kind ) ?;
65
98
66
99
benchmarks. insert ( "Summary" . to_string ( ) , summary_benchmark) ;
67
100
68
101
for response in interpolated_responses {
69
102
let benchmark = response. path . get :: < Benchmark > ( ) ?. to_string ( ) ;
70
103
let profile = * response. path . get :: < Profile > ( ) ?;
71
104
let scenario = response. path . get :: < Scenario > ( ) ?. to_string ( ) ;
72
- let graph_series = graph_series ( response. series . into_iter ( ) , body . kind ) ;
105
+ let graph_series = graph_series ( response. series . into_iter ( ) , request . kind ) ;
73
106
74
107
benchmarks
75
108
. entry ( benchmark)
@@ -79,8 +112,8 @@ async fn graph_response(
79
112
. insert ( scenario, graph_series) ;
80
113
}
81
114
82
- Ok ( Arc :: new ( graph :: Response {
83
- commits : Arc :: try_unwrap ( commits )
115
+ Ok ( Arc :: new ( graphs :: Response {
116
+ commits : Arc :: try_unwrap ( artifact_ids )
84
117
. unwrap ( )
85
118
. into_iter ( )
86
119
. map ( |c| match c {
@@ -92,13 +125,18 @@ async fn graph_response(
92
125
} ) )
93
126
}
94
127
128
+ fn artifact_ids_for_range ( ctxt : & SiteCtxt , start : Bound , end : Bound ) -> Vec < ArtifactId > {
129
+ let range = ctxt. data_range ( start..=end) ;
130
+ range. into_iter ( ) . map ( |c| c. into ( ) ) . collect ( )
131
+ }
132
+
95
133
/// Creates a summary "benchmark" that averages the results of all other
96
134
/// test cases per profile type
97
135
fn create_summary (
98
136
ctxt : & SiteCtxt ,
99
137
interpolated_responses : & [ SeriesResponse < Vec < ( ( ArtifactId , Option < f64 > ) , IsInterpolated ) > > ] ,
100
138
graph_kind : GraphKind ,
101
- ) -> ServerResult < HashMap < Profile , HashMap < String , graph :: Series > > > {
139
+ ) -> ServerResult < HashMap < Profile , HashMap < String , graphs :: Series > > > {
102
140
let mut baselines = HashMap :: new ( ) ;
103
141
let mut summary_benchmark = HashMap :: new ( ) ;
104
142
let summary_query_cases = iproduct ! (
@@ -152,8 +190,8 @@ fn create_summary(
152
190
fn graph_series (
153
191
points : impl Iterator < Item = ( ( ArtifactId , Option < f64 > ) , IsInterpolated ) > ,
154
192
kind : GraphKind ,
155
- ) -> graph :: Series {
156
- let mut graph_series = graph :: Series {
193
+ ) -> graphs :: Series {
194
+ let mut graph_series = graphs :: Series {
157
195
points : Vec :: new ( ) ,
158
196
interpolated_indices : Default :: default ( ) ,
159
197
} ;
0 commit comments