From 4b36def99ed9e17e86c6145d46a070a8ceb7ad58 Mon Sep 17 00:00:00 2001 From: Richard Patel Date: Tue, 3 Mar 2026 05:02:52 +0000 Subject: [PATCH] fdctl: add monitor --topo flag Allows running monitor for custom topologies --- src/app/shared/commands/monitor/monitor.c | 31 ++++++++++++++++++++++- src/app/shared/fd_action.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/app/shared/commands/monitor/monitor.c b/src/app/shared/commands/monitor/monitor.c index 35c20a00b10..5d8c6dc4cdd 100644 --- a/src/app/shared/commands/monitor/monitor.c +++ b/src/app/shared/commands/monitor/monitor.c @@ -1,4 +1,3 @@ -#include "../../../../util/fd_util.h" /* TODO: Layering violation */ #include "../../../shared_dev/commands/bench/bench.h" @@ -22,6 +21,8 @@ #include #include "generated/monitor_seccomp.h" +extern action_t * ACTIONS[]; + void monitor_cmd_args( int * pargc, char *** pargv, @@ -35,6 +36,12 @@ monitor_cmd_args( int * pargc, args->monitor.with_bench = fd_env_strip_cmdline_contains( pargc, pargv, "--bench" ); args->monitor.with_sankey = fd_env_strip_cmdline_contains( pargc, pargv, "--sankey" ); + char const * topo_name = fd_env_strip_cmdline_cstr( pargc, pargv, "--topo", NULL, "" ); + + ulong topo_name_len = strlen( topo_name ); + if( FD_UNLIKELY( topo_name_len > sizeof(args->monitor.topo)-1 ) ) FD_LOG_ERR(( "Unknown --topo %s", topo_name )); + fd_cstr_fini( fd_cstr_append_text( fd_cstr_init( args->monitor.topo ), topo_name, topo_name_len ) ); + if( FD_UNLIKELY( args->monitor.dt_min<0L ) ) FD_LOG_ERR(( "--dt-min should be positive" )); if( FD_UNLIKELY( args->monitor.dt_maxmonitor.dt_min ) ) FD_LOG_ERR(( "--dt-max should be at least --dt-min" )); if( FD_UNLIKELY( args->monitor.duration<0L ) ) FD_LOG_ERR(( "--duration should be non-negative" )); @@ -498,9 +505,31 @@ signal1( int sig ) { exit( 0 ); /* gracefully exit */ } +static void +reconstruct_topo( config_t * config, + char const * topo_name ) { + if( !topo_name[0] ) return; /* keep default action topo */ + + action_t const * selected = NULL; + for( action_t ** a=ACTIONS; *a; a++ ) { + action_t const * action = *a; + if( 0==strcmp( action->name, topo_name ) ) { + selected = action; + break; + } + } + + if( !selected ) FD_LOG_ERR(( "Unknown --topo %s", topo_name )); + if( !selected->topo ) FD_LOG_ERR(( "Cannot recover topology for --topo %s", topo_name )); + + selected->topo( config ); +} + void monitor_cmd_fn( args_t * args, config_t * config ) { + reconstruct_topo( config, args->monitor.topo ); + if( FD_UNLIKELY( args->monitor.with_bench ) ) { add_bench_topo( &config->topo, config->development.bench.affinity, diff --git a/src/app/shared/fd_action.h b/src/app/shared/fd_action.h index e922c2245fe..3539439abf6 100644 --- a/src/app/shared/fd_action.h +++ b/src/app/shared/fd_action.h @@ -11,6 +11,7 @@ union fdctl_args { } run1; struct { + char topo[ 64 ]; long dt_min; long dt_max; long duration;