From 2c11519f6ef547f730458490eff863b36642e7a9 Mon Sep 17 00:00:00 2001 From: Anoushk Kharangate Date: Sat, 14 Dec 2024 10:16:23 +0000 Subject: [PATCH] fix: make monitor more readable Signed-off-by: Anoushk Kharangate --- src/app/fdctl/monitor/helper.c | 29 ++++++++++++++++++++++++++++- src/app/fdctl/monitor/helper.h | 2 ++ src/app/fdctl/monitor/monitor.c | 15 +++++++++------ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/app/fdctl/monitor/helper.c b/src/app/fdctl/monitor/helper.c index 2fb6fc60efa..5111321ca61 100644 --- a/src/app/fdctl/monitor/helper.c +++ b/src/app/fdctl/monitor/helper.c @@ -1,5 +1,6 @@ #include "helper.h" - +#include +#include #include #define PRINT( ... ) do { \ @@ -174,3 +175,29 @@ printf_pct( char ** buf, if( pct<=999.999 ) { PRINT( " %7.3f", pct ); return; } /**/ PRINT( ">999.999" ); } + + +int +fd_getch() +{ + struct termios oldt, newt; + int ch; + int oldf; + /* Disables character echo and canonical mode since we want the input to be processes immediately. + * Terminal also set to non blocking in case the user doesn't send any input. + * */ + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= (tcflag_t)~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + oldf = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); + + ch = getchar(); + + /*Restore the terminal back to it's original configuration*/ + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + fcntl(STDIN_FILENO, F_SETFL, oldf); + + return ch; +} diff --git a/src/app/fdctl/monitor/helper.h b/src/app/fdctl/monitor/helper.h index 66bba6e9f5b..0aa49c8ae1c 100644 --- a/src/app/fdctl/monitor/helper.h +++ b/src/app/fdctl/monitor/helper.h @@ -107,4 +107,6 @@ printf_pct( char ** buf, ulong den_then, double lhopital_den ); +int +fd_getch(void); #endif /* HEADER_fd_src_app_fdctl_monitor_helper_h */ diff --git a/src/app/fdctl/monitor/monitor.c b/src/app/fdctl/monitor/monitor.c index a9b2977b0c9..9476d66cfe8 100644 --- a/src/app/fdctl/monitor/monitor.c +++ b/src/app/fdctl/monitor/monitor.c @@ -293,8 +293,9 @@ run_monitor( config_t * const config, if( FD_UNLIKELY( (ulong)n>=buf_sz ) ) FD_LOG_ERR(( "snprintf truncated" )); \ buf += n; buf_sz -= (ulong)n; \ } while(0) - +#define TAB 9 ulong line_count = 0; + int monitor_pane = 0; for(;;) { /* Wait a somewhat randomized amount and then make a diagnostic snapshot */ @@ -311,7 +312,7 @@ run_monitor( config_t * const config, ulong buf_sz = FD_MONITOR_TEXT_BUF_SZ; /* move to beginning of line, n lines ago */ - PRINT( "\033[%luF", line_count ); + PRINT( "\033[2J\033[%luF", line_count ); /* drain any firedancer log messages into the terminal */ if( FD_UNLIKELY( drain_output_fd >= 0 ) ) drain_to_buffer( &buf, &buf_sz, drain_output_fd ); @@ -324,11 +325,13 @@ run_monitor( config_t * const config, char * mon_start = buf; if( FD_UNLIKELY( drain_output_fd >= 0 ) ) PRINT( TEXT_NEWLINE ); + if( FD_UNLIKELY(fd_getch() != EOF) ) monitor_pane = !monitor_pane; long dt = now-then; char now_cstr[ FD_LOG_WALLCLOCK_CSTR_BUF_SZ ]; - PRINT( "snapshot for %s" TEXT_NEWLINE, fd_log_wallclock_cstr( now, now_cstr ) ); + if( !monitor_pane ){ + PRINT( "snapshot for %s | Use TAB to switch panes" TEXT_NEWLINE, fd_log_wallclock_cstr( now, now_cstr ) ); PRINT( " tile | pid | stale | heart | nivcsw | nvcsw | in backp | backp cnt | %% hkeep | %% wait | %% backp | %% finish" TEXT_NEWLINE ); PRINT( "---------+---------+------------+-------+---------------------+---------------------+----------+---------------------+----------+----------+----------+----------" TEXT_NEWLINE ); for( ulong tile_idx=0UL; tile_idxtile_cnt; tile_idx++ ) { @@ -361,7 +364,7 @@ run_monitor( config_t * const config, PRINT( " | " ); printf_pct( &buf, &buf_sz, cur_processing_ticks, prv_processing_ticks, 0., tile_total_ticks( cur ), tile_total_ticks( prv ), DBL_MIN ); PRINT( TEXT_NEWLINE ); } - PRINT( TEXT_NEWLINE ); + }else{ PRINT( " link | tot TPS | tot bps | uniq TPS | uniq bps | ha tr%% | uniq bw%% | filt tr%% | filt bw%% | ovrnp cnt | ovrnr cnt | slow cnt | tx seq" TEXT_NEWLINE ); PRINT( "------------------+----------+----------+----------+----------+----------+----------+----------+----------+---------------------+---------------------+---------------------+-------------------" TEXT_NEWLINE ); @@ -404,7 +407,8 @@ run_monitor( config_t * const config, } } - + } + fd_log_sleep(dt); if( FD_UNLIKELY( with_sankey ) ) { /* We only need to count from one of the benchs, since they both receive all of the transactions. */ @@ -573,7 +577,6 @@ monitor_cmd_fn( args_t * args, uint drain_output_fd = args->monitor.drain_output_fd >= 0 ? (uint)args->monitor.drain_output_fd : (uint)-1; populate_sock_filter_policy_monitor( 128UL, seccomp_filter, (uint)fd_log_private_logfile_fd(), drain_output_fd ); - if( FD_UNLIKELY( close( STDIN_FILENO ) ) ) FD_LOG_ERR(( "close(0) failed (%i-%s)", errno, fd_io_strerror( errno ) )); if( FD_UNLIKELY( close( config->log.lock_fd ) ) ) FD_LOG_ERR(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) )); if( FD_LIKELY( config->development.sandbox ) ) {