Added overwrite output mode for things like live monitoring.
This commit is contained in:
+26
-5
@@ -25,7 +25,8 @@ static const char helpstring[] = "Available options:\n"
|
||||
"--reset : Reset all fans to their default mode\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";
|
||||
"--watch N : Keep printing output every N seconds\n"
|
||||
"--overwrite : Overwrite previously displayed info with --watch and --compact instead of continuously logging\n";
|
||||
|
||||
void print_gpu_info(int gpu_num, struct card_info gpus[], int compact);
|
||||
|
||||
@@ -36,6 +37,7 @@ int main (int argc, char **argv)
|
||||
int print_info = 0;
|
||||
int compact = 0;
|
||||
int gpu_num = -1; /* Card to control */
|
||||
int overwrite = 0;
|
||||
unsigned int watch = 0;
|
||||
char *fan_speed[ICX3_MAX_FANS] = {NULL};
|
||||
|
||||
@@ -83,6 +85,8 @@ int main (int argc, char **argv)
|
||||
printf(helpstring);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "--overwrite") == 0) {
|
||||
overwrite = 1;
|
||||
} else {
|
||||
printf(helpstring);
|
||||
return 0;
|
||||
@@ -98,6 +102,10 @@ int main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* Don't use overwrite mode unless set to compact (we can't tell how many lines the output will be per GPU) */
|
||||
if (overwrite && !compact)
|
||||
overwrite = 0;
|
||||
|
||||
gpu_count = find_evga_gpu_i2cs(gpus, MAX_GPUS);
|
||||
|
||||
if (gpu_count == -1) {
|
||||
@@ -131,20 +139,35 @@ int main (int argc, char **argv)
|
||||
|
||||
/* NVML init */
|
||||
#ifdef USE_NVML
|
||||
int nvml_ok = init_nvml();
|
||||
nvmlDevice_t* device[MAX_GPUS];
|
||||
init_nvml();
|
||||
#endif
|
||||
|
||||
/* print sensor info */
|
||||
if (print_info) {
|
||||
do {
|
||||
printf("\x1b[K"); /* Clear current console line (really just for overwrite mode) */
|
||||
|
||||
if (gpu_num == -1) {
|
||||
/* No GPU specified on command line, loop over all supported GPUs */
|
||||
for (int i = 0; i < gpu_count; i++){
|
||||
if (i > 0)
|
||||
printf("\n");
|
||||
print_gpu_info(i, &gpus[i], compact);
|
||||
}
|
||||
} else if (gpu_num <= gpu_count - 1) {
|
||||
print_gpu_info(gpu_num, &gpus[gpu_num], compact);
|
||||
}
|
||||
|
||||
if (!overwrite)
|
||||
printf("\n"); /* Print line break at the end for continuous output */
|
||||
|
||||
if (overwrite && compact) {
|
||||
printf("\x1b[1G"); /* Move cursor back to column 1 */
|
||||
if (gpu_count > 1)
|
||||
printf("\x1b[%dA", gpu_count-1); /* Move cursor back up to the top of gpu list */
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
sleep(watch);
|
||||
} while (watch > 0);
|
||||
}
|
||||
@@ -168,7 +191,6 @@ void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) {
|
||||
#ifdef USE_NVML
|
||||
print_nvml_clock_reason(1, gpu);
|
||||
#endif
|
||||
printf("\n");
|
||||
} else {
|
||||
/* One line per GPU sensor */
|
||||
printf("#%d: %s (%s) @ %s\n", gpu_num, gpu->card_name, gpu->i2c_dev_path, gpu->pci_id);
|
||||
@@ -180,7 +202,6 @@ void print_gpu_info(int gpu_num, struct card_info *gpu, int compact) {
|
||||
#ifdef USE_NVML
|
||||
print_nvml_clock_reason(0, gpu);
|
||||
#endif
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user