Line data Source code
1 : #include "watch.h"
2 : #include "generated/watch_seccomp.h"
3 :
4 : #include "../../fd_bootinfo.h"
5 :
6 : #include "../../../../discof/backup/fd_snapmk_tile.h"
7 : #include "../../../../discof/restore/fd_snapct_tile.h"
8 : #include "../../../../discof/gossip/fd_gossip_tile.h"
9 : #include "../../../../disco/events/fd_event_client.h"
10 : #include "../../../../disco/metrics/fd_metrics.h"
11 : #include "../../../../disco/node_info/fd_node_info.h"
12 : #include "../../../../disco/genesis/fd_genesis_cluster.h"
13 : #include "../../../../util/pod/fd_pod.h"
14 : #include "../../../../util/tile/fd_tile.h"
15 :
16 : #include <errno.h>
17 : #include <sys/select.h>
18 : #include <time.h>
19 : #include <unistd.h>
20 : #include <sys/resource.h>
21 : #include <linux/capability.h>
22 :
23 : #include "../../../platform/fd_sys_util.h"
24 :
25 : void
26 : watch_cmd_perm( args_t * args FD_PARAM_UNUSED,
27 : fd_cap_chk_t * chk,
28 0 : config_t const * config ) {
29 0 : ulong mlock_limit = fd_topo_mlock( &config->topo );
30 :
31 0 : fd_cap_chk_raise_rlimit( chk, "watch", RLIMIT_MEMLOCK, mlock_limit, "call `rlimit(2)` to increase `RLIMIT_MEMLOCK` so all memory can be locked with `mlock(2)`" );
32 :
33 0 : if( fd_sandbox_requires_cap_sys_admin( config->uid, config->gid ) )
34 0 : fd_cap_chk_cap( chk, "watch", CAP_SYS_ADMIN, "call `unshare(2)` with `CLONE_NEWUSER` to sandbox the process in a user namespace" );
35 0 : if( FD_LIKELY( getuid() != config->uid ) )
36 0 : fd_cap_chk_cap( chk, "watch", CAP_SETUID, "call `setresuid(2)` to switch uid to the sanbox user" );
37 0 : if( FD_LIKELY( getgid() != config->gid ) )
38 0 : fd_cap_chk_cap( chk, "watch", CAP_SETGID, "call `setresgid(2)` to switch gid to the sandbox user" );
39 0 : }
40 :
41 :
42 : static ulong lines_printed;
43 : static int ended_on_newline = 1;
44 :
45 : static char frame_buf[ 65536UL ];
46 : static ulong frame_len;
47 :
48 : /* Show all category detail rows, not just the primary row of each.
49 : Set from --full. */
50 : static int watch_full = 0;
51 :
52 : static void
53 0 : flush_frame( void ) {
54 0 : ulong written = 0UL;
55 0 : while( written<frame_len ) {
56 0 : long w = write( STDOUT_FILENO, frame_buf+written, frame_len-written );
57 0 : if( FD_UNLIKELY( -1==w && errno==EAGAIN ) ) continue;
58 0 : else if( FD_UNLIKELY( -1==w ) ) FD_LOG_ERR(( "write() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
59 0 : else if( FD_UNLIKELY( 0==w ) ) break;
60 0 : written += (ulong)w;
61 0 : }
62 0 : frame_len = 0UL;
63 0 : }
64 :
65 : static int
66 0 : drain( int fd ) {
67 0 : int needs_reprint = 0;
68 :
69 0 : while( 1 ) {
70 0 : uchar buf[ 16384UL ];
71 0 : long result = read( fd, buf, sizeof(buf) );
72 0 : if( FD_UNLIKELY( -1==result && errno==EAGAIN ) ) break;
73 0 : else if( FD_UNLIKELY( -1==result ) ) FD_LOG_ERR(( "read() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
74 0 : else if( FD_UNLIKELY( !result ) ) fd_sys_util_exit_group( 0 ); /* writer gone: validator exited */
75 :
76 0 : if( FD_LIKELY( !needs_reprint ) ) {
77 : /* Buffer the erase sequence and first log chunk together so the
78 : terminal never renders a blank frame between erase and content. */
79 0 : frame_len = 0UL;
80 0 : if( FD_UNLIKELY( !ended_on_newline ) ) {
81 0 : FD_TEST( fd_cstr_printf_check( frame_buf, sizeof(frame_buf), &frame_len, "\033[%luA\033[%luM\033[1A\033[0J", lines_printed, lines_printed ) );
82 0 : } else {
83 0 : FD_TEST( fd_cstr_printf_check( frame_buf, sizeof(frame_buf), &frame_len, "\033[%luA\033[%luM\033[0J", lines_printed, lines_printed ) );
84 0 : }
85 0 : }
86 0 : FD_TEST( frame_len+(ulong)result<=sizeof(frame_buf) );
87 0 : fd_memcpy( frame_buf+frame_len, buf, (ulong)result );
88 0 : frame_len += (ulong)result;
89 0 : flush_frame();
90 0 : needs_reprint = 1;
91 :
92 0 : ended_on_newline = buf[ (ulong)result-1UL ]=='\n';
93 0 : }
94 :
95 0 : return needs_reprint;
96 0 : }
97 :
98 : static char *
99 : fmt_bytes( char * buf,
100 : ulong buf_sz,
101 0 : long bytes ) {
102 0 : char * tmp = fd_alloca_check( 1UL, buf_sz );
103 0 : if( FD_LIKELY( 8L*bytes<1000L ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%ld bit/s", 8L*bytes ) );
104 0 : else if( FD_LIKELY( 8L*bytes<1000000L ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f Kbit/s", (double)(8L*bytes)/1000.0 ) );
105 0 : else if( FD_LIKELY( 8L*bytes<1000000000L ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f Mbit/s", (double)(8L*bytes)/1000000.0 ) );
106 0 : else FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f Gbit/s", (double)(8L*bytes)/1000000000.0 ) );
107 :
108 0 : FD_TEST( fd_cstr_printf_check( buf, buf_sz, NULL, "%12s", tmp ) );
109 0 : return buf;
110 0 : }
111 :
112 : static char *
113 : fmt_count( char * buf,
114 : ulong buf_sz,
115 0 : ulong count ) {
116 0 : char * tmp = fd_alloca_check( 1UL, buf_sz );
117 0 : if( FD_LIKELY( count<1000UL ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%lu", count ) );
118 0 : else if( FD_LIKELY( count<1000000UL ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f K", (double)count/1000.0 ) );
119 0 : else if( FD_LIKELY( count<1000000000UL ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f M", (double)count/1000000.0 ) );
120 0 : else FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f G", (double)count/1000000000.0 ) );
121 :
122 0 : FD_TEST( fd_cstr_printf_check( buf, buf_sz, NULL, "%7s", tmp ) );
123 0 : return buf;
124 0 : }
125 :
126 : static char *
127 : fmt_countf( char * buf,
128 : ulong buf_sz,
129 0 : double count ) {
130 0 : char * tmp = fd_alloca_check( 1UL, buf_sz );
131 0 : if( FD_LIKELY( count<1000UL ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f", count ) );
132 0 : else if( FD_LIKELY( count<1000000UL ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f K", (double)count/1000.0 ) );
133 0 : else if( FD_LIKELY( count<1000000000UL ) ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f M", (double)count/1000000.0 ) );
134 0 : else memcpy( tmp, "-", 2UL );
135 :
136 0 : FD_TEST( fd_cstr_printf_check( buf, buf_sz, NULL, "%7s", tmp ) );
137 0 : return buf;
138 0 : }
139 :
140 : static char *
141 : fmt_count_tight( char * buf,
142 : ulong buf_sz,
143 0 : ulong count ) {
144 0 : char * tmp = fd_alloca_check( 1UL, buf_sz );
145 0 : if( count<1000UL ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%lu", count ) );
146 0 : else if( count<1000000UL ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1fK", (double)count/1e3 ) );
147 0 : else if( count<1000000000UL ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1fM", (double)count/1e6 ) );
148 0 : else FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1fG", (double)count/1e9 ) );
149 0 : FD_TEST( fd_cstr_printf_check( buf, buf_sz, NULL, "%6s", tmp ) );
150 0 : return buf;
151 0 : }
152 :
153 : static char *
154 : fmt_countf_tight( char * buf,
155 : ulong buf_sz,
156 0 : double count ) {
157 0 : char * tmp = fd_alloca_check( 1UL, buf_sz );
158 0 : if( count<1000.0 ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1f", count ) );
159 0 : else if( count<1000000.0 ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1fK", count/1e3 ) );
160 0 : else if( count<1000000000.0 ) FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1fM", count/1e6 ) );
161 0 : else FD_TEST( fd_cstr_printf_check( tmp, buf_sz, NULL, "%.1fG", count/1e9 ) );
162 0 : FD_TEST( fd_cstr_printf_check( buf, buf_sz, NULL, "%6s", tmp ) );
163 0 : return buf;
164 0 : }
165 :
166 : static long
167 : diff_link( config_t const * config,
168 : char const * link_name,
169 : ulong const * prev_link,
170 : ulong const * cur_link,
171 0 : ulong idx ) {
172 0 : long result = 0L;
173 :
174 0 : ulong seen[ (FD_TOPO_MAX_LINKS+63UL)/64UL ] = {0};
175 0 : ulong overall_polled_idx = 0UL;
176 0 : for( ulong i=0UL; i<config->topo.tile_cnt; i++ ) {
177 0 : fd_topo_tile_t const * tile = &config->topo.tiles[ i ];
178 0 : for( ulong j=0UL; j<config->topo.tiles[ i ].in_cnt; j++ ) {
179 0 : fd_topo_link_t const * link = &config->topo.links[ tile->in_link_id[ j ] ];
180 0 : if( FD_UNLIKELY( !tile->in_link_poll[ j ] ) ) continue;
181 :
182 0 : if( FD_LIKELY( !strcmp( link->name, link_name ) ) ) {
183 0 : ulong id = tile->in_link_id[ j ];
184 0 : if( FD_LIKELY( !( seen[ id>>6 ] & (1UL<<(id&63UL)) ) ) ) {
185 0 : seen[ id>>6 ] |= 1UL<<(id&63UL);
186 0 : result += (long)cur_link[ overall_polled_idx*8UL+idx ]-(long)prev_link[ overall_polled_idx*8UL+idx ];
187 0 : }
188 0 : }
189 :
190 0 : overall_polled_idx++;
191 0 : }
192 0 : }
193 0 : return result;
194 0 : }
195 :
196 : /* diff_tile returns the positive increase between the last and current
197 : value of an increasing counter. Clamps wraparound to zero (this
198 : happens to gauge-based counters, e.g. "number of events in an epoch") */
199 :
200 : static ulong
201 : diff_tile( config_t const * config,
202 : char const * tile_name,
203 : ulong const * prev_tile,
204 : ulong const * cur_tile,
205 0 : ulong idx ) {
206 0 : ulong result = 0UL;
207 0 : for( ulong i=0UL; i<config->topo.tile_cnt; i++ ) {
208 0 : fd_topo_tile_t const * tile = &config->topo.tiles[ i ];
209 0 : if( FD_UNLIKELY( strcmp( tile->name, tile_name ) ) ) continue;
210 0 : ulong prev = prev_tile[ i*FD_METRICS_TOTAL_SZ+idx ];
211 0 : ulong cur = cur_tile[ i*FD_METRICS_TOTAL_SZ+idx ];
212 0 : result += cur>=prev ? cur-prev : 0UL;
213 0 : }
214 0 : return result;
215 0 : }
216 :
217 : static ulong
218 0 : total_crds( ulong const * metrics ) {
219 0 : ulong sum = 0UL;
220 0 : for( ulong i=0UL; i<FD_METRICS_ENUM_CRDS_VALUE_TYPE_CNT; i++ ) {
221 0 : sum += metrics[ MIDX( GAUGE, GOSSIP, CRDS_USED_CONTACT_INFO_V1 )+i ];
222 0 : }
223 0 : return sum;
224 0 : }
225 :
226 : /* diff_tile_regime is diff_tile summed over a TileRegime group mask */
227 :
228 : static ulong
229 : diff_tile_regime( config_t const * config,
230 : char const * tile_name,
231 : ulong const * prev_tile,
232 : ulong const * cur_tile,
233 0 : ulong mask ) {
234 0 : ulong result = 0UL;
235 0 : for( ; mask; mask=fd_ulong_pop_lsb( mask ) ) {
236 0 : result += diff_tile( config, tile_name, prev_tile, cur_tile, MIDX( COUNTER, TILE, REGIME_DURATION_NANOS )+(ulong)fd_ulong_find_lsb( mask ) );
237 0 : }
238 0 : return result;
239 0 : }
240 :
241 : /* tile_regime is diff_tile_regime for the one tile at tile_idx. */
242 :
243 : static ulong
244 : tile_regime( ulong const * prev_tile,
245 : ulong const * cur_tile,
246 : ulong tile_idx,
247 0 : ulong mask ) {
248 0 : ulong result = 0UL;
249 0 : for( ; mask; mask=fd_ulong_pop_lsb( mask ) ) {
250 0 : ulong idx = tile_idx*FD_METRICS_TOTAL_SZ+MIDX( COUNTER, TILE, REGIME_DURATION_NANOS )+(ulong)fd_ulong_find_lsb( mask );
251 0 : ulong prev = prev_tile[ idx ];
252 0 : ulong cur = cur_tile[ idx ];
253 0 : result += cur>=prev ? cur-prev : 0UL;
254 0 : }
255 0 : return result;
256 0 : }
257 :
258 : static ulong
259 0 : total_regime( ulong const * metrics ) {
260 0 : ulong sum = 0UL;
261 0 : for( ulong i=0UL; i<FD_METRICS_ENUM_TILE_REGIME_CNT; i++ ) {
262 0 : sum += metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS )+i ];
263 0 : }
264 0 : return sum;
265 0 : }
266 :
267 : /* Bench */
268 : static ulong tps_sent_samples_idx = 0UL;
269 : static ulong tps_sent_samples[ 200UL ];
270 : /* Replay */
271 : static ulong cups_samples_idx = 0UL;
272 : static ulong cups_samples[ 100UL ];
273 : static ulong sps_samples_idx = 0UL;
274 : static ulong sps_samples[ 200UL ];
275 : static ulong tps_samples_idx = 0UL;
276 : static ulong tps_samples[ 200UL ];
277 : /* Snapshot */
278 : static ulong snapshot_rx_idx = 0UL;
279 : static ulong snapshot_rx_samples[ 100UL ];
280 : static long snap_cur_nanos = 0L;
281 : static long snap_prev_nanos = 0L;
282 : static ulong snap_dt_idx = 0UL;
283 : static long snap_dt_samples[ 200UL ];
284 :
285 : static long
286 0 : wallclock_monotonic( void ) {
287 0 : struct timespec ts;
288 0 : clock_gettime( CLOCK_MONOTONIC, &ts );
289 0 : return (long)ts.tv_sec*(long)1e9+ts.tv_nsec;
290 0 : }
291 :
292 : static double
293 0 : window_seconds( ulong num ) {
294 0 : ulong len = sizeof(snap_dt_samples)/sizeof(snap_dt_samples[0]);
295 0 : ulong cnt = fd_ulong_min( snap_dt_idx, fd_ulong_min( num, len ) );
296 0 : long sum = 0L;
297 0 : for( ulong i=1UL; i<=cnt; i++ ) sum += snap_dt_samples[ (snap_dt_idx-i)%len ];
298 0 : return (double)fd_long_max( sum, 1L )/1e9;
299 0 : }
300 :
301 : static ulong snapshot_acc_idx = 0UL;
302 : static ulong snapshot_acc_samples[ 100UL ];
303 : static ulong snapshot_wr_idx = 0UL;
304 : static ulong snapshot_wr_samples[ 100UL ];
305 : /* Backup */
306 : static ulong backup_acc_idx = 0UL;
307 : static ulong backup_acc_samples[ 100UL ];
308 : static ulong backup_read_idx = 0UL;
309 : static ulong backup_read_samples[ 100UL ];
310 : static ulong backup_comp_idx = 0UL;
311 : static ulong backup_comp_samples[ 100UL ];
312 : static ulong backup_upload_idx = 0UL;
313 : static ulong backup_upload_samples[ 100UL ];
314 : /* Event */
315 : static ulong events_sent_samples_idx = 0UL;
316 : static ulong events_sent_samples[ 100UL ];
317 : static ulong events_acked_samples_idx = 0UL;
318 : static ulong events_acked_samples[ 100UL ];
319 : static ulong event_bytes_written_samples_idx = 0UL;
320 : static ulong event_bytes_written_samples[ 100UL ];
321 : static ulong event_bytes_read_samples_idx = 0UL;
322 : static ulong event_bytes_read_samples[ 100UL ];
323 :
324 : /* Peer discovery follows logistic growth so the per-capita rate
325 : (dn/dt)/n is linear in n and hits zero at n=N_total. A streaming
326 : least-squares of per-capita rate vs count over 150ms buckets projects
327 : N_total.
328 :
329 : The displayed bar is n/N_total slew-limited to 60%/s (the raw
330 : projection can jump when the fit locks on) and capped at 90%. The
331 : final 10% is walked by the table-quiet gap against the tile's
332 : 500ms saturation deadline, so full coincides exactly with the
333 : tile's PEER_SATURATED condition, which is mirrored here. */
334 :
335 : static long gossip_bucket_nanos = 0L;
336 : static ulong gossip_bucket_peers = 0UL;
337 : static double gossip_sx = 0.0, gossip_sy = 0.0, gossip_sxx = 0.0, gossip_sxy = 0.0, gossip_sw = 0.0;
338 : static ulong gossip_peer_hwm = 0UL;
339 : static long gossip_peer_hwm_nanos = 0L;
340 : static long gossip_disp_nanos = 0L;
341 : static double gossip_disp_pct = 0.0;
342 : static double gossip_conv_pct = 0.0;
343 : static int gossip_saturated = 0;
344 :
345 0 : #define GOSSIP_SAT_QUIET_SECS (0.5) /* FD_GOSSIP_PEER_SAT_QUIET_NS */
346 0 : #define GOSSIP_BAR_SLEW (60.0) /* %/s */
347 0 : #define GOSSIP_BAR_FIT_CAP (90.0) /* % from the fit, rest from the quiet gap */
348 :
349 : static void
350 : sample_gossip( config_t const * config,
351 : ulong const * cur_tile,
352 0 : long now ) {
353 0 : ulong tile_idx = fd_topo_find_tile( &config->topo, "gossip", 0UL );
354 0 : if( FD_UNLIKELY( tile_idx==ULONG_MAX || gossip_saturated ) ) return;
355 :
356 0 : ulong const * t = &cur_tile[ tile_idx*FD_METRICS_TOTAL_SZ ];
357 0 : ulong peers = t[ MIDX( GAUGE, GOSSIP, CRDS_PEER_COUNT_STAKED ) ]+t[ MIDX( GAUGE, GOSSIP, CRDS_PEER_COUNT_UNSTAKED ) ];
358 :
359 0 : if( FD_UNLIKELY( peers>gossip_peer_hwm ) ) {
360 0 : gossip_peer_hwm = peers;
361 0 : gossip_peer_hwm_nanos = now;
362 0 : } else if( FD_UNLIKELY( peers>1UL && gossip_peer_hwm_nanos &&
363 0 : (double)(now-gossip_peer_hwm_nanos)/1e9>GOSSIP_SAT_QUIET_SECS ) ) {
364 : /* Mirrors the tile's PEER_SATURATED condition. */
365 0 : gossip_saturated = 1;
366 0 : gossip_conv_pct = 100.0;
367 0 : return;
368 0 : }
369 :
370 : /* Feed the regression once discovery is underway (the entrypoint
371 : alone doesn't count). */
372 0 : if( FD_LIKELY( peers>=10UL ) ) {
373 0 : if( FD_UNLIKELY( !gossip_bucket_nanos ) ) {
374 0 : gossip_bucket_nanos = now;
375 0 : gossip_bucket_peers = peers;
376 0 : } else if( FD_UNLIKELY( (double)(now-gossip_bucket_nanos)/1e9>=0.15 ) ) {
377 0 : double dt = (double)(now-gossip_bucket_nanos)/1e9;
378 0 : double x = 0.5*(double)(peers+gossip_bucket_peers);
379 0 : double y = ((double)peers-(double)gossip_bucket_peers)/dt/x; /* per-capita rate */
380 0 : gossip_sx += x; gossip_sy += y; gossip_sxx += x*x; gossip_sxy += x*y; gossip_sw += 1.0;
381 0 : gossip_bucket_nanos = now;
382 0 : gossip_bucket_peers = peers;
383 0 : }
384 0 : }
385 :
386 0 : double target = 0.0;
387 0 : if( FD_LIKELY( gossip_sw>=4.0 ) ) {
388 0 : double den = gossip_sw*gossip_sxx-gossip_sx*gossip_sx;
389 0 : if( FD_LIKELY( den>1e-9 ) ) {
390 0 : double slope = (gossip_sw*gossip_sxy-gossip_sx*gossip_sy)/den;
391 0 : double intercept = (gossip_sy-slope*gossip_sx)/gossip_sw;
392 0 : if( FD_LIKELY( slope<-1e-12 && intercept>0.0 ) ) {
393 0 : double total = -intercept/slope; /* n where per-capita rate hits zero */
394 0 : target = fd_double_if( total>0.0, 100.0*(double)peers/total, 0.0 );
395 0 : target = fd_double_if( target>GOSSIP_BAR_FIT_CAP, GOSSIP_BAR_FIT_CAP, target );
396 0 : }
397 0 : }
398 0 : }
399 :
400 0 : if( FD_UNLIKELY( !gossip_disp_nanos ) ) gossip_disp_nanos = now;
401 0 : double step = GOSSIP_BAR_SLEW*(double)(now-gossip_disp_nanos)/1e9;
402 0 : gossip_disp_nanos = now;
403 0 : if( FD_LIKELY( target>gossip_disp_pct ) )
404 0 : gossip_disp_pct = fd_double_if( gossip_disp_pct+step>target, target, gossip_disp_pct+step );
405 :
406 0 : double gap = 0.0;
407 0 : if( FD_LIKELY( peers>1UL && gossip_peer_hwm_nanos ) )
408 0 : gap = (double)(now-gossip_peer_hwm_nanos)/1e9/GOSSIP_SAT_QUIET_SECS;
409 :
410 0 : double pct = gossip_disp_pct+(100.0-GOSSIP_BAR_FIT_CAP)*gap;
411 0 : pct = fd_double_if( pct>99.0, 99.0, pct );
412 0 : gossip_conv_pct = fd_double_if( pct>gossip_conv_pct, pct, gossip_conv_pct );
413 0 : }
414 :
415 : /* Accounts */
416 : static ulong accdb_samples_idx = 0UL;
417 : static ulong accdb_acquired_samples[ 200UL ];
418 : static ulong accdb_writable_samples[ 200UL ];
419 : static ulong accdb_missed_samples [ 200UL ];
420 : static ulong accdb_evicted_samples [ 200UL ];
421 : static ulong accdb_waited_samples [ 200UL ];
422 : static ulong accdb_bytes_rd_samples[ 200UL ];
423 : static ulong accdb_bytes_wr_samples[ 200UL ];
424 : static ulong accdb_bytes_cp_samples[ 200UL ];
425 : static ulong accdb_bytes_pe_samples[ 200UL ];
426 : static ulong accdb_evicted_class_samples[ 8UL ][ 200UL ];
427 : static ulong accdb_preevicted_samples[ 200UL ];
428 : static ulong accdb_preevicted_class_samples[ 8UL ][ 200UL ];
429 : static ulong accdb_committed_new_class_samples[ 8UL ][ 200UL ];
430 : static ulong accdb_committed_overwrite_class_samples[ 8UL ][ 200UL ];
431 : /* Repair server */
432 : static ulong shreds_stored_samples_idx = 0UL;
433 : static ulong shreds_stored_sample[ 200UL ] ;
434 : static ulong rserve_rps_valid_samples_idx = 0UL;
435 : static ulong rserve_rps_valid_samples[ 100UL ];
436 : static ulong rserve_rps_invalid_samples_idx = 0UL;
437 : static ulong rserve_rps_invalid_samples[ 100UL ];
438 : static ulong rserve_rps_miss_samples[ 100UL ];
439 : static ulong rserve_rps_sigvfy_samples[ 100UL ];
440 : static ulong rserve_rps_stale_samples[ 100UL ];
441 : static ulong rserve_rps_other_rej_samples[ 100UL ];
442 :
443 0 : #define RESET "\033[0m"
444 : #define BOLD "\033[1m"
445 : #define DIM "\033[2m"
446 :
447 0 : #define RED "\033[31m"
448 0 : #define GREEN "\033[32m"
449 : #define ORANGE "\033[38;5;208m"
450 0 : #define YELLOW "\033[33m"
451 : #define BLUE "\033[34m"
452 : #define MAGENTA "\033[35m"
453 : #define CYAN "\033[36m"
454 :
455 : #define BGREEN "\033[92m"
456 : #define BYELLOW "\033[93m"
457 :
458 : /* Cluster accents matching the GUI palette. */
459 0 : #define CLUS_MAINNET "\033[38;5;43m" /* #1CE7C2 */
460 0 : #define CLUS_TESTNET "\033[38;5;178m" /* #E7B81C */
461 0 : #define CLUS_DEVNET "\033[38;5;166m" /* #E7601C */
462 0 : #define CLUS_PYTHNET "\033[38;5;129m" /* #9D1CE7 */
463 0 : #define CLUS_PYTHTEST "\033[38;5;162m" /* #E71C88 */
464 0 : #define CLUS_UNKNOWN "\033[38;5;245m" /* #898989 */
465 :
466 : #define CLEARLN "\033[K"
467 :
468 : /* Row grammar: an accent tinted glyph + bold colored section label
469 : in a fixed 12 char column, a dim divider, then dim lowercase keys
470 : with plain values so the data carries the visual weight. ROWH()
471 : opens a section row (pass the label pre-padded to 12 chars), ROWC
472 : opens a continuation row aligned under the divider, K() emits one
473 : key, U() a dim unit suffix. Icons are single cell glyphs from the
474 : geometric shapes block so every row aligns in every font. */
475 : #define ROWH( icon, color, label ) color icon " " BOLD label RESET DIM "│" RESET
476 : #define ROWC " " DIM "│" RESET
477 : #define K( key ) " " DIM key " " RESET
478 : #define U( unit ) DIM unit RESET
479 :
480 : /* Severity color for utilization style percentages: quiet when calm,
481 : loud only when it matters. */
482 : static char const *
483 0 : sev_color( double pct ) {
484 0 : if( FD_UNLIKELY( pct>=85.0 ) ) return RED;
485 0 : if( FD_UNLIKELY( pct>=50.0 ) ) return YELLOW;
486 0 : return "";
487 0 : }
488 :
489 : /* Unicode block progress bar, filled green with a dim tail. */
490 : static char *
491 : fmt_bar( char * buf,
492 : ulong buf_sz,
493 : double pct,
494 0 : ulong width ) {
495 0 : pct = fd_double_if( pct<0.0, 0.0, fd_double_if( pct>100.0, 100.0, pct ) );
496 0 : ulong filled = (ulong)( pct*(double)width/100.0+0.5 );
497 0 : ulong len = 0UL, l;
498 0 : FD_TEST( fd_cstr_printf_check( buf, buf_sz, &len, GREEN ) );
499 0 : for( ulong i=0UL; i<filled; i++ ) { FD_TEST( fd_cstr_printf_check( buf+len, buf_sz-len, &l, "█" ) ); len += l; }
500 0 : FD_TEST( fd_cstr_printf_check( buf+len, buf_sz-len, &l, DIM ) ); len += l;
501 0 : for( ulong i=filled; i<width; i++ ) { FD_TEST( fd_cstr_printf_check( buf+len, buf_sz-len, &l, "░" ) ); len += l; }
502 0 : FD_TEST( fd_cstr_printf_check( buf+len, buf_sz-len, &l, RESET ) );
503 0 : return buf;
504 0 : }
505 :
506 : #define BAR( pct, width ) (__extension__({ \
507 : fmt_bar( fd_alloca_check( 1UL, 256UL ), 256UL, pct, width ); \
508 : }))
509 :
510 0 : #define PRINT(...) do { \
511 0 : ulong _len; \
512 0 : FD_TEST( fd_cstr_printf_check( frame_buf+frame_len, sizeof(frame_buf)-frame_len, &_len, __VA_ARGS__ ) ); \
513 0 : frame_len += _len; \
514 0 : } while(0)
515 :
516 0 : #define SNAP_DT_NS() (fd_long_max( snap_cur_nanos-snap_prev_nanos, 1L ))
517 :
518 : #define DIFF_LINK_BYTES( link_name, metric_type, metric_subtype, metric ) (__extension__({ \
519 : long bytes = diff_link( config, link_name, prev_link, cur_link, MIDX( metric_type, metric_subtype, metric ) ); \
520 : fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, (long)((double)bytes*1e9/(double)SNAP_DT_NS()) ); \
521 : }))
522 :
523 0 : #define DIFF_BYTES( tile_name, metric_type, metric_subtype, metric ) (__extension__({ \
524 0 : ulong bytes = diff_tile( config, tile_name, prev_tile, cur_tile, MIDX( metric_type, metric_subtype, metric ) ); \
525 0 : fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, (long)((double)bytes*1e9/(double)SNAP_DT_NS()) ); \
526 0 : }))
527 :
528 0 : #define COUNT( count ) (__extension__({ \
529 0 : fmt_count( fd_alloca_check( 1UL, 64UL ), 64UL, count ); \
530 0 : }))
531 :
532 0 : #define COUNTF( count ) (__extension__({ \
533 0 : fmt_countf( fd_alloca_check( 1UL, 64UL ), 64UL, count ); \
534 0 : }))
535 :
536 0 : #define COUNT_T( count ) (__extension__({ \
537 0 : fmt_count_tight( fd_alloca_check( 1UL, 32UL ), 32UL, count ); \
538 0 : }))
539 :
540 0 : #define COUNTF_T( count ) (__extension__({ \
541 0 : fmt_countf_tight( fd_alloca_check( 1UL, 32UL ), 32UL, count ); \
542 0 : }))
543 :
544 : static int
545 : write_bench( config_t const * config,
546 : ulong const * cur_tile,
547 0 : ulong const * prev_tile ) {
548 0 : if( FD_UNLIKELY( fd_topo_find_tile( &config->topo, "benchs", 0UL )==ULONG_MAX ) ) return 0;
549 :
550 0 : ulong tps_sum = 0UL;
551 0 : ulong num_tps_samples = fd_ulong_min( tps_sent_samples_idx, sizeof(tps_sent_samples)/sizeof(tps_sent_samples[0]));
552 0 : for( ulong i=0UL; i<num_tps_samples; i++ ) tps_sum += tps_sent_samples[ i ];
553 0 : char * tps_str = COUNTF( (double)tps_sum/window_seconds( num_tps_samples ) );
554 :
555 0 : PRINT( ROWH( "◎", BGREEN, "bench " )
556 0 : K( "sent tps" ) "%s"
557 0 : K( "benchg" ), tps_str );
558 0 : for( ulong i=0UL; i<config->topo.tile_cnt; i++ ) {
559 0 : if( FD_LIKELY( strcmp( config->topo.tiles[ i ].name, "benchg" ) ) ) continue;
560 :
561 0 : ulong total_ticks = total_regime( &cur_tile[ i*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ i*FD_METRICS_TOTAL_SZ ] );
562 0 : double backp_pct = 100.0*(double)tile_regime( prev_tile, cur_tile, i, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)total_ticks;
563 0 : double idle_pct = 100.0*(double)tile_regime( prev_tile, cur_tile, i, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)total_ticks;
564 0 : double busy_pct = 100.0 - idle_pct - backp_pct;
565 :
566 0 : PRINT( " %s%.1f" U( "%%" ) RESET, sev_color( busy_pct ), busy_pct );
567 0 : }
568 :
569 0 : PRINT( K( "benchs" ) );
570 0 : for( ulong i=0UL; i<config->topo.tile_cnt; i++ ) {
571 0 : if( FD_LIKELY( strcmp( config->topo.tiles[ i ].name, "benchs" ) ) ) continue;
572 :
573 0 : ulong total_ticks = total_regime( &cur_tile[ i*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ i*FD_METRICS_TOTAL_SZ ] );
574 0 : double backp_pct = 100.0*(double)tile_regime( prev_tile, cur_tile, i, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)total_ticks;
575 0 : double idle_pct = 100.0*(double)tile_regime( prev_tile, cur_tile, i, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)total_ticks;
576 0 : double busy_pct = 100.0 - idle_pct - backp_pct;
577 :
578 0 : PRINT( " %s%.1f" U( "%%" ) RESET, sev_color( busy_pct ), busy_pct );
579 0 : }
580 :
581 0 : PRINT( CLEARLN "\n" );
582 0 : return 1;
583 0 : }
584 :
585 : static void
586 : write_backtest( config_t const * config,
587 0 : ulong const * cur_tile ) {
588 0 : ulong backt_idx = fd_topo_find_tile( &config->topo, "backt", 0UL );
589 0 : ulong start_slot = cur_tile[ backt_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, BACKT, START_SLOT ) ];
590 0 : ulong final_slot = cur_tile[ backt_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, BACKT, END_SLOT ) ];
591 :
592 0 : ulong replay_idx = fd_topo_find_tile( &config->topo, "replay", 0UL );
593 0 : ulong current_slot = cur_tile[ replay_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPLAY, ROOT_SLOT ) ];
594 0 : current_slot = current_slot ? current_slot : start_slot;
595 :
596 0 : ulong completed_slots = current_slot-start_slot;
597 :
598 0 : if( FD_UNLIKELY( !final_slot ) ) { /* unbounded */
599 0 : PRINT( ROWH( "◇", BGREEN, "backtest " )
600 0 : K( "slots" ) "%lu" U( " / ?" ) CLEARLN "\n", completed_slots );
601 0 : return;
602 0 : }
603 :
604 0 : ulong total_slots = final_slot-start_slot;
605 0 : double progress = total_slots ? 100.0 * (double)completed_slots / (double)total_slots : 100.0;
606 0 : PRINT( ROWH( "◇", BGREEN, "backtest " )
607 0 : " %s " BOLD "%5.1f" RESET U( "%%" )
608 0 : K( "slots" ) "%lu" U( " /" ) " %lu" CLEARLN "\n",
609 0 : BAR( progress, 20UL ), progress, completed_slots, total_slots );
610 0 : }
611 :
612 : static void
613 : write_snapshots( config_t const * config,
614 : ulong const * cur_tile,
615 0 : ulong const * prev_tile ) {
616 0 : ulong snapct_idx = fd_topo_find_tile( &config->topo, "snapct", 0UL );
617 0 : ulong snapdc_tile_cnt = fd_topo_tile_name_cnt( &config->topo, "snapdc" );
618 0 : ulong snapin_tile_cnt = fd_topo_tile_name_cnt( &config->topo, "snapin" );
619 0 : ulong state = cur_tile[ snapct_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPCT, LOAD_STATE ) ];
620 :
621 0 : double progress = 0.0;
622 0 : int incremental = 0;
623 0 : switch( state ) {
624 0 : case FD_SNAPCT_STATE_WAITING_FOR_PEERS:
625 0 : case FD_SNAPCT_STATE_WAITING_FOR_PEERS_INCREMENTAL:
626 0 : case FD_SNAPCT_STATE_COLLECTING_PEERS:
627 0 : case FD_SNAPCT_STATE_COLLECTING_PEERS_INCREMENTAL:
628 0 : break;
629 0 : case FD_SNAPCT_STATE_READING_INCREMENTAL_FILE:
630 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_FINI:
631 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_DONE:
632 0 : case FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP:
633 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_FINI:
634 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_DONE:
635 0 : incremental = 1;
636 0 : __attribute__((fallthrough));
637 0 : case FD_SNAPCT_STATE_READING_FULL_FILE:
638 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_FILE_FINI:
639 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_FILE_DONE:
640 0 : case FD_SNAPCT_STATE_READING_FULL_HTTP:
641 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_FINI:
642 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_DONE: {
643 : /* Progress is the compressed-equivalent of bytes fully applied
644 : (parse+write consumption, converted back through the decompress
645 : ratio), same as snapshot-load, rather than bytes merely
646 : downloaded by snapct. */
647 0 : ulong consumed, dc_in, dc_out, size_bytes;
648 0 : if( FD_UNLIKELY( incremental ) ) {
649 0 : consumed = ULONG_MAX;
650 0 : for( ulong i=0UL; i<snapin_tile_cnt; i++ ) {
651 0 : ulong snapin_idx = fd_topo_find_tile( &config->topo, "snapin", i );
652 0 : consumed = fd_ulong_min( consumed, cur_tile[ snapin_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPIN, PARSE_PROGRESS_BYTES_INCREMENTAL ) ] );
653 0 : }
654 0 : dc_in = 0UL;
655 0 : dc_out = 0UL;
656 0 : for( ulong i=0UL; i<snapdc_tile_cnt; i++ ) {
657 0 : ulong snapdc_idx = fd_topo_find_tile( &config->topo, "snapdc", i );
658 0 : dc_in += cur_tile[ snapdc_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPDC, COMPRESSED_PROGRESS_BYTES_INCREMENTAL ) ];
659 0 : dc_out += cur_tile[ snapdc_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPDC, DECOMPRESSED_PROGRESS_BYTES_INCREMENTAL ) ];
660 0 : }
661 0 : size_bytes = cur_tile[ snapct_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPCT, READ_EXPECTED_BYTES_INCREMENTAL ) ];
662 0 : } else {
663 0 : consumed = ULONG_MAX;
664 0 : for( ulong i=0UL; i<snapin_tile_cnt; i++ ) {
665 0 : ulong snapin_idx = fd_topo_find_tile( &config->topo, "snapin", i );
666 0 : consumed = fd_ulong_min( consumed, cur_tile[ snapin_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPIN, PARSE_PROGRESS_BYTES_FULL ) ] );
667 0 : }
668 0 : dc_in = 0UL;
669 0 : dc_out = 0UL;
670 0 : for( ulong i=0UL; i<snapdc_tile_cnt; i++ ) {
671 0 : ulong snapdc_idx = fd_topo_find_tile( &config->topo, "snapdc", i );
672 0 : dc_in += cur_tile[ snapdc_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPDC, COMPRESSED_PROGRESS_BYTES_FULL ) ];
673 0 : dc_out += cur_tile[ snapdc_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPDC, DECOMPRESSED_PROGRESS_BYTES_FULL ) ];
674 0 : }
675 0 : size_bytes = cur_tile[ snapct_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPCT, READ_EXPECTED_BYTES_FULL ) ];
676 0 : }
677 0 : double done_comp = dc_out ? (double)dc_in*( (double)consumed/(double)dc_out ) : 0.0;
678 0 : if( FD_LIKELY( size_bytes ) ) progress = fd_double_if( done_comp>(double)size_bytes, 100.0, 100.0*done_comp/(double)size_bytes );
679 0 : break;
680 0 : }
681 0 : case FD_SNAPCT_STATE_SHUTDOWN:
682 0 : progress = 100.0;
683 0 : break;
684 0 : }
685 :
686 0 : ulong snap_rx_sum = 0UL;
687 0 : ulong num_snap_rx_samples = fd_ulong_min( snapshot_rx_idx, sizeof(snapshot_rx_samples)/sizeof(snapshot_rx_samples[0]) );
688 0 : for( ulong i=0UL; i<num_snap_rx_samples; i++ ) snap_rx_sum += snapshot_rx_samples[ i ];
689 0 : double megabytes_per_second = 0.0;
690 0 : if( FD_LIKELY( num_snap_rx_samples ) ) megabytes_per_second = (double)snap_rx_sum/window_seconds( num_snap_rx_samples )/1e6;
691 :
692 0 : ulong accounts_sum = 0UL;
693 0 : ulong num_accounts_samples = fd_ulong_min( snapshot_acc_idx, sizeof(snapshot_acc_samples)/sizeof(snapshot_acc_samples[0]) );
694 0 : for( ulong i=0UL; i<num_accounts_samples; i++ ) accounts_sum += snapshot_acc_samples[ i ];
695 0 : double million_accounts_per_second = 0.0;
696 0 : if( FD_LIKELY( num_accounts_samples ) ) million_accounts_per_second = (double)accounts_sum/window_seconds( num_accounts_samples )/1e6;
697 :
698 0 : ulong snap_wr_sum = 0UL;
699 0 : ulong num_snap_wr_samples = fd_ulong_min( snapshot_wr_idx, sizeof(snapshot_wr_samples)/sizeof(snapshot_wr_samples[0]) );
700 0 : for( ulong i=0UL; i<num_snap_wr_samples; i++ ) snap_wr_sum += snapshot_wr_samples[ i ];
701 0 : double wr_megabytes_per_second = 0.0;
702 0 : if( FD_LIKELY( num_snap_wr_samples ) ) wr_megabytes_per_second = (double)snap_wr_sum/window_seconds( num_snap_wr_samples )/1e6;
703 :
704 0 : ulong snapct_total_ticks = total_regime( &cur_tile[ snapct_idx*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ snapct_idx*FD_METRICS_TOTAL_SZ ] );
705 0 : ulong snapld_total_ticks = total_regime( &cur_tile[ fd_topo_find_tile( &config->topo, "snapld", 0UL )*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ fd_topo_find_tile( &config->topo, "snapld", 0UL )*FD_METRICS_TOTAL_SZ ] );
706 0 : ulong snapdc_total_ticks = 0UL;
707 0 : for( ulong i=0UL; i<snapdc_tile_cnt; i++ ) {
708 0 : ulong snapdc_idx = fd_topo_find_tile( &config->topo, "snapdc", i );
709 0 : snapdc_total_ticks += total_regime( &cur_tile[ snapdc_idx*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ snapdc_idx*FD_METRICS_TOTAL_SZ ] );
710 0 : }
711 0 : ulong snapin_total_ticks = 0UL;
712 0 : for( ulong i=0UL; i<snapin_tile_cnt; i++ ) {
713 0 : ulong idx = fd_topo_find_tile( &config->topo, "snapin", i );
714 0 : snapin_total_ticks += total_regime( &cur_tile[ idx*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ idx*FD_METRICS_TOTAL_SZ ] );
715 0 : }
716 0 : snapct_total_ticks = fd_ulong_max( snapct_total_ticks, 1UL );
717 0 : snapld_total_ticks = fd_ulong_max( snapld_total_ticks, 1UL );
718 0 : snapdc_total_ticks = fd_ulong_max( snapdc_total_ticks, 1UL );
719 0 : snapin_total_ticks = fd_ulong_max( snapin_total_ticks, 1UL );
720 :
721 0 : double snapct_backp_pct = 100.0*(double)diff_tile_regime( config, "snapct", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)snapct_total_ticks;
722 0 : double snapld_backp_pct = 100.0*(double)diff_tile_regime( config, "snapld", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)snapld_total_ticks;
723 0 : double snapdc_backp_pct = 100.0*(double)diff_tile_regime( config, "snapdc", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)snapdc_total_ticks;
724 0 : double snapin_backp_pct = 100.0*(double)diff_tile_regime( config, "snapin", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)snapin_total_ticks;
725 :
726 0 : double snapct_idle_pct = 100.0*(double)diff_tile_regime( config, "snapct", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)snapct_total_ticks;
727 0 : double snapld_idle_pct = 100.0*(double)diff_tile_regime( config, "snapld", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)snapld_total_ticks;
728 0 : double snapdc_idle_pct = 100.0*(double)diff_tile_regime( config, "snapdc", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)snapdc_total_ticks;
729 0 : double snapin_idle_pct = 100.0*(double)diff_tile_regime( config, "snapin", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)snapin_total_ticks;
730 :
731 0 : double busy [ 4 ] = { 100.0-snapct_idle_pct-snapct_backp_pct,
732 0 : 100.0-snapld_idle_pct-snapld_backp_pct,
733 0 : 100.0-snapdc_idle_pct-snapdc_backp_pct,
734 0 : 100.0-snapin_idle_pct-snapin_backp_pct };
735 0 : double backp[ 4 ] = { snapct_backp_pct, snapld_backp_pct, snapdc_backp_pct, snapin_backp_pct };
736 0 : char const * stage[ 4 ] = { "ct", "ld", "dc", "in" };
737 :
738 0 : PRINT( ROWH( "◐", BYELLOW, "snapshot " )
739 0 : " %s " BOLD "%5.1f" RESET U( "%%" )
740 0 : K( "state" ) "%s"
741 0 : K( "rx" ) "%3.0f" U( " MB/s" )
742 0 : K( "wr" ) "%3.0f" U( " MB/s" )
743 0 : K( "acc" ) "%3.1f" U( " M/s" )
744 0 : K( "busy" ),
745 0 : BAR( progress, 20UL ),
746 0 : progress,
747 0 : fd_snapct_state_str( (int)state ),
748 0 : megabytes_per_second,
749 0 : wr_megabytes_per_second,
750 0 : million_accounts_per_second );
751 0 : for( ulong i=0UL; i<4UL; i++ )
752 0 : PRINT( " " U( "%s" ) " %s%3.0f" U( "%%" ) RESET, stage[ i ], sev_color( busy[ i ] ), busy[ i ] );
753 0 : PRINT( K( "backp" ) );
754 0 : for( ulong i=0UL; i<4UL; i++ )
755 0 : PRINT( " " U( "%s" ) " %s%3.0f" U( "%%" ) RESET, stage[ i ], sev_color( backp[ i ] ), backp[ i ] );
756 0 : PRINT( CLEARLN "\n" );
757 0 : }
758 :
759 : static long
760 : diff_tile_idx( ulong const * prev_tile,
761 : ulong const * cur_tile,
762 : ulong tile_idx,
763 0 : ulong metric_off ) {
764 0 : return (long)cur_tile [ tile_idx*FD_METRICS_TOTAL_SZ+metric_off ] -
765 0 : (long)prev_tile[ tile_idx*FD_METRICS_TOTAL_SZ+metric_off ];
766 0 : }
767 :
768 : static void
769 : accdb_per_tile_offsets( char const * name,
770 0 : ulong * offs /* 11 entries: acquired, writable, missed, waited, rd, wr, cp, evicted_class_base, preevicted_class_base, committed_new_class_base, committed_overwrite_class_base */ ) {
771 0 : if( !strcmp( name, "execle" ) ) {
772 0 : offs[0] =MIDX(COUNTER,EXECLE,ACCDB_ACCOUNT_READONLY_ACQUIRED ); offs[1]=MIDX(COUNTER,EXECLE,ACCDB_ACCOUNT_WRITABLE_ACQUIRED);
773 0 : offs[2] =MIDX(COUNTER,EXECLE,ACCDB_ACCOUNT_CACHE_MISSED ); offs[3]=MIDX(COUNTER,EXECLE,ACCDB_ACCOUNT_WAITED );
774 0 : offs[4] =MIDX(COUNTER,EXECLE,ACCDB_DISK_READ_BYTES ); offs[5]=MIDX(COUNTER,EXECLE,ACCDB_DISK_WRITTEN_BYTES );
775 0 : offs[6] =MIDX(COUNTER,EXECLE,ACCDB_COPIED_BYTES ); offs[7]=MIDX(COUNTER,EXECLE,ACCDB_ACCOUNT_EVICTED );
776 0 : offs[8] =ULONG_MAX ; offs[9]=MIDX(COUNTER,EXECLE,ACCDB_ACCOUNT_NEW_COMMITTED );
777 0 : offs[10]=MIDX(COUNTER,EXECLE,ACCDB_ACCOUNT_OVERWRITE_COMMITTED);
778 0 : } else if( !strcmp( name, "execrp" ) ) {
779 0 : offs[0] =MIDX(COUNTER,EXECRP,ACCDB_ACCOUNT_READONLY_ACQUIRED ); offs[1]=MIDX(COUNTER,EXECRP,ACCDB_ACCOUNT_WRITABLE_ACQUIRED);
780 0 : offs[2] =MIDX(COUNTER,EXECRP,ACCDB_ACCOUNT_CACHE_MISSED ); offs[3]=MIDX(COUNTER,EXECRP,ACCDB_ACCOUNT_WAITED );
781 0 : offs[4] =MIDX(COUNTER,EXECRP,ACCDB_DISK_READ_BYTES ); offs[5]=MIDX(COUNTER,EXECRP,ACCDB_DISK_WRITTEN_BYTES );
782 0 : offs[6] =MIDX(COUNTER,EXECRP,ACCDB_COPIED_BYTES ); offs[7]=MIDX(COUNTER,EXECRP,ACCDB_ACCOUNT_EVICTED );
783 0 : offs[8] =ULONG_MAX ; offs[9]=MIDX(COUNTER,EXECRP,ACCDB_ACCOUNT_NEW_COMMITTED );
784 0 : offs[10]=MIDX(COUNTER,EXECRP,ACCDB_ACCOUNT_OVERWRITE_COMMITTED);
785 0 : } else if( !strcmp( name, "replay" ) ) {
786 0 : offs[0] =MIDX(COUNTER,REPLAY,ACCDB_ACCOUNT_READONLY_ACQUIRED ); offs[1]=MIDX(COUNTER,REPLAY,ACCDB_ACCOUNT_WRITABLE_ACQUIRED);
787 0 : offs[2] =MIDX(COUNTER,REPLAY,ACCDB_ACCOUNT_CACHE_MISSED ); offs[3]=MIDX(COUNTER,REPLAY,ACCDB_ACCOUNT_WAITED );
788 0 : offs[4] =MIDX(COUNTER,REPLAY,ACCDB_DISK_READ_BYTES ); offs[5]=MIDX(COUNTER,REPLAY,ACCDB_DISK_WRITTEN_BYTES );
789 0 : offs[6] =MIDX(COUNTER,REPLAY,ACCDB_COPIED_BYTES ); offs[7]=MIDX(COUNTER,REPLAY,ACCDB_ACCOUNT_EVICTED );
790 0 : offs[8] =ULONG_MAX ; offs[9]=MIDX(COUNTER,REPLAY,ACCDB_ACCOUNT_NEW_COMMITTED );
791 0 : offs[10]=MIDX(COUNTER,REPLAY,ACCDB_ACCOUNT_OVERWRITE_COMMITTED);
792 0 : } else if( !strcmp( name, "accdb" ) ) {
793 : /* The accdb tile only runs background work (compact, preevict,
794 : advance_root, purge); it never acquires/releases. Sentinel
795 : everything that comes from the acquire/release path. */
796 0 : offs[0] =ULONG_MAX ; offs[1]=ULONG_MAX ;
797 0 : offs[2] =ULONG_MAX ; offs[3]=ULONG_MAX ;
798 0 : offs[4] =MIDX(COUNTER,ACCDB,DISK_READ_BYTES ); offs[5]=MIDX(COUNTER,ACCDB,DISK_WRITTEN_BYTES );
799 0 : offs[6] =ULONG_MAX ; offs[7]=ULONG_MAX ;
800 0 : offs[8] =MIDX(COUNTER,ACCDB,ACCOUNT_PREEVICTED ); offs[9]=ULONG_MAX ;
801 0 : offs[10]=ULONG_MAX;
802 0 : } else if( !strcmp( name, "rpc" ) ) {
803 : /* RPC is a read-only accdb consumer. It only emits the subset
804 : of counters that fd_accdb_read_one_nocache touches; everything
805 : else is sentinel and skipped by sample_accdb. */
806 0 : offs[0] =MIDX(COUNTER,RPC,ACCDB_ACCOUNT_READONLY_ACQUIRED); offs[1]=ULONG_MAX;
807 0 : offs[2] =MIDX(COUNTER,RPC,ACCDB_ACCOUNT_CACHE_MISSED); offs[3]=MIDX(COUNTER,RPC,ACCDB_ACCOUNT_WAITED);
808 0 : offs[4] =MIDX(COUNTER,RPC,ACCDB_DISK_READ_BYTES ); offs[5]=ULONG_MAX;
809 0 : offs[6] =MIDX(COUNTER,RPC,ACCDB_COPIED_BYTES ); offs[7]=ULONG_MAX;
810 0 : offs[8] =ULONG_MAX; offs[9]=ULONG_MAX;
811 0 : offs[10]=ULONG_MAX;
812 0 : } else if( !strcmp( name, "resolv" ) ) {
813 : /* Resolv is a read-only accdb consumer (address lookup table
814 : reads on the receive path). Same RO subset as RPC. */
815 0 : offs[0] =MIDX(COUNTER,RESOLV,ACCDB_ACCOUNT_READONLY_ACQUIRED ); offs[1]=ULONG_MAX;
816 0 : offs[2] =MIDX(COUNTER,RESOLV,ACCDB_ACCOUNT_CACHE_MISSED); offs[3]=MIDX(COUNTER,RESOLV,ACCDB_ACCOUNT_WAITED);
817 0 : offs[4] =MIDX(COUNTER,RESOLV,ACCDB_DISK_READ_BYTES ); offs[5]=ULONG_MAX;
818 0 : offs[6] =MIDX(COUNTER,RESOLV,ACCDB_COPIED_BYTES ); offs[7]=ULONG_MAX;
819 0 : offs[8] =ULONG_MAX; offs[9]=ULONG_MAX;
820 0 : offs[10]=ULONG_MAX;
821 0 : } else {
822 0 : for( ulong i=0UL; i<11UL; i++ ) offs[i] = ULONG_MAX;
823 0 : }
824 0 : }
825 :
826 : static void
827 : sample_accdb( config_t const * config,
828 : ulong const * prev_tile,
829 0 : ulong const * cur_tile ) {
830 0 : long acquired = 0L, writable = 0L, missed = 0L, evicted = 0L, waited = 0L;
831 0 : long bytes_rd = 0L, bytes_wr = 0L, bytes_cp = 0L, bytes_pe = 0L;
832 0 : long preevicted = 0L;
833 0 : long evicted_class[ 8 ] = {0};
834 0 : long preevicted_class[ 8 ] = {0};
835 0 : long committed_new_class[ 8 ] = {0};
836 0 : long committed_overwrite_class[ 8 ] = {0};
837 :
838 0 : for( ulong i=0UL; i<config->topo.tile_cnt; i++ ) {
839 0 : ulong offs[11];
840 0 : accdb_per_tile_offsets( config->topo.tiles[ i ].name, offs );
841 0 : if( offs[0]!=ULONG_MAX ) {
842 0 : for( ulong c=0UL; c<8UL; c++ ) acquired += diff_tile_idx( prev_tile, cur_tile, i, offs[0] + c );
843 0 : }
844 0 : if( offs[1]!=ULONG_MAX ) {
845 0 : for( ulong c=0UL; c<8UL; c++ ) writable += diff_tile_idx( prev_tile, cur_tile, i, offs[1] + c );
846 0 : }
847 0 : if( offs[3]!=ULONG_MAX ) waited += diff_tile_idx( prev_tile, cur_tile, i, offs[3] );
848 0 : if( offs[4]!=ULONG_MAX ) bytes_rd += diff_tile_idx( prev_tile, cur_tile, i, offs[4] );
849 0 : if( offs[6]!=ULONG_MAX ) bytes_cp += diff_tile_idx( prev_tile, cur_tile, i, offs[6] );
850 0 : if( offs[5]!=ULONG_MAX ) {
851 0 : long this_wr = diff_tile_idx( prev_tile, cur_tile, i, offs[5] );
852 0 : if( !strcmp( config->topo.tiles[ i ].name, "accdb" ) ) bytes_pe += this_wr;
853 0 : else bytes_wr += this_wr;
854 0 : }
855 0 : for( ulong c=0UL; c<8UL; c++ ) {
856 0 : if( offs[2]!=ULONG_MAX ) missed += diff_tile_idx( prev_tile, cur_tile, i, offs[2] + c );
857 0 : if( offs[7]!=ULONG_MAX ) {
858 0 : long d = diff_tile_idx( prev_tile, cur_tile, i, offs[7] + c );
859 0 : evicted_class[ c ] += d;
860 0 : evicted += d;
861 0 : }
862 0 : if( offs[8]!=ULONG_MAX ) {
863 0 : long d = diff_tile_idx( prev_tile, cur_tile, i, offs[8] + c );
864 0 : preevicted_class[ c ] += d;
865 0 : preevicted += d;
866 0 : }
867 0 : if( offs[9] !=ULONG_MAX ) committed_new_class [ c ] += diff_tile_idx( prev_tile, cur_tile, i, offs[9] + c );
868 0 : if( offs[10]!=ULONG_MAX ) committed_overwrite_class[ c ] += diff_tile_idx( prev_tile, cur_tile, i, offs[10] + c );
869 0 : }
870 0 : }
871 :
872 0 : ulong slot = accdb_samples_idx % (sizeof(accdb_acquired_samples)/sizeof(accdb_acquired_samples[0]));
873 0 : accdb_acquired_samples[ slot ] = (ulong)acquired;
874 0 : accdb_writable_samples[ slot ] = (ulong)writable;
875 0 : accdb_missed_samples [ slot ] = (ulong)missed;
876 0 : accdb_evicted_samples [ slot ] = (ulong)evicted;
877 0 : accdb_waited_samples [ slot ] = (ulong)waited;
878 0 : accdb_bytes_rd_samples[ slot ] = (ulong)bytes_rd;
879 0 : accdb_bytes_wr_samples[ slot ] = (ulong)bytes_wr;
880 0 : accdb_bytes_cp_samples[ slot ] = (ulong)bytes_cp;
881 0 : accdb_bytes_pe_samples[ slot ] = (ulong)bytes_pe;
882 0 : accdb_preevicted_samples[ slot ] = (ulong)preevicted;
883 0 : for( ulong c=0UL; c<8UL; c++ ) {
884 0 : accdb_evicted_class_samples [ c ][ slot ] = (ulong)evicted_class [ c ];
885 0 : accdb_preevicted_class_samples [ c ][ slot ] = (ulong)preevicted_class [ c ];
886 0 : accdb_committed_new_class_samples [ c ][ slot ] = (ulong)committed_new_class [ c ];
887 0 : accdb_committed_overwrite_class_samples[ c ][ slot ] = (ulong)committed_overwrite_class[ c ];
888 0 : }
889 0 : accdb_samples_idx++;
890 0 : }
891 :
892 : static uint
893 : write_accdb( config_t const * config,
894 : ulong const * cur_tile,
895 0 : ulong const * prev_tile ) {
896 0 : ulong accdb_tile_idx = fd_topo_find_tile( &config->topo, "accdb", 0UL );
897 0 : if( accdb_tile_idx==ULONG_MAX ) return 0U;
898 :
899 0 : ulong const * t = cur_tile + accdb_tile_idx*FD_METRICS_TOTAL_SZ;
900 :
901 0 : ulong accdb_total_ticks = total_regime( &cur_tile[ accdb_tile_idx*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ accdb_tile_idx*FD_METRICS_TOTAL_SZ ] );
902 0 : accdb_total_ticks = fd_ulong_max( accdb_total_ticks, 1UL );
903 0 : double accdb_backp_pct = 100.0*(double)diff_tile_regime( config, "accdb", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)accdb_total_ticks;
904 0 : double accdb_idle_pct = 100.0*(double)diff_tile_regime( config, "accdb", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)accdb_total_ticks;
905 0 : double accdb_busy_pct = 100.0 - accdb_backp_pct - accdb_idle_pct;
906 :
907 0 : ulong acct_cnt = t[ MIDX( GAUGE, ACCDB, ACCOUNT_USED ) ];
908 0 : ulong acct_cap = t[ MIDX( GAUGE, ACCDB, ACCOUNT_CAPACITY ) ];
909 0 : ulong used_bytes = t[ MIDX( GAUGE, ACCDB, DISK_USED_BYTES ) ];
910 0 : ulong current_bytes = t[ MIDX( GAUGE, ACCDB, DISK_CONSUMED_BYTES ) ];
911 0 : ulong alloc_bytes = t[ MIDX( GAUGE, ACCDB, DISK_ALLOCATED_BYTES ) ];
912 0 : ulong in_compaction = t[ MIDX( GAUGE, ACCDB, IS_COMPACTING ) ];
913 0 : ulong compact_req = t[ MIDX( COUNTER, ACCDB, COMPACTION_REQUESTED ) ];
914 0 : ulong compact_done = t[ MIDX( COUNTER, ACCDB, COMPACTION_COMPLETED ) ];
915 :
916 0 : ulong frag_bytes = current_bytes>used_bytes ? current_bytes-used_bytes : 0UL;
917 0 : double data_gb = (double)alloc_bytes/1e9;
918 0 : double live_gb = (double)used_bytes/1e9;
919 0 : double frag_gb = (double)frag_bytes/1e9;
920 0 : double frag_pct = current_bytes ? 100.0*(double)frag_bytes/(double)current_bytes : 0.0;
921 0 : double index_pct = acct_cap ? 100.0*(double)acct_cnt/(double)acct_cap : 0.0;
922 :
923 0 : PRINT( ROWH( "■", GREEN, "accounts " )
924 0 : K( "cache" ) "%lu" U( " GiB" )
925 0 : K( "disk" ) "%.1f" U( " GB" )
926 0 : K( "live" ) "%.1f" U( " GB" )
927 0 : K( "frag" ) "%.1f" U( " GB" ) " %s%4.1f" U( "%%" ) RESET
928 0 : K( "index" ) "%s%4.1f" U( "%%" ) RESET " " U( "%.1fM/%.1fM" )
929 0 : K( "compact" ) "%s " U( "%lu/%lu" )
930 0 : K( "busy" ) "%s%3.0f" U( "%%" ) RESET CLEARLN "\n",
931 0 : config->firedancer.accounts.cache_size_gib,
932 0 : data_gb, live_gb,
933 0 : frag_gb, sev_color( frag_pct ), frag_pct,
934 0 : sev_color( index_pct ), index_pct, (double)acct_cnt/1e6, (double)acct_cap/1e6,
935 0 : in_compaction ? YELLOW "running" RESET : DIM "idle" RESET, compact_done, compact_req,
936 0 : sev_color( accdb_busy_pct ), accdb_busy_pct );
937 :
938 0 : ulong const cap = sizeof(accdb_acquired_samples)/sizeof(accdb_acquired_samples[0]);
939 0 : ulong n = fd_ulong_min( accdb_samples_idx, cap );
940 0 : if( !n ) n = 1UL;
941 :
942 0 : ulong sum_acq = 0UL, sum_wr = 0UL, sum_miss = 0UL, sum_evict = 0UL, sum_wait = 0UL;
943 0 : ulong sum_brd = 0UL, sum_bwr = 0UL, sum_bcp = 0UL, sum_bpe = 0UL;
944 0 : ulong sum_pre = 0UL;
945 0 : for( ulong i=0UL; i<n; i++ ) {
946 0 : sum_acq += accdb_acquired_samples[ i ];
947 0 : sum_wr += accdb_writable_samples[ i ];
948 0 : sum_miss += accdb_missed_samples [ i ];
949 0 : sum_evict += accdb_evicted_samples [ i ];
950 0 : sum_wait += accdb_waited_samples [ i ];
951 0 : sum_brd += accdb_bytes_rd_samples[ i ];
952 0 : sum_bwr += accdb_bytes_wr_samples[ i ];
953 0 : sum_bcp += accdb_bytes_cp_samples[ i ];
954 0 : sum_bpe += accdb_bytes_pe_samples[ i ];
955 0 : sum_pre += accdb_preevicted_samples[ i ];
956 0 : }
957 :
958 0 : double acquired = (double)sum_acq/window_seconds( n );
959 0 : double writable = (double)sum_wr/window_seconds( n );
960 0 : double missed = (double)sum_miss/window_seconds( n );
961 0 : double evicted = (double)sum_evict/window_seconds( n );
962 0 : double waited = (double)sum_wait/window_seconds( n );
963 0 : double bytes_rd = (double)sum_brd/window_seconds( n );
964 0 : double bytes_wr = (double)sum_bwr/window_seconds( n );
965 0 : double bytes_cp = (double)sum_bcp/window_seconds( n );
966 0 : double bytes_pe = (double)sum_bpe/window_seconds( n );
967 0 : double preevicted = (double)sum_pre/window_seconds( n );
968 :
969 0 : double hit_pct = acquired>0.0 ? 100.0*(acquired-missed)/acquired : 0.0;
970 :
971 0 : char * read_str = fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, (long)bytes_rd );
972 0 : char * write_str = fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, (long)bytes_wr );
973 0 : char * copy_str = fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, (long)bytes_cp );
974 0 : char * preevict_str= fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, (long)bytes_pe );
975 0 : char * acq_str = COUNTF( acquired );
976 0 : char * wr_str = COUNTF( writable );
977 0 : char * miss_str = COUNTF( missed );
978 0 : char * evict_str = COUNTF( evicted );
979 0 : char * pre_str = COUNTF( preevicted );
980 0 : char * wait_str = COUNTF( waited );
981 :
982 0 : if( FD_LIKELY( !watch_full ) ) return 1;
983 :
984 0 : PRINT( ROWC
985 0 : K( "acquire" ) "%s" U( "/s" ) " " U( "(%s wr/s)" )
986 0 : K( "hit" ) "%5.1f" U( "%%" )
987 0 : K( "miss" ) "%s" U( "/s" )
988 0 : K( "evict" ) "%s" U( "/s (+%s/s)" )
989 0 : K( "wait" ) "%s" U( "/s" )
990 0 : K( "io" ) "%s" U( " rd" ) " %s" U( " wr-acq" ) " %s" U( " wr-pe" ) " %s" U( " cp" ) CLEARLN "\n",
991 0 : acq_str, wr_str, hit_pct, miss_str, evict_str, pre_str, wait_str,
992 0 : read_str, write_str, preevict_str, copy_str );
993 :
994 0 : char * evict_class_str[ 8 ];
995 0 : char * preevict_class_str[ 8 ];
996 0 : char * commit_new_class_str[ 8 ];
997 0 : char * commit_overwrite_class_str[ 8 ];
998 0 : for( ulong c=0UL; c<8UL; c++ ) {
999 0 : ulong sum_c = 0UL, sum_pc = 0UL, sum_cn = 0UL, sum_co = 0UL;
1000 0 : for( ulong i=0UL; i<n; i++ ) {
1001 0 : sum_c += accdb_evicted_class_samples [ c ][ i ];
1002 0 : sum_pc += accdb_preevicted_class_samples [ c ][ i ];
1003 0 : sum_cn += accdb_committed_new_class_samples [ c ][ i ];
1004 0 : sum_co += accdb_committed_overwrite_class_samples[ c ][ i ];
1005 0 : }
1006 0 : evict_class_str [ c ] = COUNTF_T( (double)sum_c/window_seconds( n ) );
1007 0 : preevict_class_str [ c ] = COUNTF_T( (double)sum_pc/window_seconds( n ) );
1008 0 : commit_new_class_str [ c ] = COUNTF_T( (double)sum_cn/window_seconds( n ) );
1009 0 : commit_overwrite_class_str[ c ] = COUNTF_T( (double)sum_co/window_seconds( n ) );
1010 0 : }
1011 :
1012 : /* Per size class grid: dim header row, then one row per family
1013 : with every cell right aligned in a fixed 19 char column. */
1014 0 : static char const * class_lbl[ 8 ] = { "128b", "512b", "2k", "8k", "32k", "128k", "1m", "10m" };
1015 :
1016 0 : PRINT( ROWC K( "class " ) );
1017 0 : for( ulong c=0UL; c<8UL; c++ ) PRINT( DIM "%21s" RESET, class_lbl[ c ] );
1018 0 : PRINT( CLEARLN "\n" );
1019 :
1020 0 : PRINT( ROWC K( "evict/s " ) );
1021 0 : for( ulong c=0UL; c<8UL; c++ ) PRINT( " %6s" DIM "+" RESET "%6s", evict_class_str[ c ], preevict_class_str[ c ] );
1022 0 : PRINT( CLEARLN "\n" );
1023 :
1024 0 : PRINT( ROWC K( "commit/s" ) );
1025 0 : for( ulong c=0UL; c<8UL; c++ ) PRINT( " %6s" DIM "=" RESET "%6s", commit_new_class_str[ c ], commit_overwrite_class_str[ c ] );
1026 0 : PRINT( CLEARLN "\n" );
1027 :
1028 0 : ulong cache_used_off = MIDX( GAUGE, ACCDB, CACHE_CLASS_USED );
1029 0 : ulong cache_max_off = MIDX( GAUGE, ACCDB, CACHE_CLASS_CAPACITY );
1030 0 : char * cache_used_str[ 8 ];
1031 0 : char * cache_max_str [ 8 ];
1032 0 : double cache_pct [ 8 ];
1033 0 : for( ulong c=0UL; c<8UL; c++ ) {
1034 0 : ulong used = t[ cache_used_off + c ];
1035 0 : ulong max = t[ cache_max_off + c ];
1036 0 : cache_used_str[ c ] = COUNT_T( used );
1037 0 : cache_max_str [ c ] = COUNT_T( max );
1038 0 : cache_pct [ c ] = max ? 100.0*(double)used/(double)max : 0.0;
1039 0 : }
1040 :
1041 0 : PRINT( ROWC K( "cache " ) );
1042 0 : for( ulong c=0UL; c<8UL; c++ ) {
1043 : /* COUNT_T strings are already 6 wide: cell = 1+5+1+1+6+1+6 = 21. */
1044 0 : PRINT( " %s%5.1f" U( "%%" ) RESET " %s" DIM "/" RESET "%s",
1045 0 : sev_color( cache_pct[ c ] ), cache_pct[ c ],
1046 0 : cache_used_str[ c ], cache_max_str[ c ] );
1047 0 : }
1048 0 : PRINT( CLEARLN "\n" );
1049 :
1050 0 : ulong cache_resv_off = MIDX( GAUGE, ACCDB, CACHE_CLASS_RESERVED );
1051 0 : ulong cache_tracked_off = MIDX( GAUGE, ACCDB, IS_CACHE_CLASS_RESERVATION_TRACKED );
1052 0 : char * cache_resv_str[ 8 ];
1053 0 : for( ulong c=0UL; c<8UL; c++ ) {
1054 0 : if( !t[ cache_tracked_off + c ] ) cache_resv_str[ c ] = " off ";
1055 0 : else cache_resv_str[ c ] = COUNT_T( t[ cache_resv_off + c ] );
1056 0 : }
1057 :
1058 0 : PRINT( ROWC K( "reserved" ) );
1059 0 : for( ulong c=0UL; c<8UL; c++ ) PRINT( " %6s", cache_resv_str[ c ] );
1060 0 : PRINT( CLEARLN "\n" );
1061 0 : return 7;
1062 0 : }
1063 :
1064 : static uint
1065 : write_wfs( config_t const * config,
1066 0 : ulong const * cur_tile ) {
1067 0 : ulong gossip_tile_idx = fd_topo_find_tile( &config->topo, "gossip", 0UL );
1068 0 : if( FD_UNLIKELY( gossip_tile_idx==ULONG_MAX ) ) return 0U;
1069 :
1070 0 : int wfs_state = (int)cur_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STATE ) ];
1071 0 : if( FD_LIKELY( wfs_state==FD_GOSSIP_WFS_STATE_DONE ) ) return 0U;
1072 :
1073 0 : char const * state_str;
1074 0 : switch( wfs_state ) {
1075 0 : case FD_GOSSIP_WFS_STATE_INIT: state_str = "loading snapshot"; break;
1076 0 : case FD_GOSSIP_WFS_STATE_WAIT: state_str = "waiting"; break;
1077 0 : case FD_GOSSIP_WFS_STATE_PUBLISH: state_str = "starting"; break;
1078 0 : default: return 0U;
1079 0 : }
1080 :
1081 0 : ulong _stake_online = cur_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_ONLINE_LAMPORTS ) ];
1082 0 : ulong _stake_total = cur_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKE_TRACKED_LAMPORTS ) ];
1083 0 : ulong peers_online = cur_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_ONLINE ) ];
1084 0 : ulong peers_total = cur_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, GOSSIP, WAIT_FOR_SUPERMAJORITY_STAKED_PEER_COUNT ) ];
1085 :
1086 0 : ulong ipecho_tile_idx = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
1087 0 : ulong shred_ver = 0UL;
1088 0 : if( FD_LIKELY( ipecho_tile_idx!=ULONG_MAX ) ) shred_ver = cur_tile[ ipecho_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, IPECHO, SHRED_VERSION ) ];
1089 :
1090 0 : double stake_pct = _stake_total>0UL ? 100.0*(double)_stake_online/(double)_stake_total : 0.0;
1091 0 : double stake_div = (_stake_total<(ulong)1e14) ? 1e9 : 1e15;
1092 0 : char const * stake_unit = (_stake_total<(ulong)1e14) ? " SOL" : "M";
1093 0 : double stake_online = (double)_stake_online / stake_div;
1094 0 : double stake_total = (double)_stake_total / stake_div;
1095 :
1096 0 : PRINT( ROWH( "○", YELLOW, "cluster boot" )
1097 0 : K( "state" ) "%s"
1098 0 : K( "stake" ) "%s " BOLD "%3.0f" RESET U( "%%" ) " " U( "(%.1f%s / %.1f%s)" )
1099 0 : K( "shred ver" ) "%lu"
1100 0 : K( "peers" ) "%lu" U( " online " ) "%lu" U( " offline" )
1101 0 : K( "bank hash" ) "%s" CLEARLN "\n",
1102 0 : state_str,
1103 0 : BAR( stake_pct, 10UL ),
1104 0 : stake_pct,
1105 0 : stake_online,
1106 0 : stake_unit,
1107 0 : stake_total,
1108 0 : stake_unit,
1109 0 : shred_ver,
1110 0 : peers_online,
1111 0 : peers_total>peers_online ? peers_total-peers_online : 0UL,
1112 0 : config->firedancer.consensus.wait_for_supermajority_with_bank_hash );
1113 0 : return 1U;
1114 0 : }
1115 :
1116 : static uint
1117 : write_gossip( config_t const * config,
1118 : ulong const * cur_tile,
1119 : ulong const * prev_tile,
1120 : ulong const * cur_link,
1121 0 : ulong const * prev_link ) {
1122 0 : ulong gossip_tile_idx = fd_topo_find_tile( &config->topo, "gossip", 0UL );
1123 0 : if( gossip_tile_idx==ULONG_MAX ) return 0U;
1124 0 : ulong const * t = &cur_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ ];
1125 0 : char * contact_info = COUNT( t[ MIDX( GAUGE, GOSSIP, CRDS_USED_CONTACT_INFO_V2 ) ] );
1126 :
1127 0 : ulong gossip_total_ticks = total_regime( &cur_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ gossip_tile_idx*FD_METRICS_TOTAL_SZ ] );
1128 0 : gossip_total_ticks = fd_ulong_max( gossip_total_ticks, 1UL );
1129 0 : double gossip_backp_pct = 100.0*(double)diff_tile_regime( config, "gossip", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)gossip_total_ticks;
1130 0 : double gossip_idle_pct = 100.0*(double)diff_tile_regime( config, "gossip", prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)gossip_total_ticks;
1131 0 : double gossip_busy_pct = 100.0 - gossip_backp_pct - gossip_idle_pct;
1132 :
1133 0 : PRINT( ROWH( "●", BLUE, "gossip " )
1134 0 : K( "rx" ) "%s"
1135 0 : K( "tx" ) "%s"
1136 0 : K( "crds" ) "%s"
1137 0 : K( "peers" ) "%s ",
1138 0 : DIFF_LINK_BYTES( "net_gossvf", COUNTER, LINK, FRAG_CONSUMED_BYTES ),
1139 0 : DIFF_LINK_BYTES( "gossip_net", COUNTER, LINK, FRAG_CONSUMED_BYTES ),
1140 0 : COUNT( total_crds( t ) ),
1141 0 : contact_info );
1142 0 : if( FD_UNLIKELY( gossip_saturated ) ) PRINT( GREEN "✓" RESET DIM " saturated" RESET );
1143 0 : else PRINT( "%s " DIM "%3.0f%%" RESET, BAR( gossip_conv_pct, 8UL ), gossip_conv_pct );
1144 0 : PRINT( K( "busy" ) "%s%3.0f" U( "%%" ) RESET
1145 0 : K( "backp" ) "%s%3.0f" U( "%%" ) RESET CLEARLN "\n",
1146 0 : sev_color( gossip_busy_pct ), gossip_busy_pct,
1147 0 : sev_color( gossip_backp_pct ), gossip_backp_pct );
1148 0 : return 1U;
1149 0 : }
1150 :
1151 : static uint
1152 : write_repair( config_t const * config,
1153 : ulong const * cur_tile,
1154 : ulong const * cur_link,
1155 0 : ulong const * prev_link ) {
1156 0 : ulong repair_tile_idx = fd_topo_find_tile( &config->topo, "repair", 0UL );
1157 0 : char const * repair_label = "repair ";
1158 0 : if( repair_tile_idx==ULONG_MAX ) return 0U;
1159 0 : ulong highest_off = MIDX( GAUGE, REPAIR, HIGHEST_DELIVERED_SLOT );
1160 0 : ulong current_off = MIDX( GAUGE, REPAIR, HIGHEST_RECEIVED_SLOT );
1161 0 : ulong repair_slot = cur_tile[ repair_tile_idx*FD_METRICS_TOTAL_SZ+highest_off ];
1162 0 : ulong turbine_slot = cur_tile[ repair_tile_idx*FD_METRICS_TOTAL_SZ+current_off ];
1163 0 : turbine_slot = fd_ulong_max( turbine_slot, cur_tile[ repair_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPAIR, CATCHUP_SLOT ) ] );
1164 0 : long repair_lag = (long)repair_slot-(long)turbine_slot;
1165 0 : PRINT( ROWH( "▲", RED, "%s" )
1166 0 : K( "rx" ) "%s"
1167 0 : K( "tx" ) "%s"
1168 0 : K( "repair slot" ) "%lu %s%+03ld" RESET
1169 0 : K( "turbine slot" ) "%lu" CLEARLN "\n",
1170 0 : repair_label,
1171 0 : DIFF_LINK_BYTES( "shred_repair", COUNTER, LINK, FRAG_CONSUMED_BYTES ),
1172 0 : DIFF_LINK_BYTES( "repair_net", COUNTER, LINK, FRAG_CONSUMED_BYTES ),
1173 0 : repair_slot,
1174 0 : repair_lag<-4L ? RED : DIM,
1175 0 : repair_lag,
1176 0 : turbine_slot );
1177 0 : return 1U;
1178 0 : }
1179 :
1180 : static uint
1181 : write_rserve( config_t const * config,
1182 : ulong const * cur_tile,
1183 : ulong const * cur_link,
1184 0 : ulong const * prev_link ) {
1185 0 : ulong rserve_tile_idx = fd_topo_find_tile( &config->topo, "rserve", 0UL );
1186 0 : if( rserve_tile_idx==ULONG_MAX ) return 0UL;
1187 :
1188 0 : ulong const * t = cur_tile + rserve_tile_idx*FD_METRICS_TOTAL_SZ;
1189 :
1190 0 : ulong shreds_stored_sum = 0UL;
1191 0 : ulong num_stored_shreds = fd_ulong_min( shreds_stored_samples_idx, sizeof(shreds_stored_sample)/sizeof(shreds_stored_sample[0]));
1192 0 : for( ulong i=0UL; i<num_stored_shreds; i++ ) shreds_stored_sum += shreds_stored_sample[ i ];
1193 0 : char * shreds_stored = COUNTF( (double)shreds_stored_sum/window_seconds( num_stored_shreds ) );
1194 :
1195 0 : ulong shreds_cur = t[ MIDX( GAUGE, RSERVE, SHRED_USED ) ];
1196 0 : ulong shreds_max = t[ MIDX( GAUGE, RSERVE, SHRED_CAPACITY ) ];
1197 :
1198 0 : ulong valid_sum = 0UL;
1199 0 : ulong num_valid_samples = fd_ulong_min( rserve_rps_valid_samples_idx, sizeof(rserve_rps_valid_samples)/sizeof(rserve_rps_valid_samples[0]) );
1200 0 : for( ulong i=0UL; i<num_valid_samples; i++ ) valid_sum += rserve_rps_valid_samples[ i ];
1201 0 : char * valid_str = COUNTF( (double)valid_sum/window_seconds( num_valid_samples ) );
1202 :
1203 0 : ulong invalid_sum = 0UL;
1204 0 : ulong num_invalid_samples = fd_ulong_min( rserve_rps_invalid_samples_idx, sizeof(rserve_rps_invalid_samples)/sizeof(rserve_rps_invalid_samples[0]) );
1205 0 : for( ulong i=0UL; i<num_invalid_samples; i++ ) invalid_sum += rserve_rps_invalid_samples[ i ];
1206 0 : char * invalid_str = COUNTF( (double)invalid_sum/window_seconds( num_invalid_samples ) );
1207 :
1208 0 : ulong num_total_samples = fd_ulong_max( num_valid_samples, 1UL );
1209 0 : char * total_str = COUNTF( (double)(valid_sum+invalid_sum)/window_seconds( num_total_samples ) );
1210 :
1211 0 : ulong n_inv = fd_ulong_max( num_invalid_samples, 1UL );
1212 :
1213 0 : ulong miss_sum = 0UL;
1214 0 : for( ulong i=0UL; i<num_invalid_samples; i++ ) miss_sum += rserve_rps_miss_samples[ i ];
1215 0 : char * miss_str = COUNTF( (double)miss_sum/window_seconds( n_inv ) );
1216 :
1217 0 : ulong sigvfy_sum = 0UL;
1218 0 : for( ulong i=0UL; i<num_invalid_samples; i++ ) sigvfy_sum += rserve_rps_sigvfy_samples[ i ];
1219 0 : char * sigvfy_str = COUNTF( (double)sigvfy_sum/window_seconds( n_inv ) );
1220 :
1221 0 : ulong stale_sum = 0UL;
1222 0 : for( ulong i=0UL; i<num_invalid_samples; i++ ) stale_sum += rserve_rps_stale_samples[ i ];
1223 0 : char * stale_str = COUNTF( (double)stale_sum/window_seconds( n_inv ) );
1224 :
1225 0 : ulong other_sum = 0UL;
1226 0 : for( ulong i=0UL; i<num_invalid_samples; i++ ) other_sum += rserve_rps_other_rej_samples[ i ];
1227 0 : char * other_str = COUNTF( (double)other_sum/window_seconds( n_inv ) );
1228 :
1229 0 : ulong disk_used = t[ MIDX( GAUGE, RSERVE, DISK_USED_BYTES ) ];
1230 0 : ulong disk_alloc = t[ MIDX( GAUGE, RSERVE, DISK_PEAK_BYTES ) ];
1231 0 : double disk_gb = (double)disk_alloc/1e9;
1232 0 : double disk_pct = disk_alloc ? 100.0*(double)disk_used/(double)disk_alloc : 0.0;
1233 :
1234 0 : char * shreds_cur_str = COUNT( shreds_cur );
1235 0 : char * shreds_max_str = COUNT( shreds_max );
1236 :
1237 0 : PRINT( ROWH( "□", GREEN, "rserve " )
1238 0 : K( "rx" ) "%s"
1239 0 : K( "tx" ) "%s"
1240 0 : K( "shreds" ) "%s" U( "/s" ) " " U( "(%s / %s)" )
1241 0 : K( "disk" ) "%.1f" U( " GB" ) " %s%4.1f" U( "%%" ) RESET,
1242 0 : DIFF_LINK_BYTES( "net_rserve", COUNTER, LINK, FRAG_CONSUMED_BYTES ),
1243 0 : DIFF_LINK_BYTES( "rserve_net", COUNTER, LINK, FRAG_CONSUMED_BYTES ),
1244 0 : shreds_stored, shreds_cur_str, shreds_max_str,
1245 0 : disk_gb, sev_color( disk_pct ), disk_pct );
1246 0 : PRINT( K( "rps" ) "%s" U( "/s" ) " " U( "(%s valid, %s invalid)" ) CLEARLN "\n",
1247 0 : total_str, valid_str, invalid_str );
1248 :
1249 0 : if( FD_LIKELY( !watch_full ) ) return 1U;
1250 :
1251 0 : PRINT( ROWC
1252 0 : K( "miss" ) "%s" U( "/s" )
1253 0 : K( "sigvfy" ) "%s" U( "/s" )
1254 0 : K( "stale" ) "%s" U( "/s" )
1255 0 : K( "other" ) "%s" U( "/s" ) CLEARLN "\n",
1256 0 : miss_str, sigvfy_str, stale_str, other_str );
1257 0 : return 2U;
1258 0 : }
1259 :
1260 : static uint
1261 : write_replay( config_t const * config,
1262 0 : ulong const * cur_tile ) {
1263 0 : ulong repair_tile_idx = fd_topo_find_tile( &config->topo, "repair", 0UL );
1264 0 : ulong replay_tile_idx = fd_topo_find_tile( &config->topo, "replay", 0UL );
1265 0 : if( replay_tile_idx==ULONG_MAX ) return 0U;
1266 :
1267 0 : ulong reset_slot = cur_tile[ replay_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPLAY, RESET_SLOT ) ];
1268 0 : ulong next_leader_slot = cur_tile[ replay_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPLAY, NEXT_LEADER_SLOT ) ];
1269 0 : ulong leader_slot = cur_tile[ replay_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPLAY, LEADER_SLOT ) ];
1270 0 : char * next_leader_slot_str = fd_alloca_check( 1UL, 64UL );
1271 :
1272 0 : ulong turbine_slot;
1273 0 : if( repair_tile_idx!=ULONG_MAX ) {
1274 0 : turbine_slot = cur_tile[ repair_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPAIR, HIGHEST_RECEIVED_SLOT ) ];
1275 0 : turbine_slot = fd_ulong_max( turbine_slot, cur_tile[ repair_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPAIR, CATCHUP_SLOT ) ] );
1276 0 : } else {
1277 0 : turbine_slot = reset_slot;
1278 0 : }
1279 :
1280 0 : ulong slot_in_seconds = (ulong)((double)(next_leader_slot-reset_slot)*0.4);
1281 0 : if( FD_UNLIKELY( leader_slot ) ) FD_TEST( fd_cstr_printf_check( next_leader_slot_str, 64UL, NULL, "now" ) );
1282 0 : else if( FD_LIKELY( next_leader_slot>0UL ) ) FD_TEST( fd_cstr_printf_check( next_leader_slot_str, 64UL, NULL, "%lum %lus", slot_in_seconds/60UL, slot_in_seconds%60UL ) );
1283 0 : else FD_TEST( fd_cstr_printf_check( next_leader_slot_str, 64UL, NULL, "never" ) );
1284 :
1285 0 : ulong root_distance = cur_tile[ replay_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPLAY, ROOT_SLOT_DISTANCE ) ];
1286 0 : ulong live_banks = cur_tile[ replay_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPLAY, BANK_USED ) ];
1287 :
1288 0 : ulong sps_sum = 0UL;
1289 0 : ulong num_sps_samples = fd_ulong_min( sps_samples_idx, sizeof(sps_samples)/sizeof(sps_samples[0]));
1290 0 : for( ulong i=0UL; i<num_sps_samples; i++ ) sps_sum += sps_samples[ i ];
1291 0 : char * sps_str = COUNTF( (double)sps_sum/window_seconds( num_sps_samples ) );
1292 :
1293 0 : ulong tps_sum = 0UL;
1294 0 : ulong num_tps_samples = fd_ulong_min( tps_samples_idx, sizeof(tps_samples)/sizeof(tps_samples[0]));
1295 0 : for( ulong i=0UL; i<num_tps_samples; i++ ) tps_sum += tps_samples[ i ];
1296 0 : char * tps_str = COUNTF( (double)tps_sum/window_seconds( num_tps_samples ) );
1297 :
1298 0 : ulong cups_sum = 0UL;
1299 0 : ulong num_cups_samples = fd_ulong_min( cups_samples_idx, sizeof(cups_samples)/sizeof(cups_samples[0]));
1300 0 : for( ulong i=0UL; i<num_cups_samples; i++ ) cups_sum += cups_samples[ i ];
1301 0 : char * mcups_str = COUNTF( (double)cups_sum/window_seconds( num_cups_samples ) );
1302 :
1303 0 : long replay_lag = (long)reset_slot-(long)turbine_slot;
1304 0 : PRINT( ROWH( "▶", MAGENTA, "replay " )
1305 0 : K( "slot" ) BOLD "%lu" RESET " %s%+03ld" RESET
1306 0 : K( "cu/s" ) "%s"
1307 0 : K( "tps" ) "%s"
1308 0 : K( "sps" ) "%s"
1309 0 : K( "leader in" ) "%s"
1310 0 : K( "root dist" ) "%lu"
1311 0 : K( "banks" ) "%2lu" CLEARLN "\n",
1312 0 : reset_slot,
1313 0 : replay_lag<-4L ? RED : DIM,
1314 0 : replay_lag,
1315 0 : mcups_str,
1316 0 : tps_str,
1317 0 : sps_str,
1318 0 : next_leader_slot_str,
1319 0 : root_distance,
1320 0 : live_banks );
1321 0 : return 1U;
1322 0 : }
1323 :
1324 : #define VOTOR_RATE( metric ) (__extension__({ \
1325 : ulong cnt = diff_tile( config, "votor", prev_tile, cur_tile, MIDX( COUNTER, VOTOR, metric ) ); \
1326 : COUNTF( (double)cnt*1e9/(double)SNAP_DT_NS() ); \
1327 : }))
1328 :
1329 : static uint
1330 : write_votor( config_t const * config,
1331 : ulong const * cur_tile,
1332 0 : ulong const * prev_tile ) {
1333 0 : ulong votor_tile_idx = fd_topo_find_tile( &config->topo, "votor", 0UL );
1334 0 : if( votor_tile_idx==ULONG_MAX ) return 0U;
1335 0 : ulong const * t = &cur_tile[ votor_tile_idx*FD_METRICS_TOTAL_SZ ];
1336 :
1337 0 : ulong replay_tile_idx = fd_topo_find_tile( &config->topo, "replay", 0UL );
1338 0 : ulong reset_slot = replay_tile_idx!=ULONG_MAX ? cur_tile[ replay_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, REPLAY, RESET_SLOT ) ] : 0UL;
1339 :
1340 0 : ulong finalized_slot = t[ MIDX( GAUGE, VOTOR, HIGHEST_FINAL_CERT_SLOT ) ];
1341 0 : ulong slots_used = t[ MIDX( GAUGE, VOTOR, VOTING_SLOT_USED ) ];
1342 0 : ulong slots_max = slots_used+t[ MIDX( GAUGE, VOTOR, VOTING_SLOT_FREE ) ];
1343 0 : ulong peers_out = t[ MIDX( GAUGE, VOTOR, CLIENT_CONN_USED )+FD_METRICS_ENUM_QUIC_CONN_STATE_V_ACTIVE_IDX ];
1344 0 : ulong peers_in = t[ MIDX( GAUGE, VOTOR, SERVER_CONN_USED )+FD_METRICS_ENUM_QUIC_CONN_STATE_V_ACTIVE_IDX ];
1345 0 : long rank = (long)t[ MIDX( GAUGE, VOTOR, RANK ) ];
1346 0 : double slots_pct = slots_max ? 100.0*(double)slots_used/(double)slots_max : 0.0;
1347 0 : long final_lag = (long)finalized_slot-(long)reset_slot;
1348 :
1349 0 : PRINT( ROWH( "◇", CYAN, "votor " )
1350 0 : K( "final" ) BOLD "%lu" RESET " %s%+03ld" RESET
1351 0 : K( "slots" ) "%s%lu" RESET U( "/%lu" ),
1352 0 : finalized_slot,
1353 0 : final_lag<-32L ? RED : DIM,
1354 0 : final_lag,
1355 0 : sev_color( slots_pct ), slots_used, slots_max );
1356 0 : if( FD_UNLIKELY( rank<0L ) ) {
1357 0 : PRINT( " " YELLOW "unstaked" RESET );
1358 0 : } else {
1359 0 : PRINT( K( "votes" ) "%s" U( "/s" )
1360 0 : K( "certs" ) "%s" U( "/s" )
1361 0 : K( "peers" ) "%lu" U( "out" ) " %lu" U( "in" )
1362 0 : K( "rank" ) "%ld",
1363 0 : VOTOR_RATE( VOTE_RX_SUCCESS ),
1364 0 : VOTOR_RATE( CERT_RX_SUCCESS ),
1365 0 : peers_out, peers_in,
1366 0 : rank );
1367 0 : }
1368 0 : PRINT( CLEARLN "\n" );
1369 0 : return 1U;
1370 0 : }
1371 :
1372 : #undef VOTOR_RATE
1373 :
1374 : static uint
1375 : write_gui( config_t const * config,
1376 : ulong const * cur_tile,
1377 0 : ulong const * prev_tile ) {
1378 0 : char const * gui_name = "gui";
1379 0 : ulong gui_tile_idx = fd_topo_find_tile( &config->topo, gui_name, 0UL );
1380 0 : if( FD_UNLIKELY( gui_tile_idx==ULONG_MAX ) ) return 0U;
1381 :
1382 0 : ulong off_conn_active, off_websocket_conn_active, off_websocket_frame_tx, off_websocket_frame_rx;
1383 0 : char * bytes_read_s;
1384 0 : char * bytes_written_s;
1385 0 : off_conn_active = MIDX( GAUGE, GUI, CONN_OPEN );
1386 0 : off_websocket_conn_active = MIDX( GAUGE, GUI, WEBSOCKET_CONN_OPEN );
1387 0 : off_websocket_frame_tx = MIDX( COUNTER, GUI, WEBSOCKET_FRAME_TX );
1388 0 : off_websocket_frame_rx = MIDX( COUNTER, GUI, WEBSOCKET_FRAME_RX );
1389 :
1390 0 : bytes_read_s = DIFF_BYTES( gui_name, COUNTER, GUI, CONN_RX_BYTES );
1391 0 : bytes_written_s = DIFF_BYTES( gui_name, COUNTER, GUI, CONN_TX_BYTES );
1392 :
1393 0 : ulong connection_count = cur_tile[ gui_tile_idx*FD_METRICS_TOTAL_SZ+off_conn_active ]+cur_tile[ gui_tile_idx*FD_METRICS_TOTAL_SZ+off_websocket_conn_active ];
1394 0 : ulong gui_total_ticks = total_regime( &cur_tile[ gui_tile_idx*FD_METRICS_TOTAL_SZ ] )-total_regime( &prev_tile[ gui_tile_idx*FD_METRICS_TOTAL_SZ ] );
1395 0 : gui_total_ticks = fd_ulong_max( gui_total_ticks, 1UL );
1396 0 : double gui_backp_pct = 100.0*(double)diff_tile_regime( config, gui_name, prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_BACKPRESSURE_MASK )/(double)gui_total_ticks;
1397 0 : double gui_idle_pct = 100.0*(double)diff_tile_regime( config, gui_name, prev_tile, cur_tile, FD_METRICS_ENUM_TILE_REGIME_G_IDLE_MASK )/(double)gui_total_ticks;
1398 0 : double gui_busy_pct = 100.0 - gui_backp_pct - gui_idle_pct;
1399 :
1400 0 : ulong sent_frame_count = diff_tile( config, gui_name, prev_tile, cur_tile, off_websocket_frame_tx );
1401 0 : char * sent_frame_count_s = COUNT( sent_frame_count );
1402 0 : ulong received_frame_count = diff_tile( config, gui_name, prev_tile, cur_tile, off_websocket_frame_rx );
1403 :
1404 0 : PRINT( ROWH( "◉", CYAN, "gui " )
1405 0 : K( "conns" ) "%lu"
1406 0 : K( "frames" ) "%s" U( " in" ) " %s" U( " out" )
1407 0 : K( "bw" ) "%s" U( " in" ) " %s" U( " out" )
1408 0 : K( "busy" ) "%s%3.0f" U( "%%" ) RESET CLEARLN "\n",
1409 0 : connection_count,
1410 0 : COUNT( received_frame_count ),
1411 0 : sent_frame_count_s,
1412 0 : bytes_read_s,
1413 0 : bytes_written_s,
1414 0 : sev_color( gui_busy_pct ), gui_busy_pct );
1415 0 : return 1U;
1416 0 : }
1417 :
1418 : static uint
1419 : write_event( config_t const * config,
1420 0 : ulong const * cur_tile ) {
1421 0 : ulong event_tile_idx = fd_topo_find_tile( &config->topo, "event", 0UL );
1422 0 : if( event_tile_idx==ULONG_MAX ) return 0U;
1423 :
1424 0 : ulong connection_state = cur_tile[ event_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, EVENT, CONN_STATE ) ];
1425 0 : char const * connection_state_str;
1426 0 : switch( connection_state ) {
1427 0 : case FD_EVENT_CLIENT_STATE_DISCONNECTED: connection_state_str = RED "disconnected" RESET; break;
1428 0 : case FD_EVENT_CLIENT_STATE_CONNECTING: connection_state_str = YELLOW "connecting" RESET; break;
1429 0 : case FD_EVENT_CLIENT_STATE_AUTHENTICATING: connection_state_str = YELLOW "authenticating" RESET; break;
1430 0 : case FD_EVENT_CLIENT_STATE_CONNECTED: connection_state_str = GREEN "connected" RESET; break;
1431 0 : default: connection_state_str = RED "unknown" RESET; break;
1432 0 : }
1433 :
1434 0 : ulong event_queue_count = cur_tile[ event_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, EVENT, QUEUE_USED ) ];
1435 0 : ulong event_queue_unsent = cur_tile[ event_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, EVENT, QUEUE_UNSENT_COUNT ) ];
1436 0 : ulong event_queue_unacked = event_queue_count>event_queue_unsent ? event_queue_count-event_queue_unsent : 0UL;
1437 0 : ulong event_last_acked_id = cur_tile[ event_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, EVENT, LAST_ACKED_NONCE ) ];
1438 0 : ulong event_queue_drops = cur_tile[ event_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( COUNTER, EVENT, QUEUE_EVICTED ) ];
1439 0 : ulong event_queue_bytes_used = cur_tile[ event_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, EVENT, QUEUE_USED_BYTES ) ];
1440 0 : ulong event_queue_bytes_capacity = cur_tile[ event_tile_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, EVENT, QUEUE_CAPACITY_BYTES ) ];
1441 :
1442 0 : double event_queue_pct_full = event_queue_bytes_capacity>0UL ? 100.0*(double)event_queue_bytes_used/(double)event_queue_bytes_capacity : 0.0;
1443 :
1444 0 : ulong events_sent_sum = 0UL;
1445 0 : ulong num_events_sent_samples = fd_ulong_min( events_sent_samples_idx, sizeof(events_sent_samples)/sizeof(events_sent_samples[0]));
1446 0 : for( ulong i=0UL; i<num_events_sent_samples; i++ ) events_sent_sum += events_sent_samples[ i ];
1447 0 : char * events_sent_str = COUNTF( (double)events_sent_sum/window_seconds( num_events_sent_samples ) );
1448 :
1449 0 : ulong events_acked_sum = 0UL;
1450 0 : ulong num_events_acked_samples = fd_ulong_min( events_acked_samples_idx, sizeof(events_acked_samples)/sizeof(events_acked_samples[0]));
1451 0 : for( ulong i=0UL; i<num_events_acked_samples; i++ ) events_acked_sum += events_acked_samples[ i ];
1452 0 : char * events_acked_str = COUNTF( (double)events_acked_sum/window_seconds( num_events_acked_samples ) );
1453 :
1454 0 : ulong bytes_written_sum = 0UL;
1455 0 : ulong num_bytes_written_samples = fd_ulong_min( event_bytes_written_samples_idx, sizeof(event_bytes_written_samples)/sizeof(event_bytes_written_samples[0]));
1456 0 : for( ulong i=0UL; i<num_bytes_written_samples; i++ ) bytes_written_sum += event_bytes_written_samples[ i ];
1457 0 : long bytes_written_per_sec = (long)((double)bytes_written_sum/window_seconds( num_bytes_written_samples ));
1458 0 : char * bytes_written_str = fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, bytes_written_per_sec );
1459 :
1460 0 : ulong bytes_read_sum = 0UL;
1461 0 : ulong num_bytes_read_samples = fd_ulong_min( event_bytes_read_samples_idx, sizeof(event_bytes_read_samples)/sizeof(event_bytes_read_samples[0]));
1462 0 : for( ulong i=0UL; i<num_bytes_read_samples; i++ ) bytes_read_sum += event_bytes_read_samples[ i ];
1463 0 : long bytes_read_per_sec = (long)((double)bytes_read_sum/window_seconds( num_bytes_read_samples ));
1464 0 : char * bytes_read_str = fmt_bytes( fd_alloca_check( 1UL, 64UL ), 64UL, bytes_read_per_sec );
1465 :
1466 0 : char * event_queue_unacked_s = COUNT( event_queue_unacked );
1467 0 : char * event_queue_unsent_s = COUNT( event_queue_unsent );
1468 0 : char * event_last_acked_id_s = COUNT( event_last_acked_id );
1469 :
1470 0 : PRINT( ROWH( "◆", YELLOW, "event " )
1471 0 : K( "state" ) "%s"
1472 0 : K( "unacked" ) "%s"
1473 0 : K( "queue" ) "%s"
1474 0 : K( "sent" ) "%s" U( "/s" )
1475 0 : K( "acked" ) "%s" U( "/s" )
1476 0 : K( "last ack" ) "%s"
1477 0 : K( "bw" ) "%s" U( " in" ) " %s" U( " out" )
1478 0 : K( "drops" ) "%s"
1479 0 : K( "full" ) "%s%3.0f" U( "%%" ) RESET CLEARLN "\n",
1480 0 : connection_state_str,
1481 0 : event_queue_unacked_s,
1482 0 : event_queue_unsent_s,
1483 0 : events_sent_str,
1484 0 : events_acked_str,
1485 0 : event_last_acked_id_s,
1486 0 : bytes_read_str,
1487 0 : bytes_written_str,
1488 0 : COUNT( event_queue_drops ),
1489 0 : sev_color( event_queue_pct_full ), event_queue_pct_full );
1490 0 : return 1U;
1491 0 : }
1492 :
1493 : /* Pad a value to a fixed display width so fields that fill in after
1494 : boot (identity, vote, shred version, ...) never shift the columns
1495 : to their right on redraw. Unknown values render as a dim "-". */
1496 : static char *
1497 : fmt_field( char * buf,
1498 : ulong buf_sz,
1499 : char const * val,
1500 : int known,
1501 0 : int width ) {
1502 0 : if( FD_LIKELY( known ) ) FD_TEST( fd_cstr_printf_check( buf, buf_sz, NULL, "%-*s", width, val ) );
1503 0 : else FD_TEST( fd_cstr_printf_check( buf, buf_sz, NULL, DIM "%-*s" RESET, width, "-" ) );
1504 0 : return buf;
1505 0 : }
1506 :
1507 : static char *
1508 : base58_short( char out[ static 16 ],
1509 0 : uchar const key[ static 32 ] ) {
1510 0 : char enc[ FD_BASE58_ENCODED_32_SZ ];
1511 0 : ulong len;
1512 0 : fd_base58_encode_32( key, &len, enc );
1513 0 : char * p = fd_cstr_init( out );
1514 0 : p = fd_cstr_append_text( p, enc, 6 ),
1515 0 : p = fd_cstr_append_text( p, "…", sizeof("…")-1 ),
1516 0 : p = fd_cstr_append_text( p, enc+len-6, 6 );
1517 0 : fd_cstr_fini( p );
1518 0 : return out;
1519 0 : }
1520 :
1521 : static void
1522 : fmt_balance( char out[ static 64 ],
1523 0 : ulong lamports ) {
1524 0 : ulong maj = lamports / 1000000000UL;
1525 0 : ulong min = lamports % 1000000000UL;
1526 0 : fd_cstr_printf_check( out, 64UL, NULL, "%lu.%09lu", maj, min );
1527 0 : }
1528 :
1529 : static uint
1530 : write_node_info( config_t const * config,
1531 : ulong const * cur_tile,
1532 0 : fd_node_info_t const * node_info ) {
1533 :
1534 0 : char identity_b58[ FD_BASE58_ENCODED_32_SZ ];
1535 0 : int has_identity = node_info && !fd_pubkey_check_zero( &node_info->identity );
1536 0 : if( FD_LIKELY( has_identity ) ) fd_base58_encode_32( node_info->identity.key, NULL, identity_b58 );
1537 :
1538 0 : char vote_acc_b58[ FD_BASE58_ENCODED_32_SZ ];
1539 0 : int has_vote_acc = node_info && !fd_pubkey_check_zero( &node_info->vote_account );
1540 0 : if( FD_LIKELY( has_vote_acc ) ) fd_base58_encode_32( node_info->vote_account.key, NULL, vote_acc_b58 );
1541 :
1542 0 : char shred_ver[ 16 ];
1543 0 : int has_shred_ver = 1;
1544 0 : ulong ipecho_idx = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
1545 0 : ushort shred_version = 0;
1546 0 : if( FD_LIKELY( ipecho_idx!=ULONG_MAX ) ) shred_version = (ushort)cur_tile[ ipecho_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, IPECHO, SHRED_VERSION ) ];
1547 0 : if( shred_version ) {
1548 0 : fd_cstr_printf_check( shred_ver, sizeof(shred_ver), NULL, "%hu", shred_version );
1549 0 : } else if( config->consensus.expected_shred_version ) {
1550 0 : fd_cstr_printf_check( shred_ver, sizeof(shred_ver), NULL, "(%hu)", config->consensus.expected_shred_version );
1551 0 : } else {
1552 0 : has_shred_ver = 0;
1553 0 : }
1554 :
1555 0 : char genesis_hash_b58[ FD_BASE58_ENCODED_32_SZ ] = {0};
1556 0 : char genesis_short[ 16 ] = {0};
1557 0 : int has_genesis_b58 = 0;
1558 0 : if( FD_LIKELY( node_info && !fd_pubkey_check_zero( &node_info->genesis_hash ) ) ) {
1559 0 : fd_base58_encode_32( node_info->genesis_hash.key, NULL, genesis_hash_b58 );
1560 0 : base58_short( genesis_short, node_info->genesis_hash.key );
1561 0 : has_genesis_b58 = 1;
1562 0 : }
1563 :
1564 0 : char const * cluster_str = "";
1565 0 : char const * cluster_color = "";
1566 0 : if( has_genesis_b58 ) {
1567 0 : ulong cluster_id = fd_genesis_cluster_identify( genesis_hash_b58 );
1568 0 : cluster_str = cluster_id==FD_CLUSTER_MAINNET_BETA ? "mainnet" : fd_genesis_cluster_name( cluster_id );
1569 0 : switch( cluster_id ) {
1570 0 : case FD_CLUSTER_MAINNET_BETA: cluster_color = CLUS_MAINNET; break;
1571 0 : case FD_CLUSTER_TESTNET: cluster_color = CLUS_TESTNET; break;
1572 0 : case FD_CLUSTER_DEVNET: cluster_color = CLUS_DEVNET; break;
1573 0 : case FD_CLUSTER_PYTHNET: cluster_color = CLUS_PYTHNET; break;
1574 0 : case FD_CLUSTER_PYTHTEST: cluster_color = CLUS_PYTHTEST; break;
1575 0 : default: cluster_color = CLUS_UNKNOWN; break;
1576 0 : }
1577 0 : }
1578 :
1579 0 : char uptime_str[ 32UL ];
1580 0 : int has_uptime = 1;
1581 0 : long now = fd_log_wallclock();
1582 0 : if( FD_LIKELY( config->boot_timestamp_nanos>0L && now>config->boot_timestamp_nanos ) ) {
1583 0 : ulong elapsed_s = (ulong)( (now - config->boot_timestamp_nanos) / (long)1e9 );
1584 0 : ulong days = elapsed_s / 86400UL;
1585 0 : ulong hours = (elapsed_s % 86400UL) / 3600UL;
1586 0 : ulong mins = (elapsed_s % 3600UL) / 60UL;
1587 0 : ulong secs = elapsed_s % 60UL;
1588 0 : if( days ) fd_cstr_printf_check( uptime_str, sizeof(uptime_str), NULL, "%lud %luh %lum", days, hours, mins );
1589 0 : else if( hours ) fd_cstr_printf_check( uptime_str, sizeof(uptime_str), NULL, "%luh %lum %lus", hours, mins, secs );
1590 0 : else fd_cstr_printf_check( uptime_str, sizeof(uptime_str), NULL, "%lum %lus", mins, secs );
1591 0 : } else {
1592 0 : has_uptime = 0;
1593 0 : }
1594 :
1595 0 : ulong replay_idx = fd_topo_find_tile( &config->topo, "replay", 0UL );
1596 0 : if( FD_UNLIKELY( replay_idx==ULONG_MAX ) ) return 0U;
1597 0 : ulong const * replay_metrics = &cur_tile[ replay_idx*FD_METRICS_TOTAL_SZ ];
1598 0 : ulong identity_balance = replay_metrics[ MIDX( GAUGE, REPLAY, IDENTITY_BALANCE_LAMPORTS ) ];
1599 0 : ulong stake_amount = replay_metrics[ MIDX( GAUGE, REPLAY, ACTIVE_STAKE_LAMPORTS ) ];
1600 0 : ulong epoch_credits = replay_metrics[ MIDX( GAUGE, REPLAY, EPOCH_CREDITS ) ];
1601 0 : ulong tot_stake = replay_metrics[ MIDX( GAUGE, REPLAY, CLUSTER_ACTIVE_STAKE_LAMPORTS ) ];
1602 0 : char identity_balance_str[ 64 ]; fmt_balance( identity_balance_str, identity_balance );
1603 0 : char stake_amount_str [ 64 ]; fmt_balance( stake_amount_str, stake_amount );
1604 0 : double stake_percent = 0.0;
1605 0 : if( tot_stake>0UL ) stake_percent = 100.0*(double)stake_amount/(double)tot_stake;
1606 :
1607 : /* Fixed width slots (base58 keys are at most 44 chars) so fields
1608 : that appear over time never shift their neighbors. */
1609 0 : char id_field [ 64 ]; fmt_field( id_field, sizeof(id_field), identity_b58, has_identity, 44 );
1610 0 : char vote_field[ 64 ]; fmt_field( vote_field, sizeof(vote_field), vote_acc_b58, has_vote_acc, 44 );
1611 0 : char clus_field[ 32 ]; fmt_field( clus_field, sizeof(clus_field), cluster_str, has_genesis_b58, 8 );
1612 0 : char up_field [ 64 ]; fmt_field( up_field, sizeof(up_field), uptime_str, has_uptime, 12 );
1613 0 : char sv_field [ 32 ]; fmt_field( sv_field, sizeof(sv_field), shred_ver, has_shred_ver, 7 );
1614 :
1615 0 : PRINT( ROWH( "◈", ORANGE, "node " )
1616 0 : K( "cluster" ) "%s" BOLD "%s" RESET
1617 0 : K( "id" ) BOLD "%s" RESET
1618 0 : K( "vote" ) "%s"
1619 0 : K( "uptime" ) "%s"
1620 0 : K( "shred" ) "%s"
1621 0 : K( "genesis" ) "%s",
1622 0 : cluster_color,
1623 0 : clus_field,
1624 0 : id_field,
1625 0 : vote_field,
1626 0 : up_field,
1627 0 : sv_field,
1628 0 : has_genesis_b58 ? genesis_short : DIM "-" RESET );
1629 0 : PRINT( CLEARLN "\n" );
1630 :
1631 0 : if( FD_LIKELY( !watch_full ) ) return 1U;
1632 :
1633 0 : PRINT( ROWC
1634 0 : K( "balance" ) "%s" U( " SOL" )
1635 0 : K( "stake" ) "%s" U( " SOL" ) " " U( "(%.2f%%)" )
1636 0 : K( "credits" ) "%lu" CLEARLN "\n",
1637 0 : identity_balance_str, stake_amount_str, stake_percent, epoch_credits );
1638 :
1639 0 : return 2U;
1640 0 : }
1641 :
1642 : static uint
1643 : write_backup( config_t const * config,
1644 0 : ulong const * cur_tile ) {
1645 0 : ulong snapmk_idx = fd_topo_find_tile( &config->topo, "snapmk", 0UL );
1646 0 : ulong snapsv_idx = fd_topo_find_tile( &config->topo, "snapsv", 0UL );
1647 0 : ulong conns = snapsv_idx==ULONG_MAX ? 0UL : cur_tile[ snapsv_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPSV, CONN_OPEN ) ];
1648 0 : ulong state = snapmk_idx==ULONG_MAX ? SNAPMK_STATE_IDLE : cur_tile[ snapmk_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPMK, JOB_STATE ) ];
1649 0 : int active = state>=SNAPMK_STATE_START && state<=SNAPMK_STATE_FAIL;
1650 0 : int server_on = conns>0UL;
1651 0 : if( FD_UNLIKELY( !active && !server_on ) ) return 0U;
1652 :
1653 0 : ulong upload_sum = 0UL;
1654 0 : ulong upload_cnt = fd_ulong_min( backup_upload_idx, sizeof(backup_upload_samples)/sizeof(backup_upload_samples[0]) );
1655 0 : for( ulong i=0UL; i<upload_cnt; i++ ) upload_sum += backup_upload_samples[ i ];
1656 0 : double upload_mbps = upload_cnt ? 8.0*(double)upload_sum/window_seconds( upload_cnt )/1e6 : 0.0;
1657 :
1658 0 : PRINT( ROWH( "□", BLUE, "backup " ) );
1659 0 : if( FD_LIKELY( server_on ) ) {
1660 0 : PRINT( K( "conns" ) "%3lu" K( "upload" ) "%4.0f" U( " Mbit/s" ), conns, upload_mbps );
1661 0 : }
1662 0 : if( FD_UNLIKELY( !active ) ) {
1663 0 : PRINT( CLEARLN "\n" );
1664 0 : return 1U;
1665 0 : }
1666 :
1667 0 : ulong snapmk_off = snapmk_idx*FD_METRICS_TOTAL_SZ;
1668 0 : ulong full_slot = cur_tile[ snapmk_off+MIDX( GAUGE, SNAPMK, LAST_STARTED_SLOT_FULL ) ];
1669 0 : ulong incr_slot = cur_tile[ snapmk_off+MIDX( GAUGE, SNAPMK, LAST_STARTED_SLOT_INCREMENTAL ) ];
1670 0 : int incremental = incr_slot>full_slot;
1671 :
1672 0 : double progress = 0.0;
1673 0 : if( FD_LIKELY( !incremental && state==SNAPMK_STATE_ACCDB_DISK ) ) {
1674 0 : ulong snaprd_idx = fd_topo_find_tile( &config->topo, "snaprd", 0UL );
1675 0 : if( FD_LIKELY( snaprd_idx!=ULONG_MAX ) ) {
1676 0 : ulong snaprd_off = snaprd_idx*FD_METRICS_TOTAL_SZ;
1677 0 : ulong done = cur_tile[ snaprd_off+MIDX( GAUGE, SNAPRD, EXPORT_PROGRESS_BYTES ) ];
1678 0 : ulong total = cur_tile[ snaprd_off+MIDX( GAUGE, SNAPRD, EXPORT_EXPECTED_BYTES ) ];
1679 0 : if( FD_LIKELY( total ) ) progress = 100.0*(double)fd_ulong_min( done, total )/(double)total;
1680 0 : }
1681 0 : } else if( FD_LIKELY( !incremental && state>SNAPMK_STATE_ACCDB_DISK && state<=SNAPMK_STATE_DONE ) ) {
1682 0 : progress = 100.0;
1683 0 : } else if( FD_UNLIKELY( incremental && state==SNAPMK_STATE_ACCDB_DELTA ) ) {
1684 0 : ulong done = cur_tile[ snapmk_off+MIDX( GAUGE, SNAPMK, INCREMENTAL_ACCOUNT_PROGRESS ) ];
1685 0 : ulong total = cur_tile[ snapmk_off+MIDX( GAUGE, SNAPMK, INCREMENTAL_ACCOUNT_EXPECTED ) ];
1686 0 : progress = total ? 100.0*(double)fd_ulong_min( done, total )/(double)total : 100.0;
1687 0 : } else if( FD_UNLIKELY( incremental && state>SNAPMK_STATE_ACCDB_DELTA && state<=SNAPMK_STATE_DONE ) ) {
1688 0 : progress = 100.0;
1689 0 : }
1690 :
1691 0 : ulong acc_sum = 0UL;
1692 0 : ulong acc_cnt = fd_ulong_min( backup_acc_idx, sizeof(backup_acc_samples)/sizeof(backup_acc_samples[0]) );
1693 0 : for( ulong i=0UL; i<acc_cnt; i++ ) acc_sum += backup_acc_samples[ i ];
1694 :
1695 0 : ulong read_sum = 0UL;
1696 0 : ulong read_cnt = fd_ulong_min( backup_read_idx, sizeof(backup_read_samples)/sizeof(backup_read_samples[0]) );
1697 0 : for( ulong i=0UL; i<read_cnt; i++ ) read_sum += backup_read_samples[ i ];
1698 :
1699 0 : ulong comp_sum = 0UL;
1700 0 : ulong comp_cnt = fd_ulong_min( backup_comp_idx, sizeof(backup_comp_samples)/sizeof(backup_comp_samples[0]) );
1701 0 : for( ulong i=0UL; i<comp_cnt; i++ ) comp_sum += backup_comp_samples[ i ];
1702 :
1703 0 : double accounts_per_second = acc_cnt ? (double)acc_sum/window_seconds( acc_cnt ) : 0.0;
1704 0 : double read_mbps = read_cnt ? (double)read_sum/window_seconds( read_cnt )/1e6 : 0.0;
1705 0 : double comp_mbps = comp_cnt ? (double)comp_sum/window_seconds( comp_cnt )/1e6 : 0.0;
1706 0 : char * accounts_rate = COUNTF_T( accounts_per_second );
1707 :
1708 0 : PRINT( " %s " BOLD "%5.1f" RESET U( "%%" )
1709 0 : K( "type" ) "%-4s"
1710 0 : K( "slot" ) "%10lu"
1711 0 : K( "acc" ) "%s" U( "/s" )
1712 0 : K( "read" ) "%4.0f" U( " MB/s" )
1713 0 : K( "comp" ) "%4.0f" U( " MB/s" ) CLEARLN "\n",
1714 0 : BAR( progress, 20UL ), progress,
1715 0 : incremental ? "incr" : "full",
1716 0 : incremental ? incr_slot : full_slot,
1717 0 : accounts_rate,
1718 0 : read_mbps,
1719 0 : comp_mbps );
1720 0 : return 1U;
1721 0 : }
1722 :
1723 : static void
1724 : write_summary( config_t const * config,
1725 : fd_node_info_box_t const * shinfo,
1726 : ulong const * cur_tile,
1727 : ulong const * prev_tile,
1728 : ulong const * cur_link,
1729 0 : ulong const * prev_link ) {
1730 0 : (void)config;
1731 0 : (void)prev_tile;
1732 0 : (void)cur_tile;
1733 :
1734 0 : if( FD_UNLIKELY( !ended_on_newline ) ) PRINT( "\n" );
1735 0 : PRINT( "\033[?7l" ); /* disable autowrap mode */
1736 0 : lines_printed = 0UL;
1737 :
1738 0 : ulong snapct_idx = fd_topo_find_tile( &config->topo, "snapct", 0UL );
1739 0 : int shutdown = 1;
1740 0 : if( FD_LIKELY( snapct_idx!=ULONG_MAX ) ) shutdown = cur_tile[ snapct_idx*FD_METRICS_TOTAL_SZ+MIDX( GAUGE, SNAPCT, LOAD_STATE ) ]==FD_SNAPCT_STATE_SHUTDOWN;
1741 :
1742 0 : static long snap_shutdown_time = 0L;
1743 0 : if( FD_UNLIKELY( !snap_shutdown_time && !shutdown ) ) snap_shutdown_time = 1L; /* Was not shutdown on boot */
1744 0 : if( FD_UNLIKELY( !snap_shutdown_time && shutdown ) ) snap_shutdown_time = 2L; /* Was shutdown on boot */
1745 0 : if( FD_UNLIKELY( snap_shutdown_time==1L && shutdown ) ) snap_shutdown_time = fd_log_wallclock();
1746 :
1747 0 : fd_node_info_t node_info[1] = {0};
1748 0 : if( FD_LIKELY( shinfo ) ) fd_node_info_read( node_info, shinfo );
1749 0 : lines_printed += write_node_info( config, cur_tile, node_info );
1750 :
1751 0 : if( FD_UNLIKELY( write_bench( config, cur_tile, prev_tile ) ) ) lines_printed++;
1752 :
1753 0 : ulong backt_idx = fd_topo_find_tile( &config->topo, "backt", 0UL );
1754 0 : if( FD_UNLIKELY( backt_idx!=ULONG_MAX ) ) {
1755 0 : lines_printed++;
1756 0 : write_backtest( config, cur_tile );
1757 0 : }
1758 :
1759 0 : long now = fd_log_wallclock();
1760 0 : if( FD_UNLIKELY( snap_shutdown_time==1L || now<snap_shutdown_time+(long)2e9 ) ) {
1761 0 : lines_printed++;
1762 0 : write_snapshots( config, cur_tile, prev_tile );
1763 0 : }
1764 :
1765 0 : lines_printed += write_accdb( config, cur_tile, prev_tile );
1766 0 : lines_printed += write_wfs( config, cur_tile );
1767 0 : lines_printed += write_gossip( config, cur_tile, prev_tile, cur_link, prev_link );
1768 0 : lines_printed += write_repair( config, cur_tile, cur_link, prev_link );
1769 0 : lines_printed += write_rserve( config, cur_tile, cur_link, prev_link );
1770 0 : lines_printed += write_replay( config, cur_tile );
1771 0 : lines_printed += write_votor( config, cur_tile, prev_tile );
1772 0 : lines_printed += write_gui( config, cur_tile, prev_tile );
1773 0 : lines_printed += write_event( config, cur_tile );
1774 0 : lines_printed += write_backup( config, cur_tile );
1775 :
1776 0 : PRINT( "\033[?7h" ); /* enable autowrap mode */
1777 0 : }
1778 :
1779 : static void
1780 : snap_tiles( fd_topo_t const * topo,
1781 0 : ulong * tiles ) {
1782 0 : for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
1783 0 : fd_topo_tile_t const * tile = &topo->tiles[ i ];
1784 0 : volatile ulong const * metrics = fd_metrics_tile( tile->metrics );
1785 0 : FD_TEST( metrics );
1786 0 : for( ulong j=0UL; j<FD_METRICS_TOTAL_SZ/8UL; j++ ) tiles[ i*FD_METRICS_TOTAL_SZ+j ] = metrics[ j ];
1787 0 : }
1788 0 : }
1789 :
1790 : static void
1791 : snap_links( fd_topo_t const * topo,
1792 0 : ulong * links ) {
1793 0 : ulong overall_polled_idx = 0UL;
1794 :
1795 0 : for( ulong i=0UL; i<topo->tile_cnt; i++ ) {
1796 0 : fd_topo_tile_t const * tile = &topo->tiles[ i ];
1797 :
1798 0 : ulong polled_in_idx = 0UL;
1799 0 : for( ulong j=0UL; j<topo->tiles[ i ].in_cnt; j++ ) {
1800 0 : if( FD_UNLIKELY( !tile->in_link_poll[ j ] ) ) continue;
1801 :
1802 0 : volatile ulong const * metrics = fd_metrics_link_in( tile->metrics, polled_in_idx );
1803 0 : FD_TEST( metrics );
1804 0 : for( ulong k=0UL; k<FD_METRICS_ALL_LINK_IN_TOTAL; k++ ) links[ overall_polled_idx*8UL+k ] = metrics[ k ];
1805 0 : polled_in_idx++;
1806 0 : overall_polled_idx++;
1807 0 : }
1808 0 : }
1809 0 : }
1810 :
1811 : static ulong tiles[ 2UL*FD_TILE_MAX*FD_METRICS_TOTAL_SZ ];
1812 : static ulong links[ 2UL*4096UL*8UL*FD_METRICS_ALL_LINK_IN_TOTAL ];
1813 :
1814 : static void
1815 : run( config_t const * config,
1816 0 : int drain_output_fd ) {
1817 0 : (void)config;
1818 0 : (void)drain_output_fd;
1819 :
1820 0 : ulong node_info_obj_id = fd_pod_query_ulong( config->topo.props, "node_info", ULONG_MAX );
1821 0 : fd_node_info_box_t * node_info = node_info_obj_id==ULONG_MAX ? NULL :
1822 0 : fd_node_info_box_join( fd_topo_obj_laddr( &config->topo, node_info_obj_id ) );
1823 0 : FD_TEST( node_info_obj_id==ULONG_MAX || node_info );
1824 :
1825 0 : ulong tile_cnt = config->topo.tile_cnt;
1826 :
1827 0 : ulong cons_cnt = 0UL;
1828 0 : for( ulong i=0UL; i<config->topo.tile_cnt; i++ ) {
1829 0 : for( ulong j=0UL; j<config->topo.tiles[ i ].in_cnt; j++ ) {
1830 0 : if( FD_UNLIKELY( config->topo.tiles[ i ].in_link_poll[ j ] ) ) cons_cnt++;
1831 0 : }
1832 0 : }
1833 :
1834 0 : FD_TEST( tile_cnt<=FD_TILE_MAX );
1835 0 : FD_TEST( cons_cnt<=4096UL );
1836 :
1837 0 : snap_tiles( &config->topo, tiles );
1838 0 : fd_memcpy( tiles+tile_cnt*FD_METRICS_TOTAL_SZ, tiles, tile_cnt*FD_METRICS_TOTAL_SZ*sizeof(ulong) );
1839 :
1840 0 : snap_links( &config->topo, links );
1841 0 : fd_memcpy( links+(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL), links, cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL*sizeof(ulong) );
1842 :
1843 0 : snap_cur_nanos = wallclock_monotonic();
1844 0 : snap_prev_nanos = snap_cur_nanos-(long)1e7;
1845 :
1846 0 : ulong last_snap = 1UL;
1847 :
1848 :
1849 0 : frame_len = 0UL;
1850 0 : write_summary( config, node_info, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, links+last_snap*(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL), links+(1UL-last_snap)*(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL) );
1851 0 : flush_frame();
1852 :
1853 0 : long next = fd_log_wallclock()+(long)1e7;
1854 0 : for(;;) {
1855 0 : long timeout_ns = next-fd_log_wallclock();
1856 0 : if( FD_LIKELY( timeout_ns>0L ) ) {
1857 0 : fd_set rfds;
1858 0 : FD_ZERO( &rfds );
1859 0 : if( FD_LIKELY( drain_output_fd>=0 ) ) FD_SET( drain_output_fd, &rfds );
1860 0 : struct timeval tv = { .tv_sec = timeout_ns/(long)1e9, .tv_usec = (timeout_ns%(long)1e9)/1000L+1L };
1861 0 : if( FD_UNLIKELY( -1==select( drain_output_fd>=0 ? drain_output_fd+1 : 0, drain_output_fd>=0 ? &rfds : NULL, NULL, NULL, &tv ) && errno!=EINTR ) )
1862 0 : FD_LOG_ERR(( "select() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
1863 0 : }
1864 0 : if( FD_UNLIKELY( drain_output_fd>=0 ) ) {
1865 0 : if( FD_UNLIKELY( drain( drain_output_fd ) ) ) {
1866 0 : frame_len = 0UL;
1867 0 : write_summary( config, node_info, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, links+last_snap*(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL), links+(1UL-last_snap)*(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL) );
1868 0 : flush_frame();
1869 0 : }
1870 0 : }
1871 :
1872 0 : long now = fd_log_wallclock();
1873 0 : if( FD_UNLIKELY( now>=next ) ) {
1874 0 : last_snap = 1UL-last_snap;
1875 0 : snap_tiles( &config->topo, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ );
1876 0 : snap_links( &config->topo, links+last_snap*(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL) );
1877 0 : snap_prev_nanos = snap_cur_nanos;
1878 0 : snap_cur_nanos = wallclock_monotonic();
1879 0 : snap_dt_samples[ (snap_dt_idx++)%(sizeof(snap_dt_samples)/sizeof(snap_dt_samples[0])) ] = snap_cur_nanos-snap_prev_nanos;
1880 :
1881 : /* Bench */
1882 0 : tps_sent_samples[ tps_sent_samples_idx%(sizeof(tps_sent_samples)/sizeof(tps_sent_samples[0])) ] = diff_tile( config, "benchs", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, BENCHS, TXN_TX ) );
1883 0 : tps_sent_samples_idx++;
1884 :
1885 : /* Replay */
1886 0 : sps_samples[ sps_samples_idx%(sizeof(sps_samples)/sizeof(sps_samples[0])) ] = diff_tile( config, "replay", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, REPLAY, BANK_FROZEN ) );
1887 0 : sps_samples_idx++;
1888 0 : tps_samples[ tps_samples_idx%(sizeof(tps_samples)/sizeof(tps_samples[0])) ] = diff_tile( config, "replay", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( GAUGE, REPLAY, CHAIN_TXN_HEIGHT ) );
1889 0 : tps_samples_idx++;
1890 0 : cups_samples[ cups_samples_idx%(sizeof(cups_samples)/sizeof(cups_samples[0])) ] =
1891 0 : diff_tile( config, "execrp", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, EXECRP, CU_CONSUMED ) ) +
1892 0 : diff_tile( config, "execle", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, EXECLE, CU_CONSUMED ) );
1893 0 : cups_samples_idx++;
1894 :
1895 : /* Snapshot */
1896 0 : snapshot_rx_samples[ snapshot_rx_idx%(sizeof(snapshot_rx_samples)/sizeof(snapshot_rx_samples[0])) ] = diff_tile( config, "snapct", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( GAUGE, SNAPCT, READ_PROGRESS_BYTES_FULL ) ) +
1897 0 : diff_tile( config, "snapct", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( GAUGE, SNAPCT, READ_PROGRESS_BYTES_INCREMENTAL ) );
1898 0 : snapshot_rx_idx++;
1899 0 : snapshot_acc_samples[ snapshot_acc_idx%(sizeof(snapshot_acc_samples)/sizeof(snapshot_acc_samples[0])) ] = diff_tile( config, "snapin", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( GAUGE, SNAPIN, ACCOUNT_PROGRESS_NEW ) );
1900 0 : snapshot_acc_idx++;
1901 0 : snapshot_wr_samples[ snapshot_wr_idx%(sizeof(snapshot_wr_samples)/sizeof(snapshot_wr_samples[0])) ] = diff_tile( config, "snapin", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, SNAPIN, DISK_WRITTEN_BYTES ) );
1902 0 : snapshot_wr_idx++;
1903 :
1904 : /* Backup */
1905 0 : backup_acc_samples[ backup_acc_idx%(sizeof(backup_acc_samples)/sizeof(backup_acc_samples[0])) ] = diff_tile( config, "snapzp", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, SNAPZP, ACCOUNT_COMPRESSED ) );
1906 0 : backup_acc_idx++;
1907 0 : backup_read_samples[ backup_read_idx%(sizeof(backup_read_samples)/sizeof(backup_read_samples[0])) ] = diff_tile( config, "snaprd", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, SNAPRD, DISK_READ_BYTES ) );
1908 0 : backup_read_idx++;
1909 0 : backup_comp_samples[ backup_comp_idx%(sizeof(backup_comp_samples)/sizeof(backup_comp_samples[0])) ] = diff_tile( config, "snapmk", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, SNAPMK, COMPRESS_CONSUMED_BYTES ) ) +
1910 0 : diff_tile( config, "snapzp", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, SNAPZP, COMPRESS_CONSUMED_BYTES ) );
1911 0 : backup_comp_idx++;
1912 0 : backup_upload_samples[ backup_upload_idx%(sizeof(backup_upload_samples)/sizeof(backup_upload_samples[0])) ] = diff_tile( config, "snapsv", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, SNAPSV, HTTP_TX_BYTES ) );
1913 0 : backup_upload_idx++;
1914 :
1915 : /* Events */
1916 0 : events_sent_samples[ events_sent_samples_idx%(sizeof(events_sent_samples)/sizeof(events_sent_samples[0])) ] = diff_tile( config, "event", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, EVENT, EVENT_TX ) );
1917 0 : events_sent_samples_idx++;
1918 0 : events_acked_samples[ events_acked_samples_idx%(sizeof(events_acked_samples)/sizeof(events_acked_samples[0])) ] = diff_tile( config, "event", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, EVENT, ACK_RX ) );
1919 0 : events_acked_samples_idx++;
1920 0 : event_bytes_written_samples[ event_bytes_written_samples_idx%(sizeof(event_bytes_written_samples)/sizeof(event_bytes_written_samples[0])) ] = diff_tile( config, "event", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, EVENT, STREAM_TX_BYTES ) );
1921 0 : event_bytes_written_samples_idx++;
1922 0 : event_bytes_read_samples[ event_bytes_read_samples_idx%(sizeof(event_bytes_read_samples)/sizeof(event_bytes_read_samples[0])) ] = diff_tile( config, "event", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, EVENT, STREAM_RX_BYTES ) );
1923 0 : event_bytes_read_samples_idx++;
1924 :
1925 : /* Accounts */
1926 0 : sample_accdb( config, tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ );
1927 :
1928 : /* Gossip */
1929 0 : sample_gossip( config, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, now );
1930 :
1931 : /* Repair server */
1932 0 : shreds_stored_sample[ shreds_stored_samples_idx%(sizeof(shreds_stored_sample)/sizeof(shreds_stored_sample[0])) ] = diff_tile( config, "rserve", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( GAUGE, RSERVE, SHRED_USED ) );
1933 0 : shreds_stored_samples_idx++;
1934 :
1935 0 : rserve_rps_valid_samples[ rserve_rps_valid_samples_idx%(sizeof(rserve_rps_valid_samples)/sizeof(rserve_rps_valid_samples[0])) ] =
1936 0 : diff_tile( config, "rserve", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, RSERVE, RESPONSE_TX_PING ) ) +
1937 0 : diff_tile( config, "rserve", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, RSERVE, RESPONSE_TX_WINDOW_INDEX ) ) +
1938 0 : diff_tile( config, "rserve", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, RSERVE, RESPONSE_TX_HIGHEST_WINDOW_INDEX ) ) +
1939 0 : diff_tile( config, "rserve", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, RSERVE, RESPONSE_TX_ORPHAN ) );
1940 0 : rserve_rps_valid_samples_idx++;
1941 :
1942 0 : rserve_rps_invalid_samples[ rserve_rps_invalid_samples_idx%(sizeof(rserve_rps_invalid_samples)/sizeof(rserve_rps_invalid_samples[0])) ] = 0UL;
1943 0 : for( ulong r=0UL; r<FD_METRICS_ENUM_REPAIR_REQUEST_TYPE_CNT; r++ ) {
1944 0 : rserve_rps_invalid_samples[ rserve_rps_invalid_samples_idx%(sizeof(rserve_rps_invalid_samples)/sizeof(rserve_rps_invalid_samples[0])) ] +=
1945 0 : diff_tile( config, "rserve", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, RSERVE, REQUEST_UNANSWERED )+r );
1946 0 : }
1947 0 : for( ulong r=0UL; r<FD_METRICS_ENUM_REQUEST_DROP_REASON_CNT; r++ ) {
1948 0 : rserve_rps_invalid_samples[ rserve_rps_invalid_samples_idx%(sizeof(rserve_rps_invalid_samples)/sizeof(rserve_rps_invalid_samples[0])) ] +=
1949 0 : diff_tile( config, "rserve", tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+r );
1950 0 : }
1951 0 : {
1952 0 : ulong slot = rserve_rps_invalid_samples_idx % (sizeof(rserve_rps_miss_samples)/sizeof(rserve_rps_miss_samples[0]));
1953 0 : ulong const * prev = tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ;
1954 0 : ulong const * cur = tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ;
1955 :
1956 0 : rserve_rps_miss_samples[ slot ] = 0UL;
1957 0 : for( ulong r=0UL; r<FD_METRICS_ENUM_REPAIR_REQUEST_TYPE_CNT; r++ ) rserve_rps_miss_samples[ slot ] += diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_UNANSWERED )+r );
1958 :
1959 0 : rserve_rps_sigvfy_samples[ slot ] = diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+FD_METRICS_ENUM_REQUEST_DROP_REASON_V_SIGNATURE_FAILED_IDX );
1960 :
1961 0 : rserve_rps_stale_samples[ slot ] = diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+FD_METRICS_ENUM_REQUEST_DROP_REASON_V_TIMESTAMP_SKEW_IDX );
1962 :
1963 0 : rserve_rps_other_rej_samples[ slot ] =
1964 0 : diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+FD_METRICS_ENUM_REQUEST_DROP_REASON_V_FROM_SELF_IDX ) +
1965 0 : diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+FD_METRICS_ENUM_REQUEST_DROP_REASON_V_PONG_TOKEN_INVALID_IDX ) +
1966 0 : diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+FD_METRICS_ENUM_REQUEST_DROP_REASON_V_WRONG_RECIPIENT_IDX ) +
1967 0 : diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+FD_METRICS_ENUM_REQUEST_DROP_REASON_V_SHRED_INDEX_INVALID_IDX ) +
1968 0 : diff_tile( config, "rserve", prev, cur, MIDX( COUNTER, RSERVE, REQUEST_DROPPED )+FD_METRICS_ENUM_REQUEST_DROP_REASON_V_FEC_SET_INDEX_INVALID_IDX );
1969 0 : }
1970 0 : rserve_rps_invalid_samples_idx++;
1971 :
1972 : /* Move cursor to top of dashboard and overwrite in place.
1973 : All output is buffered and flushed in a single write() so
1974 : the terminal never renders a partially drawn frame. */
1975 0 : frame_len = 0UL;
1976 0 : PRINT( "\033[?25l" ); /* hide cursor during redraw */
1977 0 : if( FD_UNLIKELY( !ended_on_newline ) ) {
1978 0 : PRINT( "\033[%luA\r", lines_printed+1UL );
1979 0 : } else {
1980 0 : PRINT( "\033[%luA\r", lines_printed );
1981 0 : }
1982 0 : write_summary( config, node_info, tiles+last_snap*tile_cnt*FD_METRICS_TOTAL_SZ, tiles+(1UL-last_snap)*tile_cnt*FD_METRICS_TOTAL_SZ, links+last_snap*(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL), links+(1UL-last_snap)*(cons_cnt*8UL*FD_METRICS_ALL_LINK_IN_TOTAL) );
1983 0 : PRINT( "\033[0J" ); /* clear any leftover lines below */
1984 0 : PRINT( "\033[?25h" ); /* show cursor */
1985 0 : flush_frame();
1986 0 : next += (long)1e7;
1987 0 : }
1988 0 : }
1989 0 : }
1990 :
1991 : void
1992 : watch_cmd_args( int * pargc,
1993 : char *** pargv,
1994 0 : args_t * args ) {
1995 0 : args->watch.drain_output_fd = -1;
1996 0 : args->watch.full = fd_env_strip_cmdline_contains( pargc, pargv, "--full" );
1997 0 : }
1998 :
1999 : void
2000 : watch_cmd_fn( args_t * args,
2001 0 : config_t * config ) {
2002 : /* Development commands spawn watch internally with the validator's
2003 : own config, only discover when invoked standalone. */
2004 0 : if( FD_LIKELY( args->watch.drain_output_fd==-1 ) ) fd_bootinfo_adopt( config );
2005 :
2006 0 : int allow_fds[ 5 ];
2007 0 : ulong allow_fds_cnt = 0;
2008 0 : allow_fds[ allow_fds_cnt++ ] = 0; /* stdin */
2009 0 : allow_fds[ allow_fds_cnt++ ] = 1; /* stdout */
2010 0 : allow_fds[ allow_fds_cnt++ ] = 2; /* stderr */
2011 0 : if( FD_LIKELY( fd_log_private_logfile_fd()!=-1 ) )
2012 0 : allow_fds[ allow_fds_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
2013 0 : if( FD_UNLIKELY( args->watch.drain_output_fd!=-1 ) )
2014 0 : allow_fds[ allow_fds_cnt++ ] = args->watch.drain_output_fd; /* maybe we are interposing firedancer log output with the monitor */
2015 :
2016 0 : if( FD_LIKELY( args->watch.drain_output_fd==-1 ) ) fd_bootinfo_check_layout( config );
2017 0 : fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_ONLY, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
2018 :
2019 0 : struct sock_filter seccomp_filter[ 128UL ];
2020 0 : uint drain_output_fd = args->watch.drain_output_fd >= 0 ? (uint)args->watch.drain_output_fd : (uint)-1;
2021 0 : populate_sock_filter_policy_watch( 128UL, seccomp_filter, (uint)fd_log_private_logfile_fd(), drain_output_fd );
2022 :
2023 0 : if( FD_LIKELY( config->development.sandbox ) ) {
2024 0 : fd_sandbox_enter( config->uid,
2025 0 : config->gid,
2026 0 : 0,
2027 0 : 0,
2028 0 : 0,
2029 0 : 1, /* Keep controlling terminal for main so it can receive Ctrl+C */
2030 0 : 0,
2031 0 : 0UL,
2032 0 : 0UL,
2033 0 : 0UL,
2034 0 : 0UL,
2035 0 : allow_fds_cnt,
2036 0 : allow_fds,
2037 0 : sock_filter_policy_watch_instr_cnt,
2038 0 : seccomp_filter );
2039 0 : } else {
2040 0 : fd_sandbox_switch_uid_gid( config->uid, config->gid );
2041 0 : }
2042 :
2043 0 : fd_topo_fill( &config->topo );
2044 :
2045 0 : watch_full = args->watch.full;
2046 0 : run( config, args->watch.drain_output_fd );
2047 0 : }
2048 :
2049 : static void
2050 0 : watch_args_help( fd_action_help_t * help ) {
2051 0 : fd_action_help_arg( help, "--full", NULL, "Show all detail rows for each category, not just the primary row" );
2052 0 : }
2053 :
2054 : action_t fd_action_watch = {
2055 : .name = "watch",
2056 : .args = watch_cmd_args,
2057 : .fn = watch_cmd_fn,
2058 : .require_config = 0,
2059 : .perm = watch_cmd_perm,
2060 : .description = "Watch a locally running Firedancer instance with a terminal GUI",
2061 : .detail = "Connects to a running validator and renders a terminal dashboard of the\n"
2062 : "most important monitoring and operational metrics.",
2063 : .usage = "watch [--full]",
2064 : .args_help = watch_args_help,
2065 : };
|