From: Michael Tremer Date: Wed, 29 Oct 2025 11:46:22 +0000 (+0000) Subject: graphs: Simplify the LINE macros X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eba1800daa9a0ceb774325c4d2f210a62242f230;p=telemetry.git graphs: Simplify the LINE macros We should pass the strength of the line instead of replicating the same macro again and again. Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graphs/conntrack.c b/src/daemon/graphs/conntrack.c index 48cbd80..20d2338 100644 --- a/src/daemon/graphs/conntrack.c +++ b/src/daemon/graphs/conntrack.c @@ -51,7 +51,7 @@ static int conntrack_render(td_ctx* ctx, PRINT_CAMM(args, "count", NULL, LARGE_INTEGER); // Limit - DRAW_LINE1_WITH_LABEL(args, "max", NULL, LIMIT, _("Limit"), DASHES SKIPSCALE); + DRAW_LINE_WITH_LABEL(args, 1, "max", NULL, LIMIT, _("Limit"), DASHES SKIPSCALE); PRINT(args, FIELD_CURRENT("max_cur"), NULL, LARGE_INTEGER); PRINT_NOTHING(args); PRINT_NOTHING(args); diff --git a/src/daemon/graphs/cpufreq.c b/src/daemon/graphs/cpufreq.c index e3b6a8e..1b883c6 100644 --- a/src/daemon/graphs/cpufreq.c +++ b/src/daemon/graphs/cpufreq.c @@ -58,14 +58,14 @@ static int cpufreq_render(td_ctx* ctx, return r; // Draw the line - DRAW_LINE1_WITH_LABEL(args, "freq_cur", object, COLOR_CPU(i), _("CPU Core %ld")); + DRAW_LINE_WITH_LABEL(args, 1, "freq_cur", object, COLOR_CPU(i), _("CPU Core %ld")); PRINT_CAMM(args, "freq_cur", object, HZ, _("Hz")); // Draw the minimum - DRAW_LINE2(args, "freq_min", object, MINIMUM); + DRAW_LINE(args, 2, "freq_min", object, MINIMUM); // Draw the maximum - DRAW_LINE2(args, "freq_max", object, MAXIMUM); + DRAW_LINE(args, 2, "freq_max", object, MAXIMUM); } return 0; diff --git a/src/daemon/graphs/graph.h b/src/daemon/graphs/graph.h index ab4d9d6..8cab94c 100644 --- a/src/daemon/graphs/graph.h +++ b/src/daemon/graphs/graph.h @@ -79,28 +79,20 @@ SCRIPT(args, what ":" FIELD "%s:" LABEL __VA_ARGS__, FIELD_AND_OBJECT(field, object), color, label) // Draw lines -#define DRAW_LINE1(args, field, object, color, ...) \ - DRAW(args, "LINE1", field, object, color, __VA_ARGS__) -#define DRAW_LINE1_WITH_LABEL(args, field, object, color, label, ...) \ - DRAW_WITH_LABEL(args, "LINE1", field, object, color, label, __VA_ARGS__) - -#define DRAW_LINE2(args, field, object, color, ...) \ - DRAW(args, "LINE2", field, object, color, __VA_ARGS__) -#define DRAW_LINE2_WITH_LABEL(args, field, object, color, label, ...) \ - DRAW_WITH_LABEL(args, "LINE2", field, object, color, label, __VA_ARGS__) - -#define DRAW_LINE3(args, field, object, color, ...) \ - DRAW(args, "LINE3", field, object, color, __VA_ARGS__) -#define DRAW_LINE3_WITH_LABEL(args, field, object, color, label, ...) \ - DRAW_WITH_LABEL(args, "LINE3", field, object, color, label, __VA_ARGS__) +#define DRAW_LINE(args, strength, field, object, color, ...) \ + DRAW(args, "LINE" TOSTRING(strength), field, object, color, __VA_ARGS__) +#define DRAW_LINE_WITH_LABEL(args, strength, field, object, color, label, ...) \ + DRAW_WITH_LABEL(args, "LINE" TOSTRING(strength), field, object, color, label, __VA_ARGS__) // Macros to draw the background of an area #define DRAW_AREA_BACKGROUND(args, field, object, color, ...) \ DRAW(args, "AREA", field, object, COLOR_WITH_ALPHA(color, OPACITY_AREA), __VA_ARGS__) // Macros to draw the area's outline -#define DRAW_AREA_OUTLINE DRAW_LINE1 -#define DRAW_AREA_OUTLINE_WITH_LABEL DRAW_LINE1_WITH_LABEL +#define DRAW_AREA_OUTLINE(args, field, object, color) \ + DRAW_LINE(args, 1, field, object, color) +#define DRAW_AREA_OUTLINE_WITH_LABEL(args, field, object, color, label, ...) \ + DRAW_LINE_WITH_LABEL(args, 1, field, object, color, label, __VA_ARGS__) #define DRAW_AREA(args, field, object, color) \ do { \ diff --git a/src/daemon/graphs/hostapd-station-rate-info.c b/src/daemon/graphs/hostapd-station-rate-info.c index 5f796ae..d83d6c1 100644 --- a/src/daemon/graphs/hostapd-station-rate-info.c +++ b/src/daemon/graphs/hostapd-station-rate-info.c @@ -47,11 +47,11 @@ static int hostapd_station_rate_info_render(td_ctx* ctx, PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); // Receive Rate - DRAW_LINE2_WITH_LABEL(args, "rx_rate", object, COLOR_RX, _("Receive Rate")); + DRAW_LINE_WITH_LABEL(args, 2, "rx_rate", object, COLOR_RX, _("Receive Rate")); PRINT_CAMM(args, "rx_rate", object, BPS, _("bps")); // Transmit Rate - DRAW_LINE2_WITH_LABEL(args, "tx_rate", object, COLOR_TX, _("Transmit Rate")); + DRAW_LINE_WITH_LABEL(args, 2, "tx_rate", object, COLOR_TX, _("Transmit Rate")); PRINT_CAMM(args, "tx_rate", object, BPS, _("bps")); return 0; diff --git a/src/daemon/graphs/hostapd-station-signal.c b/src/daemon/graphs/hostapd-station-signal.c index 7df75c2..528b5b4 100644 --- a/src/daemon/graphs/hostapd-station-signal.c +++ b/src/daemon/graphs/hostapd-station-signal.c @@ -59,16 +59,16 @@ static int hostapd_station_signal_render(td_ctx* ctx, PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); // Draw signal - DRAW_LINE2_WITH_LABEL(args, "signal", object, GREEN, _("Signal")); + DRAW_LINE_WITH_LABEL(args, 2, "signal", object, GREEN, _("Signal")); PRINT_CAMM(args, "signal", object, FLOAT_WITH_UNIT, _("dBm")); // Draw the lower signal quality in different colors - DRAW_LINE2(args, "signal_good", object, YELLOW); - DRAW_LINE2(args, "signal_fair", object, ORANGE); - DRAW_LINE2(args, "signal_poor", object, RED); + DRAW_LINE(args, 2, "signal_good", object, YELLOW); + DRAW_LINE(args, 2, "signal_fair", object, ORANGE); + DRAW_LINE(args, 2, "signal_poor", object, RED); // Draw last ACK signal - DRAW_LINE2_WITH_LABEL(args, "last_ack_signal", object, GREY, _("Last ACK Signal")); + DRAW_LINE_WITH_LABEL(args, 2, "last_ack_signal", object, GREY, _("Last ACK Signal")); PRINT_CAMM(args, "last_ack_signal", object, FLOAT_WITH_UNIT, _("dBm")); return 0; diff --git a/src/daemon/graphs/memory.c b/src/daemon/graphs/memory.c index 21aa727..03a8406 100644 --- a/src/daemon/graphs/memory.c +++ b/src/daemon/graphs/memory.c @@ -81,18 +81,18 @@ static int memory_render(td_ctx* ctx, PRINT_CAMM(args, "cached", NULL, LARGE_FLOAT); // Draw the total memory as a line - DRAW_LINE1(args, "mem_total", NULL, COLOR_MEM_TOTAL); + DRAW_LINE(args, 1, "mem_total", NULL, COLOR_MEM_TOTAL); // Make some space for swap PRINT_EMPTY_LINE(args); - DRAW_LINE1_WITH_LABEL(args, "swap_used", NULL, COLOR_SWAP_USED, _("Used Swap"), DASHES); + DRAW_LINE_WITH_LABEL(args, 1, "swap_used", NULL, COLOR_SWAP_USED, _("Used Swap"), DASHES); PRINT_CAMM(args, "swap_used", NULL, LARGE_FLOAT); PRINT_EMPTY_LABEL(args); PRINT_CAMM(args, "swap_used", NULL, PERCENTAGE); - DRAW_LINE1_WITH_LABEL(args, "swap_total", NULL, COLOR_SWAP_TOTAL, _("Total Swap"), DASHES); + DRAW_LINE_WITH_LABEL(args, 1, "swap_total", NULL, COLOR_SWAP_TOTAL, _("Total Swap"), DASHES); PRINT(args, FIELD_CURRENT("swap_used"), NULL, LARGE_FLOAT); PRINT_NOTHING(args); PRINT_NOTHING(args);