Skip to content

Commit

Permalink
fix: make monitor more readable
Browse files Browse the repository at this point in the history
Signed-off-by: Anoushk Kharangate <kharangateanoushk04@gmail.com>
  • Loading branch information
anoushk1234 committed Dec 17, 2024
1 parent 6989302 commit b1bc7f1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
29 changes: 28 additions & 1 deletion src/app/fdctl/monitor/helper.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "helper.h"

#include <termios.h>
#include <fcntl.h>
#include <stdio.h>

#define PRINT( ... ) do { \
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/app/fdctl/monitor/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
15 changes: 9 additions & 6 deletions src/app/fdctl/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 );
Expand All @@ -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_idx<topo->tile_cnt; tile_idx++ ) {
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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 ) ) {
Expand Down

0 comments on commit b1bc7f1

Please sign in to comment.