1
1
use collector:: Bound ;
2
- use std:: cell:: RefCell ;
3
2
use std:: collections:: HashMap ;
4
- use std:: convert:: TryInto ;
5
- use std:: str;
6
3
use std:: sync:: Arc ;
7
4
8
5
use crate :: api:: graph:: GraphKind ;
@@ -38,9 +35,9 @@ pub async fn handle_graph(
38
35
39
36
let mut benchmarks = HashMap :: new ( ) ;
40
37
41
- let raw = handle_graph_impl ( body, ctxt) . await ?;
38
+ let benchmarks_impl = handle_graph_impl ( body, ctxt) . await ?;
42
39
43
- for ( benchmark_, benchmark_data) in raw . benchmarks . iter ( ) {
40
+ for ( benchmark_, benchmark_data) in benchmarks_impl . iter ( ) {
44
41
let mut by_profile = HashMap :: with_capacity ( 3 ) ;
45
42
46
43
for ( profile, series) in benchmark_data. iter ( ) {
@@ -86,13 +83,15 @@ pub async fn handle_graph(
86
83
Ok ( resp)
87
84
}
88
85
89
- static INTERPOLATED_COLOR : & str = "#fcb0f1" ;
86
+ struct GraphData {
87
+ y : f32 ,
88
+ is_interpolated : bool ,
89
+ }
90
90
91
91
async fn handle_graph_impl (
92
92
body : graph:: Request ,
93
93
ctxt : & SiteCtxt ,
94
- ) -> ServerResult < graph:: Response > {
95
- let cc = CommitIdxCache :: new ( ) ;
94
+ ) -> ServerResult < HashMap < String , HashMap < String , Vec < ( String , Vec < GraphData > ) > > > > {
96
95
let range = ctxt. data_range ( body. start . clone ( ) ..=body. end . clone ( ) ) ;
97
96
let commits: Arc < Vec < _ > > = Arc :: new ( range. iter ( ) . map ( |c| c. clone ( ) . into ( ) ) . collect ( ) ) ;
98
97
@@ -113,7 +112,7 @@ async fn handle_graph_impl(
113
112
. into_iter ( )
114
113
. map ( |sr| {
115
114
sr. interpolate ( )
116
- . map ( |series| to_graph_data ( & cc , body. kind , series) . collect :: < Vec < _ > > ( ) )
115
+ . map ( |series| to_graph_data ( body. kind , series) . collect :: < Vec < _ > > ( ) )
117
116
} )
118
117
. collect :: < Vec < _ > > ( ) ;
119
118
@@ -183,7 +182,7 @@ async fn handle_graph_impl(
183
182
. collect ( ) ,
184
183
)
185
184
. map ( |( ( c, d) , i) | ( ( c, Some ( d. expect ( "interpolated" ) / against) ) , i) ) ;
186
- let graph_data = to_graph_data ( & cc , body. kind , averaged) . collect :: < Vec < _ > > ( ) ;
185
+ let graph_data = to_graph_data ( body. kind , averaged) . collect :: < Vec < _ > > ( ) ;
187
186
series. push ( selector:: SeriesResponse {
188
187
path : selector:: Path :: new ( )
189
188
. set ( PathComponent :: Benchmark ( "Summary" . into ( ) ) )
@@ -203,17 +202,8 @@ async fn handle_graph_impl(
203
202
}
204
203
205
204
let mut by_test_case = HashMap :: new ( ) ;
206
- let mut by_benchmark_max = HashMap :: new ( ) ;
207
205
for sr in series {
208
206
let benchmark = sr. path . get :: < Benchmark > ( ) ?. to_string ( ) ;
209
- let max = by_benchmark_max
210
- . entry ( benchmark. clone ( ) )
211
- . or_insert ( f32:: MIN ) ;
212
- * max = sr
213
- . series
214
- . iter ( )
215
- . map ( |p| p. y )
216
- . fold ( * max, |max, p| max. max ( p) ) ;
217
207
by_test_case
218
208
. entry ( benchmark)
219
209
. or_insert_with ( HashMap :: new)
@@ -222,76 +212,29 @@ async fn handle_graph_impl(
222
212
. push ( ( sr. path . get :: < Scenario > ( ) ?. to_string ( ) , sr. series ) ) ;
223
213
}
224
214
225
- Ok ( graph:: Response {
226
- max : by_benchmark_max,
227
- benchmarks : by_test_case,
228
- colors : vec ! [ String :: new( ) , String :: from( INTERPOLATED_COLOR ) ] ,
229
- commits : cc. into_commits ( ) ,
230
- } )
231
- }
232
-
233
- struct CommitIdxCache {
234
- commit_idx : RefCell < HashMap < String , u16 > > ,
235
- commits : RefCell < Vec < String > > ,
236
- }
237
-
238
- impl CommitIdxCache {
239
- fn new ( ) -> Self {
240
- Self {
241
- commit_idx : RefCell :: new ( HashMap :: new ( ) ) ,
242
- commits : RefCell :: new ( Vec :: new ( ) ) ,
243
- }
244
- }
245
-
246
- fn into_commits ( self ) -> Vec < String > {
247
- std:: mem:: take ( & mut * self . commits . borrow_mut ( ) )
248
- }
249
-
250
- fn lookup ( & self , commit : String ) -> u16 {
251
- * self
252
- . commit_idx
253
- . borrow_mut ( )
254
- . entry ( commit. clone ( ) )
255
- . or_insert_with ( || {
256
- let idx = self . commits . borrow ( ) . len ( ) ;
257
- self . commits . borrow_mut ( ) . push ( commit) ;
258
- idx. try_into ( ) . unwrap_or_else ( |_| {
259
- panic ! ( "{} too big" , idx) ;
260
- } )
261
- } )
262
- }
215
+ Ok ( by_test_case)
263
216
}
264
217
265
218
fn to_graph_data < ' a > (
266
- cc : & ' a CommitIdxCache ,
267
219
kind : GraphKind ,
268
220
points : impl Iterator < Item = ( ( ArtifactId , Option < f64 > ) , Interpolated ) > + ' a ,
269
- ) -> impl Iterator < Item = graph :: GraphData > + ' a {
221
+ ) -> impl Iterator < Item = GraphData > + ' a {
270
222
let mut first = None ;
271
223
let mut prev = None ;
272
- points. map ( move |( ( aid, point) , interpolated) | {
273
- let commit = if let ArtifactId :: Commit ( commit) = aid {
274
- commit
275
- } else {
276
- unimplemented ! ( )
277
- } ;
224
+ points. map ( move |( ( _aid, point) , interpolated) | {
278
225
let point = point. expect ( "interpolated" ) ;
279
226
first = Some ( first. unwrap_or ( point) ) ;
280
227
let first = first. unwrap ( ) ;
281
228
let percent_first = ( point - first) / first * 100.0 ;
282
229
let previous_point = prev. unwrap_or ( point) ;
283
230
let percent_prev = ( point - previous_point) / previous_point * 100.0 ;
284
231
prev = Some ( point) ;
285
- graph:: GraphData {
286
- commit : cc. lookup ( commit. sha ) ,
287
- absolute : point as f32 ,
288
- percent_first : percent_first as f32 ,
232
+ GraphData {
289
233
y : match kind {
290
234
GraphKind :: Raw => point as f32 ,
291
235
GraphKind :: PercentRelative => percent_prev as f32 ,
292
236
GraphKind :: PercentFromFirst => percent_first as f32 ,
293
237
} ,
294
- x : commit. date . 0 . timestamp ( ) as u64 * 1000 , // all dates are since 1970
295
238
is_interpolated : interpolated. is_interpolated ( ) ,
296
239
}
297
240
} )
0 commit comments