@@ -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 ,
@@ -301,7 +298,7 @@ impl CompareScreen {
301
298
base : Commit ,
302
299
modified : Commit ,
303
300
) -> anyhow:: Result < Self > {
304
- let pstats = load_data (
301
+ let data = load_data (
305
302
metric,
306
303
& db_state. index ,
307
304
db_state. db . as_mut ( ) ,
@@ -314,10 +311,22 @@ impl CompareScreen {
314
311
modified,
315
312
db_state,
316
313
metric,
317
- data : pstats ,
314
+ data,
318
315
table_state : TableState :: default ( ) ,
319
316
} )
320
317
}
318
+
319
+ async fn reload_data ( & mut self ) -> anyhow:: Result < ( ) > {
320
+ self . data = load_data (
321
+ self . metric ,
322
+ & self . db_state . index ,
323
+ self . db_state . db . as_mut ( ) ,
324
+ & self . base ,
325
+ & self . modified ,
326
+ )
327
+ . await ?;
328
+ Ok ( ( ) )
329
+ }
321
330
}
322
331
323
332
impl Screen for CompareScreen {
@@ -330,15 +339,20 @@ impl Screen for CompareScreen {
330
339
[
331
340
// +2 because of borders
332
341
Constraint :: Min ( ( summary_table. lines ( ) . count ( ) + 2 ) as u16 ) ,
342
+ Constraint :: Length ( 2 ) ,
333
343
Constraint :: Percentage ( 100 ) ,
334
344
]
335
345
. as_ref ( ) ,
336
346
)
337
347
. split ( frame. area ( ) ) ;
348
+
338
349
frame. render_widget (
339
350
Paragraph :: new ( Text :: raw ( summary_table) ) . block ( Block :: bordered ( ) . title ( "Summary" ) ) ,
340
351
layout[ 0 ] ,
341
352
) ;
353
+
354
+ render_metric ( frame, self . metric , layout[ 1 ] ) ;
355
+
342
356
let header = Row :: new ( vec ! [
343
357
Line :: from( "Benchmark" ) ,
344
358
Line :: from( "Profile" ) ,
@@ -398,7 +412,7 @@ impl Screen for CompareScreen {
398
412
. row_highlight_style ( Style :: new ( ) . bold ( ) ) ;
399
413
400
414
let table_layout =
401
- Layout :: new ( Direction :: Horizontal , [ Constraint :: Max ( 120 ) ] ) . split ( layout[ 1 ] ) ;
415
+ Layout :: new ( Direction :: Horizontal , [ Constraint :: Max ( 120 ) ] ) . split ( layout[ 2 ] ) ;
402
416
frame. render_stateful_widget ( table, table_layout[ 0 ] , & mut self . table_state ) ;
403
417
}
404
418
@@ -410,6 +424,14 @@ impl Screen for CompareScreen {
410
424
match key {
411
425
KeyCode :: Down => self . table_state . select_next ( ) ,
412
426
KeyCode :: Up => self . table_state . select_previous ( ) ,
427
+ KeyCode :: Char ( 'a' ) => {
428
+ self . metric = select_metric ( self . metric , -1 ) ;
429
+ self . reload_data ( ) . await ?;
430
+ }
431
+ KeyCode :: Char ( 's' ) => {
432
+ self . metric = select_metric ( self . metric , 1 ) ;
433
+ self . reload_data ( ) . await ?;
434
+ }
413
435
_ => { }
414
436
}
415
437
@@ -418,6 +440,23 @@ impl Screen for CompareScreen {
418
440
}
419
441
}
420
442
443
+ fn select_metric ( current : Metric , direction : isize ) -> Metric {
444
+ let index = ALL_METRICS . iter ( ) . position ( |m| * m == current) . unwrap_or ( 0 ) as isize ;
445
+ let index = ( ( index + direction) + ALL_METRICS . len ( ) as isize ) % ALL_METRICS . len ( ) as isize ;
446
+ ALL_METRICS [ index as usize ]
447
+ }
448
+
449
+ fn render_metric ( frame : & mut Frame , metric : Metric , area : Rect ) {
450
+ frame. render_widget (
451
+ Line :: from ( vec ! [
452
+ "Metric: " . into( ) ,
453
+ metric. as_str( ) . bold( ) ,
454
+ " (switch: A/S)" . into( ) ,
455
+ ] ) ,
456
+ area,
457
+ )
458
+ }
459
+
421
460
async fn load_data (
422
461
metric : Metric ,
423
462
index : & Index ,
0 commit comments