From d4e32a78fcd39bf53b99cf0f49b21be4e9741613 Mon Sep 17 00:00:00 2001 From: moosecrap Date: Mon, 3 Feb 2025 06:34:33 -0800 Subject: [PATCH] Added color support in compact mode. --- README.md | 1 + evga-icx.c | 21 ++++++++++++++++----- icx3.c | 15 --------------- nvidia-sensors.c | 7 +------ 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 5504c23..155adbe 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Available options: --compact : Print sensor reading in a compact one-line per card format --watch N : Keep printing output every N seconds --overwrite : Overwrite previously displayed info with --watch and --compact instead of continuously logging new lines +--color : Print headers in color in --compact mode for better readability ``` ### Examples: diff --git a/evga-icx.c b/evga-icx.c index ea3bf63..028b39a 100644 --- a/evga-icx.c +++ b/evga-icx.c @@ -17,6 +17,11 @@ #include "evga-card.h" #define MAX_GPUS 16 +#define HEADER_COLOR_START "\x1b[36m" +#define HEADER_COLOR_END "\x1b[39m" + +char *header_start = ""; +char *header_end = ""; static const char helpstring[] = "Available options:\n" "--gpu N : Control only GPU N instead of all supported cards\n" @@ -30,7 +35,8 @@ static const char helpstring[] = "Available options:\n" "--sensors : Print sensor readings even if setting a fan speed \n" "--compact : Print sensor reading in a compact one-line per card format\n" "--watch N : Keep printing output every N seconds\n" - "--overwrite : Overwrite previously displayed info with --watch and --compact instead of continuously logging\n"; + "--overwrite : Overwrite previously displayed info with --watch and --compact instead of continuously logging\n" + "--color : Print headers in color in --compact mode for better readability\n"; void print_gpu_info(int gpu_num, struct card_info gpus[], int compact); @@ -91,6 +97,9 @@ int main (int argc, char **argv) } } else if (strcmp(argv[i], "--overwrite") == 0) { overwrite = 1; + } else if (strcmp(argv[i], "--color") == 0) { + header_start = HEADER_COLOR_START; + header_end = HEADER_COLOR_END; } else { printf(helpstring); return 0; @@ -190,9 +199,9 @@ int main (int argc, char **argv) void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) { if (compact) { /* One line per GPU */ - printf("#%d ", gpu_num); + printf("%s#%d FAN%s", header_start, gpu_num, header_end); print_icx3_fans_oneline(gpu); - printf(" GPU"); + printf("%s GPU%s", header_start, header_end); #ifdef USE_NVML printf(" %3d", get_nvml_temp(gpu)); @@ -202,7 +211,7 @@ void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) { get_temp_sensors(icx_temp_sensors, gpu); for (int i = 0; i < ICX3_NUM_TEMP_SENSORS; i++) { if (i > 0 && strncmp(icx3_temp_sensor_names[i], icx3_temp_sensor_names[i-1], 3)) - printf(" %.3s", icx3_temp_sensor_names[i]); + printf("%s %.3s%s", header_start, icx3_temp_sensor_names[i], header_end); #ifdef USE_LIBPCI if (strncmp(icx3_temp_sensor_names[i], "MEM1", 4) == 0) printf(" %3.0f", get_vram_temp(gpu)); /* Print the VRAM temp before the rest of the memory sensors */ @@ -211,12 +220,13 @@ void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) { } #ifdef USE_LIBPCI - printf(" HOT %3.0f", get_hotspot_temp(gpu)); + printf("%s HOT%s %3.0f", header_start, header_end, get_hotspot_temp(gpu)); #endif printf("°C "); #ifdef USE_NVML + printf("%s CLK %s", header_start, header_end); print_nvml_clock_reason(1, gpu); #endif @@ -246,6 +256,7 @@ void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) { #endif #ifdef USE_NVML + printf("Clock reasons: "); print_nvml_clock_reason(0, gpu); #endif } diff --git a/icx3.c b/icx3.c index 289f558..89e7dd1 100644 --- a/icx3.c +++ b/icx3.c @@ -62,27 +62,12 @@ void print_icx3_fans_oneline(struct card_info *card) struct icx3_fan_control fans[ICX3_MAX_FANS]; get_fan_status(fans, card); - printf("FAN"); for (int i=0; i < ICX3_MAX_FANS; i++) { printf(" %3d", fans[i].duty_status); } printf("%%"); } -void print_icx3_temps_oneline(struct card_info *card) -{ - float temps[ICX3_NUM_TEMP_SENSORS]; - - get_temp_sensors(temps, card); - - for (int i=0; i 0 && strncmp(icx3_temp_sensor_names[i], icx3_temp_sensor_names[i-1], 3)) - printf(" %.3s", icx3_temp_sensor_names[i]); - printf(" %3.0f", temps[i]); - } -} - void get_available_fans(char *fans_avail, struct card_info *card) { int product_id = card->product_id; diff --git a/nvidia-sensors.c b/nvidia-sensors.c index 2cdeee8..90aeb44 100644 --- a/nvidia-sensors.c +++ b/nvidia-sensors.c @@ -14,12 +14,7 @@ void print_nvml_clock_reason(int compact, struct card_info *card) { unsigned long long reasons = get_nvml_clock_reasons(card); int single_reason = 1; - - if (compact) - printf(" CLK "); - else - printf("Clock reasons: "); - + for (int i = 0; i < (sizeof(clock_reason_names) / sizeof(struct clock_reason)); i++) { if (reasons & clock_reason_names[i].mask) { if (!single_reason) {