@@ -10,7 +10,7 @@ use crate::selector::{self, Tag};
10
10
11
11
use collector:: category:: Category ;
12
12
use collector:: Bound ;
13
- use serde:: { Deserialize , Serialize } ;
13
+ use serde:: { Deserialize , Deserializer , Serialize } ;
14
14
15
15
use std:: cmp:: Ordering ;
16
16
use std:: collections:: { HashMap , HashSet } ;
@@ -48,20 +48,25 @@ pub async fn handle_triage(
48
48
let metric = Metric :: Instructions ;
49
49
let benchmark_map = ctxt. get_benchmark_category_map ( ) . await ;
50
50
loop {
51
- let comparison =
52
- match compare_given_commits ( before, next. clone ( ) , metric, ctxt, & master_commits)
53
- . await
54
- . map_err ( |e| format ! ( "error comparing commits: {}" , e) ) ?
55
- {
56
- Some ( c) => c,
57
- None => {
58
- log:: info!(
59
- "No data found for end bound {:?}. Ending comparison..." ,
60
- next
61
- ) ;
62
- break ;
63
- }
64
- } ;
51
+ let comparison = match compare_given_commits (
52
+ before,
53
+ next. clone ( ) ,
54
+ metric. clone ( ) ,
55
+ ctxt,
56
+ & master_commits,
57
+ )
58
+ . await
59
+ . map_err ( |e| format ! ( "error comparing commits: {}" , e) ) ?
60
+ {
61
+ Some ( c) => c,
62
+ None => {
63
+ log:: info!(
64
+ "No data found for end bound {:?}. Ending comparison..." ,
65
+ next
66
+ ) ;
67
+ break ;
68
+ }
69
+ } ;
65
70
num_comparisons += 1 ;
66
71
log:: info!(
67
72
"Comparing {} to {}" ,
@@ -180,34 +185,39 @@ async fn populate_report(
180
185
}
181
186
}
182
187
183
- #[ derive( Copy , Clone , Debug , PartialEq , Serialize , Deserialize ) ]
188
+ #[ derive( Clone , Debug , PartialEq , Serialize ) ]
184
189
pub enum Metric {
185
190
#[ serde( rename = "instructions:u" ) ]
186
191
Instructions ,
187
192
#[ serde( rename = "cycles:u" ) ]
188
193
Cycles ,
189
- #[ serde( rename = "faults" ) ]
190
- Faults ,
191
194
#[ serde( rename = "max-rss" ) ]
192
195
MaxRSS ,
193
- #[ serde( rename = "task-clock" ) ]
194
- TaskClock ,
195
- #[ serde( rename = "wall-time" ) ]
196
- WallTime ,
197
- #[ serde( rename = "cpu-clock" ) ]
198
- CpuClock ,
196
+ Custom ( String ) ,
197
+ }
198
+
199
+ impl < ' de > Deserialize < ' de > for Metric {
200
+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
201
+ where
202
+ D : Deserializer < ' de > ,
203
+ {
204
+ let metric = String :: deserialize ( deserializer) ?;
205
+ Ok ( match metric. as_str ( ) {
206
+ "instructions:u" => Metric :: Instructions ,
207
+ "cycles:u" => Metric :: Cycles ,
208
+ "max-rss" => Metric :: MaxRSS ,
209
+ _ => Metric :: Custom ( metric) ,
210
+ } )
211
+ }
199
212
}
200
213
201
214
impl Metric {
202
- pub fn as_str ( & self ) -> & ' static str {
215
+ pub fn as_str ( & self ) -> & str {
203
216
match self {
204
217
Self :: Instructions => "instructions:u" ,
205
218
Self :: Cycles => "cycles:u" ,
206
- Self :: Faults => "faults" ,
207
219
Self :: MaxRSS => "max-rss" ,
208
- Self :: TaskClock => "task-clock" ,
209
- Self :: WallTime => "wall-time" ,
210
- Self :: CpuClock => "cpu-clock" ,
220
+ Self :: Custom ( str) => str. as_str ( ) ,
211
221
}
212
222
}
213
223
@@ -662,7 +672,7 @@ async fn compare_given_commits(
662
672
let statistics_for_b = statistics_from_series ( & mut responses) ;
663
673
664
674
let mut historical_data =
665
- HistoricalDataMap :: calculate ( ctxt, a. clone ( ) , master_commits, metric) . await ?;
675
+ HistoricalDataMap :: calculate ( ctxt, a. clone ( ) , master_commits, metric. clone ( ) ) . await ?;
666
676
let comparisons = statistics_for_a
667
677
. into_iter ( )
668
678
. filter_map ( |( test_case, a) | {
@@ -672,7 +682,7 @@ async fn compare_given_commits(
672
682
benchmark : test_case. 0 ,
673
683
profile : test_case. 1 ,
674
684
scenario : test_case. 2 ,
675
- metric,
685
+ metric : metric . clone ( ) ,
676
686
historical_data : historical_data. data . remove ( & test_case) ,
677
687
results : ( a, b) ,
678
688
} )
@@ -1484,6 +1494,33 @@ mod tests {
1484
1494
) ;
1485
1495
}
1486
1496
1497
+ #[ test]
1498
+ fn parse_metric_instructions ( ) {
1499
+ let metric: Metric = serde_json:: from_str ( r#""instructions:u""# ) . unwrap ( ) ;
1500
+ assert ! ( matches!( metric, Metric :: Instructions ) ) ;
1501
+ }
1502
+
1503
+ #[ test]
1504
+ fn parse_metric_cycles ( ) {
1505
+ let metric: Metric = serde_json:: from_str ( r#""cycles:u""# ) . unwrap ( ) ;
1506
+ assert ! ( matches!( metric, Metric :: Cycles ) ) ;
1507
+ }
1508
+
1509
+ #[ test]
1510
+ fn parse_metric_max_rss ( ) {
1511
+ let metric: Metric = serde_json:: from_str ( r#""max-rss""# ) . unwrap ( ) ;
1512
+ assert ! ( matches!( metric, Metric :: MaxRSS ) ) ;
1513
+ }
1514
+
1515
+ #[ test]
1516
+ fn parse_metric_custom ( ) {
1517
+ let metric: Metric = serde_json:: from_str ( r#""foo""# ) . unwrap ( ) ;
1518
+ match metric {
1519
+ Metric :: Custom ( str) => assert_eq ! ( str , "foo" ) ,
1520
+ _ => panic ! ( ) ,
1521
+ }
1522
+ }
1523
+
1487
1524
// (category, before, after)
1488
1525
fn check_table ( values : Vec < ( Category , f64 , f64 ) > , expected : & str ) {
1489
1526
let mut primary_comparisons = HashSet :: new ( ) ;
0 commit comments