@@ -8,17 +8,14 @@ use ratatui::{
8
8
prelude:: * ,
9
9
widgets:: Block ,
10
10
} ;
11
- use std:: fmt:: Display ;
12
11
use std:: future:: Future ;
13
12
use std:: pin:: Pin ;
14
13
use std:: sync:: Arc ;
15
- use tabled:: settings:: object:: { Column , Columns } ;
16
- use tabled:: settings:: Modify ;
17
14
use tabled:: Tabled ;
18
15
19
16
static ALL_METRICS : & [ Metric ] = & [
20
17
Metric :: InstructionsUser ,
21
- Metric :: Cycles ,
18
+ Metric :: CyclesUser ,
22
19
Metric :: WallTime ,
23
20
Metric :: MaxRSS ,
24
21
Metric :: LinkedArtifactSize ,
@@ -31,7 +28,7 @@ static ALL_METRICS: &[Metric] = &[
31
28
Metric :: CpuClock ,
32
29
Metric :: CpuClockUser ,
33
30
Metric :: CrateMetadataSize ,
34
- Metric :: CyclesUser ,
31
+ Metric :: Cycles ,
35
32
Metric :: DepGraphSize ,
36
33
Metric :: DocByteSize ,
37
34
Metric :: DwoFileSize ,
@@ -70,14 +67,14 @@ pub async fn compare_artifacts(
70
67
commit : Option < String > ,
71
68
label : & str ,
72
69
) -> anyhow:: Result < Option < Commit > > {
73
- Ok ( commit
70
+ commit
74
71
. map ( |commit| {
75
72
aids. iter ( )
76
73
. find ( |c| c. sha == commit)
77
74
. cloned ( )
78
75
. ok_or_else ( || anyhow:: anyhow!( "{label} commit {commit} not found" ) )
79
76
} )
80
- . transpose ( ) ? )
77
+ . transpose ( )
81
78
}
82
79
83
80
let base: Option < Commit > = check_commit ( & aids, base, "Base" ) ?;
@@ -111,8 +108,8 @@ pub async fn compare_artifacts(
111
108
terminal. draw ( |frame| {
112
109
screen. draw ( frame) ;
113
110
} ) ?;
114
- match event:: read ( ) ? {
115
- Event :: Key ( key_event ) => match key_event. code {
111
+ if let Event :: Key ( key_event ) = event:: read ( ) ? {
112
+ match key_event. code {
116
113
KeyCode :: Char ( 'q' ) | KeyCode :: Esc => break ,
117
114
key => {
118
115
if let Some ( action) = screen. handle_key ( key) . await ? {
@@ -123,8 +120,7 @@ pub async fn compare_artifacts(
123
120
}
124
121
}
125
122
}
126
- } ,
127
- _ => { }
123
+ }
128
124
}
129
125
}
130
126
ratatui:: restore ( ) ;
@@ -301,7 +297,7 @@ impl CompareScreen {
301
297
base : Commit ,
302
298
modified : Commit ,
303
299
) -> anyhow:: Result < Self > {
304
- let pstats = load_data (
300
+ let data = load_data (
305
301
metric,
306
302
& db_state. index ,
307
303
db_state. db . as_mut ( ) ,
@@ -314,10 +310,22 @@ impl CompareScreen {
314
310
modified,
315
311
db_state,
316
312
metric,
317
- data : pstats ,
313
+ data,
318
314
table_state : TableState :: default ( ) ,
319
315
} )
320
316
}
317
+
318
+ async fn reload_data ( & mut self ) -> anyhow:: Result < ( ) > {
319
+ self . data = load_data (
320
+ self . metric ,
321
+ & self . db_state . index ,
322
+ self . db_state . db . as_mut ( ) ,
323
+ & self . base ,
324
+ & self . modified ,
325
+ )
326
+ . await ?;
327
+ Ok ( ( ) )
328
+ }
321
329
}
322
330
323
331
impl Screen for CompareScreen {
@@ -330,15 +338,20 @@ impl Screen for CompareScreen {
330
338
[
331
339
// +2 because of borders
332
340
Constraint :: Min ( ( summary_table. lines ( ) . count ( ) + 2 ) as u16 ) ,
341
+ Constraint :: Length ( 2 ) ,
333
342
Constraint :: Percentage ( 100 ) ,
334
343
]
335
344
. as_ref ( ) ,
336
345
)
337
346
. split ( frame. area ( ) ) ;
347
+
338
348
frame. render_widget (
339
349
Paragraph :: new ( Text :: raw ( summary_table) ) . block ( Block :: bordered ( ) . title ( "Summary" ) ) ,
340
350
layout[ 0 ] ,
341
351
) ;
352
+
353
+ render_metric ( frame, self . metric , layout[ 1 ] ) ;
354
+
342
355
let header = Row :: new ( vec ! [
343
356
Line :: from( "Benchmark" ) ,
344
357
Line :: from( "Profile" ) ,
@@ -398,7 +411,7 @@ impl Screen for CompareScreen {
398
411
. row_highlight_style ( Style :: new ( ) . bold ( ) ) ;
399
412
400
413
let table_layout =
401
- Layout :: new ( Direction :: Horizontal , [ Constraint :: Max ( 120 ) ] ) . split ( layout[ 1 ] ) ;
414
+ Layout :: new ( Direction :: Horizontal , [ Constraint :: Max ( 120 ) ] ) . split ( layout[ 2 ] ) ;
402
415
frame. render_stateful_widget ( table, table_layout[ 0 ] , & mut self . table_state ) ;
403
416
}
404
417
@@ -410,6 +423,14 @@ impl Screen for CompareScreen {
410
423
match key {
411
424
KeyCode :: Down => self . table_state . select_next ( ) ,
412
425
KeyCode :: Up => self . table_state . select_previous ( ) ,
426
+ KeyCode :: Char ( 'a' ) => {
427
+ self . metric = select_metric ( self . metric , -1 ) ;
428
+ self . reload_data ( ) . await ?;
429
+ }
430
+ KeyCode :: Char ( 's' ) => {
431
+ self . metric = select_metric ( self . metric , 1 ) ;
432
+ self . reload_data ( ) . await ?;
433
+ }
413
434
_ => { }
414
435
}
415
436
@@ -418,6 +439,23 @@ impl Screen for CompareScreen {
418
439
}
419
440
}
420
441
442
+ fn select_metric ( current : Metric , direction : isize ) -> Metric {
443
+ let index = ALL_METRICS . iter ( ) . position ( |m| * m == current) . unwrap_or ( 0 ) as isize ;
444
+ let index = ( ( index + direction) + ALL_METRICS . len ( ) as isize ) % ALL_METRICS . len ( ) as isize ;
445
+ ALL_METRICS [ index as usize ]
446
+ }
447
+
448
+ fn render_metric ( frame : & mut Frame , metric : Metric , area : Rect ) {
449
+ frame. render_widget (
450
+ Line :: from ( vec ! [
451
+ "Metric: " . into( ) ,
452
+ metric. as_str( ) . bold( ) ,
453
+ " (switch: A/S)" . into( ) ,
454
+ ] ) ,
455
+ area,
456
+ )
457
+ }
458
+
421
459
async fn load_data (
422
460
metric : Metric ,
423
461
index : & Index ,
@@ -429,7 +467,7 @@ async fn load_data(
429
467
let resp = query
430
468
. execute (
431
469
conn,
432
- & index,
470
+ index,
433
471
Arc :: new ( vec ! [
434
472
ArtifactId :: Commit ( base. clone( ) ) ,
435
473
ArtifactId :: Commit ( modified. clone( ) ) ,
@@ -497,26 +535,19 @@ struct Regression {
497
535
count : usize ,
498
536
#[ tabled( display( "display_range" ) ) ]
499
537
range : ( Option < f64 > , Option < f64 > ) ,
500
- #[ tabled( display( "display_mean " ) ) ]
538
+ #[ tabled( display( "format_value " ) ) ]
501
539
mean : Option < f64 > ,
502
540
}
503
541
504
- fn format_value ( value : Option < f64 > ) -> String {
542
+ fn format_value ( value : & Option < f64 > ) -> String {
505
543
match value {
506
- Some ( value) => format ! ( "{:+.2}%" , value ) ,
544
+ Some ( value) => format ! ( "{value :+.2}%" ) ,
507
545
None => "-" . to_string ( ) ,
508
546
}
509
547
}
510
548
511
549
fn display_range ( & ( min, max) : & ( Option < f64 > , Option < f64 > ) ) -> String {
512
- format ! ( "[{}, {}]" , & format_value( min) , & format_value( max) )
513
- }
514
-
515
- fn display_mean ( value : & Option < f64 > ) -> String {
516
- match value {
517
- Some ( value) => format ! ( "{:+.2}%" , value) ,
518
- None => "-" . to_string ( ) ,
519
- }
550
+ format ! ( "[{}, {}]" , & format_value( & min) , & format_value( & max) )
520
551
}
521
552
522
553
impl From < & Vec < f64 > > for Regression {
0 commit comments