@@ -10,11 +10,12 @@ use crate::selector::{self, Tag};
10
10
11
11
use collector:: category:: Category ;
12
12
use collector:: Bound ;
13
- use serde:: Serialize ;
13
+ use serde:: { Deserialize , Serialize } ;
14
14
15
15
use std:: cmp:: Ordering ;
16
16
use std:: collections:: { HashMap , HashSet } ;
17
17
use std:: error:: Error ;
18
+ use std:: fmt:: Write ;
18
19
use std:: hash:: Hash ;
19
20
use std:: sync:: Arc ;
20
21
@@ -44,11 +45,11 @@ pub async fn handle_triage(
44
45
let mut before = start. clone ( ) ;
45
46
46
47
let mut num_comparisons = 0 ;
47
- let stat = "instructions:u" . to_owned ( ) ;
48
+ let stat = Stat :: Instructions ;
48
49
let benchmark_map = ctxt. get_benchmark_category_map ( ) . await ;
49
50
loop {
50
51
let comparison =
51
- match compare_given_commits ( before, next. clone ( ) , stat. clone ( ) , ctxt, & master_commits)
52
+ match compare_given_commits ( before, next. clone ( ) , stat, ctxt, & master_commits)
52
53
. await
53
54
. map_err ( |e| format ! ( "error comparing commits: {}" , e) ) ?
54
55
{
@@ -171,14 +172,46 @@ async fn populate_report(
171
172
( None , None ) => return ,
172
173
} ;
173
174
174
- let include_in_triage = deserves_attention ( & primary, & secondary) ;
175
+ let include_in_triage = deserves_attention_icount ( & primary, & secondary) ;
175
176
176
177
if include_in_triage {
177
178
let entry = report. entry ( direction) . or_default ( ) ;
178
179
entry. push ( write_triage_summary ( comparison, & primary, & secondary) . await ) ;
179
180
}
180
181
}
181
182
183
+ #[ derive( Copy , Clone , Debug , PartialEq , Serialize , Deserialize ) ]
184
+ pub enum Stat {
185
+ #[ serde( rename = "instructions:u" ) ]
186
+ Instructions ,
187
+ #[ serde( rename = "cycles:u" ) ]
188
+ Cycles ,
189
+ #[ serde( rename = "faults" ) ]
190
+ Faults ,
191
+ #[ serde( rename = "max-rss" ) ]
192
+ MaxRSS ,
193
+ #[ serde( rename = "task-clock" ) ]
194
+ TaskClock ,
195
+ #[ serde( rename = "wall-time" ) ]
196
+ WallTime ,
197
+ #[ serde( rename = "cpu-clock" ) ]
198
+ CpuClock ,
199
+ }
200
+
201
+ impl Stat {
202
+ pub fn as_str ( & self ) -> & ' static str {
203
+ match self {
204
+ Self :: Instructions => "instructions:u" ,
205
+ Self :: Cycles => "cycles:u" ,
206
+ Self :: Faults => "faults" ,
207
+ Self :: MaxRSS => "max-rss" ,
208
+ Self :: TaskClock => "task-clock" ,
209
+ Self :: WallTime => "wall-time" ,
210
+ Self :: CpuClock => "cpu-clock" ,
211
+ }
212
+ }
213
+ }
214
+
182
215
/// A summary of a given comparison
183
216
///
184
217
/// This summary only includes changes that are significant and relevant (as determined by a change's magnitude).
@@ -366,7 +399,7 @@ impl ArtifactComparisonSummary {
366
399
///
367
400
/// For example, this can be used to determine if artifact comparisons with regressions should be labeled with the
368
401
/// `perf-regression` GitHub label or should be shown in the perf triage report.
369
- pub ( crate ) fn deserves_attention (
402
+ pub ( crate ) fn deserves_attention_icount (
370
403
primary : & ArtifactComparisonSummary ,
371
404
secondary : & ArtifactComparisonSummary ,
372
405
) -> bool {
@@ -388,7 +421,6 @@ async fn write_triage_summary(
388
421
primary : & ArtifactComparisonSummary ,
389
422
secondary : & ArtifactComparisonSummary ,
390
423
) -> String {
391
- use std:: fmt:: Write ;
392
424
let mut result = if let Some ( pr) = comparison. b . pr {
393
425
let title = github:: pr_title ( pr) . await ;
394
426
format ! (
@@ -415,8 +447,6 @@ pub fn write_summary_table(
415
447
with_footnotes : bool ,
416
448
result : & mut String ,
417
449
) {
418
- use std:: fmt:: Write ;
419
-
420
450
fn render_stat < F : FnOnce ( ) -> Option < f64 > > ( count : usize , calculate : F ) -> String {
421
451
let value = if count > 0 { calculate ( ) } else { None } ;
422
452
value
@@ -538,16 +568,16 @@ pub fn write_summary_table(
538
568
} ) ,
539
569
largest_change,
540
570
] ) ;
571
+ }
541
572
542
- if with_footnotes {
543
- writeln ! (
544
- result,
545
- r#"
573
+ pub fn write_summary_table_footer ( result : & mut String ) {
574
+ writeln ! (
575
+ result,
576
+ r#"
546
577
[^1]: *number of relevant changes*
547
578
[^2]: *the arithmetic mean of the percent change*"#
548
- )
549
- . unwrap ( ) ;
550
- }
579
+ )
580
+ . unwrap ( ) ;
551
581
}
552
582
553
583
/// Compare two bounds on a given stat
@@ -556,7 +586,7 @@ pub fn write_summary_table(
556
586
pub async fn compare (
557
587
start : Bound ,
558
588
end : Bound ,
559
- stat : String ,
589
+ stat : Stat ,
560
590
ctxt : & SiteCtxt ,
561
591
) -> Result < Option < ArtifactComparison > , BoxedError > {
562
592
let master_commits = & ctxt. get_master_commits ( ) . commits ;
@@ -568,7 +598,7 @@ pub async fn compare(
568
598
async fn compare_given_commits (
569
599
start : Bound ,
570
600
end : Bound ,
571
- stat : String ,
601
+ stat : Stat ,
572
602
ctxt : & SiteCtxt ,
573
603
master_commits : & [ collector:: MasterCommit ] ,
574
604
) -> Result < Option < ArtifactComparison > , BoxedError > {
@@ -587,7 +617,7 @@ async fn compare_given_commits(
587
617
. set :: < String > ( Tag :: Benchmark , selector:: Selector :: All )
588
618
. set :: < String > ( Tag :: Scenario , selector:: Selector :: All )
589
619
. set :: < String > ( Tag :: Profile , selector:: Selector :: All )
590
- . set ( Tag :: Metric , selector:: Selector :: One ( stat. clone ( ) ) ) ;
620
+ . set ( Tag :: Metric , selector:: Selector :: One ( stat. as_str ( ) ) ) ;
591
621
592
622
// `responses` contains series iterators. The first element in the iterator is the data
593
623
// for `a` and the second is the data for `b`
@@ -834,7 +864,7 @@ impl HistoricalDataMap {
834
864
ctxt : & SiteCtxt ,
835
865
from : ArtifactId ,
836
866
master_commits : & [ collector:: MasterCommit ] ,
837
- stat : String ,
867
+ stat : Stat ,
838
868
) -> Result < Self , BoxedError > {
839
869
let mut historical_data = HashMap :: new ( ) ;
840
870
@@ -856,7 +886,7 @@ impl HistoricalDataMap {
856
886
. set :: < String > ( Tag :: Benchmark , selector:: Selector :: All )
857
887
. set :: < String > ( Tag :: Scenario , selector:: Selector :: All )
858
888
. set :: < String > ( Tag :: Profile , selector:: Selector :: All )
859
- . set ( Tag :: Metric , selector:: Selector :: One ( stat) ) ;
889
+ . set ( Tag :: Metric , selector:: Selector :: One ( stat. as_str ( ) ) ) ;
860
890
861
891
let mut previous_commit_series = ctxt
862
892
. statistic_series ( query, previous_commits. clone ( ) )
@@ -1272,9 +1302,6 @@ mod tests {
1272
1302
| count[^1] | 3 | 0 | 0 | 0 | 3 |
1273
1303
| mean[^2] | 146.7% | N/A | N/A | N/A | 146.7% |
1274
1304
| max | 200.0% | N/A | N/A | N/A | 200.0% |
1275
-
1276
- [^1]: *number of relevant changes*
1277
- [^2]: *the arithmetic mean of the percent change*
1278
1305
"#
1279
1306
. trim_start ( ) ,
1280
1307
) ;
@@ -1294,9 +1321,6 @@ mod tests {
1294
1321
| count[^1] | 0 | 0 | 3 | 0 | 3 |
1295
1322
| mean[^2] | N/A | N/A | -71.7% | N/A | -71.7% |
1296
1323
| max | N/A | N/A | -80.0% | N/A | -80.0% |
1297
-
1298
- [^1]: *number of relevant changes*
1299
- [^2]: *the arithmetic mean of the percent change*
1300
1324
"#
1301
1325
. trim_start ( ) ,
1302
1326
) ;
@@ -1316,9 +1340,6 @@ mod tests {
1316
1340
| count[^1] | 0 | 0 | 0 | 3 | 0 |
1317
1341
| mean[^2] | N/A | N/A | N/A | -71.7% | N/A |
1318
1342
| max | N/A | N/A | N/A | -80.0% | N/A |
1319
-
1320
- [^1]: *number of relevant changes*
1321
- [^2]: *the arithmetic mean of the percent change*
1322
1343
"#
1323
1344
. trim_start ( ) ,
1324
1345
) ;
@@ -1338,9 +1359,6 @@ mod tests {
1338
1359
| count[^1] | 0 | 3 | 0 | 0 | 0 |
1339
1360
| mean[^2] | N/A | 146.7% | N/A | N/A | N/A |
1340
1361
| max | N/A | 200.0% | N/A | N/A | N/A |
1341
-
1342
- [^1]: *number of relevant changes*
1343
- [^2]: *the arithmetic mean of the percent change*
1344
1362
"#
1345
1363
. trim_start ( ) ,
1346
1364
) ;
@@ -1361,9 +1379,6 @@ mod tests {
1361
1379
| count[^1] | 2 | 0 | 2 | 0 | 4 |
1362
1380
| mean[^2] | 150.0% | N/A | -62.5% | N/A | 43.8% |
1363
1381
| max | 200.0% | N/A | -75.0% | N/A | 200.0% |
1364
-
1365
- [^1]: *number of relevant changes*
1366
- [^2]: *the arithmetic mean of the percent change*
1367
1382
"#
1368
1383
. trim_start ( ) ,
1369
1384
) ;
@@ -1386,9 +1401,6 @@ mod tests {
1386
1401
| count[^1] | 2 | 1 | 2 | 1 | 4 |
1387
1402
| mean[^2] | 150.0% | 100.0% | -62.5% | -66.7% | 43.8% |
1388
1403
| max | 200.0% | 100.0% | -75.0% | -66.7% | 200.0% |
1389
-
1390
- [^1]: *number of relevant changes*
1391
- [^2]: *the arithmetic mean of the percent change*
1392
1404
"#
1393
1405
. trim_start ( ) ,
1394
1406
) ;
@@ -1407,9 +1419,6 @@ mod tests {
1407
1419
| count[^1] | 1 | 0 | 1 | 0 | 2 |
1408
1420
| mean[^2] | 20.0% | N/A | -50.0% | N/A | -15.0% |
1409
1421
| max | 20.0% | N/A | -50.0% | N/A | -50.0% |
1410
-
1411
- [^1]: *number of relevant changes*
1412
- [^2]: *the arithmetic mean of the percent change*
1413
1422
"#
1414
1423
. trim_start ( ) ,
1415
1424
) ;
@@ -1428,9 +1437,6 @@ mod tests {
1428
1437
| count[^1] | 1 | 0 | 1 | 0 | 2 |
1429
1438
| mean[^2] | 100.0% | N/A | -16.7% | N/A | 41.7% |
1430
1439
| max | 100.0% | N/A | -16.7% | N/A | 100.0% |
1431
-
1432
- [^1]: *number of relevant changes*
1433
- [^2]: *the arithmetic mean of the percent change*
1434
1440
"#
1435
1441
. trim_start ( ) ,
1436
1442
) ;
0 commit comments