Added color support in compact mode.

This commit is contained in:
moosecrap 2025-02-03 06:34:33 -08:00
parent 65aa52ac42
commit d4e32a78fc
4 changed files with 18 additions and 26 deletions

View File

@ -51,6 +51,7 @@ Available options:
--compact : Print sensor reading in a compact one-line per card format --compact : Print sensor reading in a compact one-line per card format
--watch N : Keep printing output every N seconds --watch N : Keep printing output every N seconds
--overwrite : Overwrite previously displayed info with --watch and --compact instead of continuously logging new lines --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: ### Examples:

View File

@ -17,6 +17,11 @@
#include "evga-card.h" #include "evga-card.h"
#define MAX_GPUS 16 #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" static const char helpstring[] = "Available options:\n"
"--gpu N : Control only GPU N instead of all supported cards\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" "--sensors : Print sensor readings even if setting a fan speed \n"
"--compact : Print sensor reading in a compact one-line per card format\n" "--compact : Print sensor reading in a compact one-line per card format\n"
"--watch N : Keep printing output every N seconds\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); 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) { } else if (strcmp(argv[i], "--overwrite") == 0) {
overwrite = 1; overwrite = 1;
} else if (strcmp(argv[i], "--color") == 0) {
header_start = HEADER_COLOR_START;
header_end = HEADER_COLOR_END;
} else { } else {
printf(helpstring); printf(helpstring);
return 0; 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) { void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) {
if (compact) { if (compact) {
/* One line per GPU */ /* One line per GPU */
printf("#%d ", gpu_num); printf("%s#%d FAN%s", header_start, gpu_num, header_end);
print_icx3_fans_oneline(gpu); print_icx3_fans_oneline(gpu);
printf(" GPU"); printf("%s GPU%s", header_start, header_end);
#ifdef USE_NVML #ifdef USE_NVML
printf(" %3d", get_nvml_temp(gpu)); 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); get_temp_sensors(icx_temp_sensors, gpu);
for (int i = 0; i < ICX3_NUM_TEMP_SENSORS; i++) { 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)) 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 #ifdef USE_LIBPCI
if (strncmp(icx3_temp_sensor_names[i], "MEM1", 4) == 0) 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 */ 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 #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 #endif
printf("°C "); printf("°C ");
#ifdef USE_NVML #ifdef USE_NVML
printf("%s CLK %s", header_start, header_end);
print_nvml_clock_reason(1, gpu); print_nvml_clock_reason(1, gpu);
#endif #endif
@ -246,6 +256,7 @@ void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) {
#endif #endif
#ifdef USE_NVML #ifdef USE_NVML
printf("Clock reasons: ");
print_nvml_clock_reason(0, gpu); print_nvml_clock_reason(0, gpu);
#endif #endif
} }

15
icx3.c
View File

@ -62,27 +62,12 @@ void print_icx3_fans_oneline(struct card_info *card)
struct icx3_fan_control fans[ICX3_MAX_FANS]; struct icx3_fan_control fans[ICX3_MAX_FANS];
get_fan_status(fans, card); get_fan_status(fans, card);
printf("FAN");
for (int i=0; i < ICX3_MAX_FANS; i++) { for (int i=0; i < ICX3_MAX_FANS; i++) {
printf(" %3d", fans[i].duty_status); printf(" %3d", fans[i].duty_status);
} }
printf("%%"); 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<ICX3_NUM_TEMP_SENSORS; i++) {
/* If this math seems a little jank, it's so we can optionally inject the NVML and vram temps into the oneline */
if (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) void get_available_fans(char *fans_avail, struct card_info *card)
{ {
int product_id = card->product_id; int product_id = card->product_id;

View File

@ -15,11 +15,6 @@ void print_nvml_clock_reason(int compact, struct card_info *card)
unsigned long long reasons = get_nvml_clock_reasons(card); unsigned long long reasons = get_nvml_clock_reasons(card);
int single_reason = 1; 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++) { for (int i = 0; i < (sizeof(clock_reason_names) / sizeof(struct clock_reason)); i++) {
if (reasons & clock_reason_names[i].mask) { if (reasons & clock_reason_names[i].mask) {
if (!single_reason) { if (!single_reason) {