@@ -25,7 +25,7 @@ pub async fn handle_triage(
25
25
let end = body. end ;
26
26
// Compare against self to get next
27
27
let master_commits = collector:: master_commits ( ) . await ?;
28
- let comparison = compare (
28
+ let comparison = compare_given_commits (
29
29
start. clone ( ) ,
30
30
start. clone ( ) ,
31
31
"instructions:u" . to_owned ( ) ,
@@ -40,7 +40,7 @@ pub async fn handle_triage(
40
40
let mut before = start. clone ( ) ;
41
41
42
42
loop {
43
- let comparison = match compare (
43
+ let comparison = match compare_given_commits (
44
44
before,
45
45
after. clone ( ) ,
46
46
"instructions:u" . to_owned ( ) ,
@@ -87,16 +87,17 @@ pub async fn handle_compare(
87
87
body : api:: days:: Request ,
88
88
data : & InputData ,
89
89
) -> Result < api:: days:: Response , BoxedError > {
90
- let commits = collector:: master_commits ( ) . await ?;
90
+ let master_commits = collector:: master_commits ( ) . await ?;
91
91
let end = body. end ;
92
- let comparison = crate :: comparison:: compare ( body. start , end. clone ( ) , body. stat , data, & commits)
93
- . await ?
94
- . ok_or_else ( || format ! ( "could not find end commit for bound {:?}" , end) ) ?;
92
+ let comparison =
93
+ compare_given_commits ( body. start , end. clone ( ) , body. stat , data, & master_commits)
94
+ . await ?
95
+ . ok_or_else ( || format ! ( "could not find end commit for bound {:?}" , end) ) ?;
95
96
96
97
let conn = data. conn ( ) . await ;
97
- let prev = comparison. prev ( & commits ) ;
98
- let next = comparison. next ( & commits ) ;
99
- let is_contiguous = comparison. is_contiguous ( & * conn, & commits ) . await ;
98
+ let prev = comparison. prev ( & master_commits ) ;
99
+ let next = comparison. next ( & master_commits ) ;
100
+ let is_contiguous = comparison. is_contiguous ( & * conn, & master_commits ) . await ;
100
101
101
102
Ok ( api:: days:: Response {
102
103
prev,
@@ -108,7 +109,7 @@ pub async fn handle_compare(
108
109
}
109
110
110
111
async fn populate_report ( comparison : & Comparison , report : & mut HashMap < Direction , Vec < String > > ) {
111
- if let Some ( summary) = summarize_comparison ( comparison) {
112
+ if let Some ( summary) = ComparisonSummary :: summarize_comparison ( comparison) {
112
113
if let Some ( direction) = summary. direction ( ) {
113
114
let entry = report. entry ( direction) . or_default ( ) ;
114
115
@@ -117,44 +118,44 @@ async fn populate_report(comparison: &Comparison, report: &mut HashMap<Direction
117
118
}
118
119
}
119
120
120
- fn summarize_comparison < ' a > ( comparison : & ' a Comparison ) -> Option < ComparisonSummary < ' a > > {
121
- let mut benchmarks = comparison. get_benchmarks ( ) ;
122
- // Skip empty commits, sometimes happens if there's a compiler bug or so.
123
- if benchmarks. len ( ) == 0 {
124
- return None ;
125
- }
126
-
127
- let cmp = |b1 : & BenchmarkComparison , b2 : & BenchmarkComparison | {
128
- b1. log_change ( )
129
- . partial_cmp ( & b2. log_change ( ) )
130
- . unwrap_or ( std:: cmp:: Ordering :: Equal )
131
- } ;
132
- let lo = benchmarks
133
- . iter ( )
134
- . enumerate ( )
135
- . min_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
136
- . filter ( |( _, c) | c. is_significant ( ) && !c. is_increase ( ) )
137
- . map ( |( i, _) | i) ;
138
- let lo = lo. map ( |lo| benchmarks. remove ( lo) ) ;
139
- let hi = benchmarks
140
- . iter ( )
141
- . enumerate ( )
142
- . max_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
143
- . filter ( |( _, c) | c. is_significant ( ) && c. is_increase ( ) )
144
- . map ( |( i, _) | i) ;
145
- let hi = hi. map ( |hi| benchmarks. remove ( hi) ) ;
146
-
147
- Some ( ComparisonSummary { hi, lo } )
148
- }
149
-
150
- struct ComparisonSummary < ' a > {
121
+ pub struct ComparisonSummary < ' a > {
151
122
hi : Option < BenchmarkComparison < ' a > > ,
152
123
lo : Option < BenchmarkComparison < ' a > > ,
153
124
}
154
125
155
126
impl ComparisonSummary < ' _ > {
127
+ pub fn summarize_comparison < ' a > ( comparison : & ' a Comparison ) -> Option < ComparisonSummary < ' a > > {
128
+ let mut benchmarks = comparison. get_benchmarks ( ) ;
129
+ // Skip empty commits, sometimes happens if there's a compiler bug or so.
130
+ if benchmarks. len ( ) == 0 {
131
+ return None ;
132
+ }
133
+
134
+ let cmp = |b1 : & BenchmarkComparison , b2 : & BenchmarkComparison | {
135
+ b1. log_change ( )
136
+ . partial_cmp ( & b2. log_change ( ) )
137
+ . unwrap_or ( std:: cmp:: Ordering :: Equal )
138
+ } ;
139
+ let lo = benchmarks
140
+ . iter ( )
141
+ . enumerate ( )
142
+ . min_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
143
+ . filter ( |( _, c) | c. is_significant ( ) && !c. is_increase ( ) )
144
+ . map ( |( i, _) | i) ;
145
+ let lo = lo. map ( |lo| benchmarks. remove ( lo) ) ;
146
+ let hi = benchmarks
147
+ . iter ( )
148
+ . enumerate ( )
149
+ . max_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
150
+ . filter ( |( _, c) | c. is_significant ( ) && c. is_increase ( ) )
151
+ . map ( |( i, _) | i) ;
152
+ let hi = hi. map ( |hi| benchmarks. remove ( hi) ) ;
153
+
154
+ Some ( ComparisonSummary { hi, lo } )
155
+ }
156
+
156
157
/// The direction of the changes
157
- fn direction ( & self ) -> Option < Direction > {
158
+ pub fn direction ( & self ) -> Option < Direction > {
158
159
let d = match ( & self . hi , & self . lo ) {
159
160
( None , None ) => return None ,
160
161
( Some ( b) , None ) => b. direction ( ) ,
@@ -166,7 +167,7 @@ impl ComparisonSummary<'_> {
166
167
}
167
168
168
169
/// The changes ordered by their signficance (most significant first)
169
- fn ordered_changes ( & self ) -> Vec < & BenchmarkComparison < ' _ > > {
170
+ pub fn ordered_changes ( & self ) -> Vec < & BenchmarkComparison < ' _ > > {
170
171
match ( & self . hi , & self . lo ) {
171
172
( None , None ) => Vec :: new ( ) ,
172
173
( Some ( b) , None ) => vec ! [ b] ,
@@ -202,7 +203,7 @@ impl ComparisonSummary<'_> {
202
203
203
204
for change in self . ordered_changes ( ) {
204
205
write ! ( result, "- " ) . unwrap ( ) ;
205
- change. summary_line ( & mut result, link)
206
+ change. summary_line ( & mut result, Some ( link) )
206
207
}
207
208
result
208
209
}
@@ -216,6 +217,17 @@ pub async fn compare(
216
217
end : Bound ,
217
218
stat : String ,
218
219
data : & InputData ,
220
+ ) -> Result < Option < Comparison > , BoxedError > {
221
+ let master_commits = collector:: master_commits ( ) . await ?;
222
+ compare_given_commits ( start, end, stat, data, & master_commits) . await
223
+ }
224
+
225
+ /// Compare two bounds on a given stat
226
+ pub async fn compare_given_commits (
227
+ start : Bound ,
228
+ end : Bound ,
229
+ stat : String ,
230
+ data : & InputData ,
219
231
master_commits : & [ collector:: MasterCommit ] ,
220
232
) -> Result < Option < Comparison > , BoxedError > {
221
233
let a = data
@@ -404,7 +416,7 @@ impl Comparison {
404
416
405
417
// A single comparison based on benchmark and cache state
406
418
#[ derive( Debug ) ]
407
- struct BenchmarkComparison < ' a > {
419
+ pub struct BenchmarkComparison < ' a > {
408
420
bench_name : & ' a str ,
409
421
cache_state : & ' a str ,
410
422
results : ( f64 , f64 ) ,
@@ -446,7 +458,7 @@ impl BenchmarkComparison<'_> {
446
458
}
447
459
}
448
460
449
- fn summary_line ( & self , summary : & mut String , link : & str ) {
461
+ pub fn summary_line ( & self , summary : & mut String , link : Option < & str > ) {
450
462
use std:: fmt:: Write ;
451
463
let magnitude = self . log_change ( ) . abs ( ) ;
452
464
let size = if magnitude > 0.10 {
@@ -467,7 +479,10 @@ impl BenchmarkComparison<'_> {
467
479
"{} {} in [instruction counts]({})" ,
468
480
size,
469
481
self . direction( ) ,
470
- link
482
+ match link {
483
+ Some ( l) => l,
484
+ None => "" ,
485
+ }
471
486
)
472
487
. unwrap ( ) ;
473
488
writeln ! (
@@ -481,7 +496,7 @@ impl BenchmarkComparison<'_> {
481
496
482
497
// The direction of a performance change
483
498
#[ derive( PartialEq , Eq , Hash ) ]
484
- enum Direction {
499
+ pub enum Direction {
485
500
Improvement ,
486
501
Regression ,
487
502
Mixed ,
0 commit comments