@@ -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 = rustc_artifacts:: 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 ( ) ,
@@ -39,7 +39,7 @@ pub async fn handle_triage(
39
39
let mut before = start. clone ( ) ;
40
40
41
41
loop {
42
- let comparison = compare (
42
+ let comparison = compare_given_commits (
43
43
before,
44
44
after. clone ( ) ,
45
45
"instructions:u" . to_owned ( ) ,
@@ -76,14 +76,14 @@ pub async fn handle_compare(
76
76
body : api:: days:: Request ,
77
77
data : & InputData ,
78
78
) -> Result < api:: days:: Response , BoxedError > {
79
- let commits = rustc_artifacts:: master_commits ( ) . await ?;
79
+ let master_commits = rustc_artifacts:: master_commits ( ) . await ?;
80
80
let comparison =
81
- crate :: comparison :: compare ( body. start , body. end , body. stat , data, & commits ) . await ?;
81
+ compare_given_commits ( body. start , body. end , body. stat , data, & master_commits ) . await ?;
82
82
83
83
let conn = data. conn ( ) . await ;
84
- let prev = comparison. prev ( & commits ) ;
85
- let next = comparison. next ( & commits ) ;
86
- let is_contiguous = comparison. is_contiguous ( & * conn, & commits ) . await ;
84
+ let prev = comparison. prev ( & master_commits ) ;
85
+ let next = comparison. next ( & master_commits ) ;
86
+ let is_contiguous = comparison. is_contiguous ( & * conn, & master_commits ) . await ;
87
87
88
88
Ok ( api:: days:: Response {
89
89
prev,
@@ -95,7 +95,7 @@ pub async fn handle_compare(
95
95
}
96
96
97
97
async fn populate_report ( comparison : & Comparison , report : & mut HashMap < Direction , Vec < String > > ) {
98
- if let Some ( summary) = summarize_comparison ( comparison) {
98
+ if let Some ( summary) = ComparisonSummary :: summarize_comparison ( comparison) {
99
99
if let Some ( direction) = summary. direction ( ) {
100
100
let entry = report. entry ( direction) . or_default ( ) ;
101
101
@@ -104,42 +104,43 @@ async fn populate_report(comparison: &Comparison, report: &mut HashMap<Direction
104
104
}
105
105
}
106
106
107
- fn summarize_comparison < ' a > ( comparison : & ' a Comparison ) -> Option < ComparisonSummary < ' a > > {
108
- let mut benchmarks = comparison. get_benchmarks ( ) ;
109
- // Skip empty commits, sometimes happens if there's a compiler bug or so.
110
- if benchmarks. len ( ) == 0 {
111
- return None ;
112
- }
113
-
114
- let cmp = |b1 : & BenchmarkComparison , b2 : & BenchmarkComparison | {
115
- b1. log_change ( )
116
- . partial_cmp ( & b2. log_change ( ) )
117
- . unwrap_or ( std:: cmp:: Ordering :: Equal )
118
- } ;
119
- let lo = benchmarks
120
- . iter ( )
121
- . enumerate ( )
122
- . min_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
123
- . filter ( |( _, c) | c. is_significant ( ) && !c. is_increase ( ) )
124
- . map ( |( i, _) | i) ;
125
- let lo = lo. map ( |lo| benchmarks. remove ( lo) ) ;
126
- let hi = benchmarks
127
- . iter ( )
128
- . enumerate ( )
129
- . max_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
130
- . filter ( |( _, c) | c. is_significant ( ) && c. is_increase ( ) )
131
- . map ( |( i, _) | i) ;
132
- let hi = hi. map ( |hi| benchmarks. remove ( hi) ) ;
133
-
134
- Some ( ComparisonSummary { hi, lo } )
135
- }
136
-
137
- struct ComparisonSummary < ' a > {
107
+ pub struct ComparisonSummary < ' a > {
138
108
hi : Option < BenchmarkComparison < ' a > > ,
139
109
lo : Option < BenchmarkComparison < ' a > > ,
140
110
}
141
111
142
112
impl ComparisonSummary < ' _ > {
113
+ pub fn summarize_comparison < ' a > ( comparison : & ' a Comparison ) -> Option < ComparisonSummary < ' a > > {
114
+ let mut benchmarks = comparison. get_benchmarks ( ) ;
115
+ // Skip empty commits, sometimes happens if there's a compiler bug or so.
116
+ if benchmarks. len ( ) == 0 {
117
+ return None ;
118
+ }
119
+
120
+ let cmp = |b1 : & BenchmarkComparison , b2 : & BenchmarkComparison | {
121
+ b1. log_change ( )
122
+ . partial_cmp ( & b2. log_change ( ) )
123
+ . unwrap_or ( std:: cmp:: Ordering :: Equal )
124
+ } ;
125
+ let lo = benchmarks
126
+ . iter ( )
127
+ . enumerate ( )
128
+ . min_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
129
+ . filter ( |( _, c) | c. is_significant ( ) && !c. is_increase ( ) )
130
+ . map ( |( i, _) | i) ;
131
+ let lo = lo. map ( |lo| benchmarks. remove ( lo) ) ;
132
+ let hi = benchmarks
133
+ . iter ( )
134
+ . enumerate ( )
135
+ . max_by ( |& ( _, b1) , & ( _, b2) | cmp ( b1, b2) )
136
+ . filter ( |( _, c) | c. is_significant ( ) && c. is_increase ( ) )
137
+ . map ( |( i, _) | i) ;
138
+ let hi = hi. map ( |hi| benchmarks. remove ( hi) ) ;
139
+
140
+ benchmarks. clear ( ) ;
141
+
142
+ Some ( ComparisonSummary { hi, lo } )
143
+ }
143
144
/// The direction of the changes
144
145
fn direction ( & self ) -> Option < Direction > {
145
146
let d = match ( & self . hi , & self . lo ) {
@@ -153,7 +154,7 @@ impl ComparisonSummary<'_> {
153
154
}
154
155
155
156
/// The changes ordered by their signficance (most significant first)
156
- fn ordered_changes ( & self ) -> Vec < & BenchmarkComparison < ' _ > > {
157
+ pub fn ordered_changes ( & self ) -> Vec < & BenchmarkComparison < ' _ > > {
157
158
match ( & self . hi , & self . lo ) {
158
159
( None , None ) => Vec :: new ( ) ,
159
160
( Some ( b) , None ) => vec ! [ b] ,
@@ -189,7 +190,7 @@ impl ComparisonSummary<'_> {
189
190
190
191
for change in self . ordered_changes ( ) {
191
192
write ! ( result, "- " ) . unwrap ( ) ;
192
- change. summary_line ( & mut result, link)
193
+ change. summary_line ( & mut result, Some ( link) )
193
194
}
194
195
result
195
196
}
@@ -201,6 +202,17 @@ pub async fn compare(
201
202
end : Bound ,
202
203
stat : String ,
203
204
data : & InputData ,
205
+ ) -> Result < Comparison , BoxedError > {
206
+ let master_commits = rustc_artifacts:: master_commits ( ) . await ?;
207
+ compare_given_commits ( start, end, stat, data, & master_commits) . await
208
+ }
209
+
210
+ /// Compare two bounds on a given stat
211
+ pub async fn compare_given_commits (
212
+ start : Bound ,
213
+ end : Bound ,
214
+ stat : String ,
215
+ data : & InputData ,
204
216
master_commits : & [ rustc_artifacts:: Commit ] ,
205
217
) -> Result < Comparison , BoxedError > {
206
218
let a = data
@@ -388,7 +400,7 @@ impl Comparison {
388
400
389
401
// A single comparison based on benchmark and cache state
390
402
#[ derive( Debug ) ]
391
- struct BenchmarkComparison < ' a > {
403
+ pub struct BenchmarkComparison < ' a > {
392
404
bench_name : & ' a str ,
393
405
cache_state : & ' a str ,
394
406
results : ( f64 , f64 ) ,
@@ -430,7 +442,7 @@ impl BenchmarkComparison<'_> {
430
442
}
431
443
}
432
444
433
- fn summary_line ( & self , summary : & mut String , link : & str ) {
445
+ pub fn summary_line ( & self , summary : & mut String , link : Option < & str > ) {
434
446
use std:: fmt:: Write ;
435
447
let magnitude = self . log_change ( ) . abs ( ) ;
436
448
let size = if magnitude > 0.10 {
@@ -451,7 +463,10 @@ impl BenchmarkComparison<'_> {
451
463
"{} {} in [instruction counts]({})" ,
452
464
size,
453
465
self . direction( ) ,
454
- link
466
+ match link {
467
+ Some ( l) => l,
468
+ None => "" ,
469
+ }
455
470
)
456
471
. unwrap ( ) ;
457
472
writeln ! (
0 commit comments