[v0.21] Add verbose option. Fix CUDA driver initialization message when verbose output is used
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
struct args_struct {
|
||||
bool help_flag;
|
||||
bool verbose_flag;
|
||||
bool version_flag;
|
||||
bool list_gpus;
|
||||
int gpu_idx;
|
||||
@@ -38,6 +39,7 @@ const char args_chr[] = {
|
||||
/* [ARG_GPU] = */ 'g',
|
||||
/* [ARG_LIST] = */ 'l',
|
||||
/* [ARG_HELP] = */ 'h',
|
||||
/* [ARG_VERBOSE] = */ 'v',
|
||||
/* [ARG_VERSION] = */ 'V',
|
||||
};
|
||||
|
||||
@@ -46,6 +48,7 @@ const char *args_str[] = {
|
||||
/* [ARG_GPU] = */ "gpu",
|
||||
/* [ARG_LIST] = */ "list-gpus",
|
||||
/* [ARG_HELP] = */ "help",
|
||||
/* [ARG_VERBOSE] = */ "verbose",
|
||||
/* [ARG_VERSION] = */ "version",
|
||||
};
|
||||
|
||||
@@ -116,6 +119,10 @@ bool show_version() {
|
||||
return args.version_flag;
|
||||
}
|
||||
|
||||
bool verbose_enabled() {
|
||||
return args.verbose_flag;
|
||||
}
|
||||
|
||||
int max_arg_str_length() {
|
||||
int max_len = -1;
|
||||
int len = sizeof(args_str) / sizeof(args_str[0]);
|
||||
@@ -131,9 +138,9 @@ char* build_short_options() {
|
||||
char* str = (char *) emalloc(sizeof(char) * (len*2 + 1));
|
||||
memset(str, 0, sizeof(char) * (len*2 + 1));
|
||||
|
||||
sprintf(str, "%c:%c:%c%c%c", c[ARG_GPU],
|
||||
sprintf(str, "%c:%c:%c%c%c%c", c[ARG_GPU],
|
||||
c[ARG_COLOR], c[ARG_HELP], c[ARG_LIST],
|
||||
c[ARG_VERSION]);
|
||||
c[ARG_VERBOSE], c[ARG_VERSION]);
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -208,6 +215,7 @@ bool parse_args(int argc, char* argv[]) {
|
||||
{args_str[ARG_GPU], required_argument, 0, args_chr[ARG_GPU] },
|
||||
{args_str[ARG_LIST], no_argument, 0, args_chr[ARG_LIST] },
|
||||
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
|
||||
{args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
|
||||
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
@@ -237,6 +245,9 @@ bool parse_args(int argc, char* argv[]) {
|
||||
else if(opt == args_chr[ARG_HELP]) {
|
||||
args.help_flag = true;
|
||||
}
|
||||
else if(opt == args_chr[ARG_VERBOSE]) {
|
||||
args.verbose_flag = true;
|
||||
}
|
||||
else if(opt == args_chr[ARG_VERSION]) {
|
||||
args.version_flag = true;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ enum {
|
||||
ARG_GPU,
|
||||
ARG_LIST,
|
||||
ARG_HELP,
|
||||
ARG_VERBOSE,
|
||||
ARG_VERSION
|
||||
};
|
||||
|
||||
@@ -34,6 +35,7 @@ bool parse_args(int argc, char* argv[]);
|
||||
bool show_help();
|
||||
bool list_gpus();
|
||||
bool show_version();
|
||||
bool verbose_enabled();
|
||||
void free_colors_struct(struct color** cs);
|
||||
int get_gpu_idx();
|
||||
struct color** get_colors();
|
||||
|
||||
@@ -26,6 +26,7 @@ enum {
|
||||
};
|
||||
|
||||
int LOG_LEVEL;
|
||||
bool clean;
|
||||
|
||||
void printWarn(const char *fmt, ...) {
|
||||
if(LOG_LEVEL == LOG_LEVEL_VERBOSE) {
|
||||
@@ -37,6 +38,7 @@ void printWarn(const char *fmt, ...) {
|
||||
va_end(args);
|
||||
fprintf(stderr, BOLD "[WARNING]: " RESET "%s\n",buffer);
|
||||
delete [] buffer;
|
||||
clean = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +51,7 @@ void printErr(const char *fmt, ...) {
|
||||
va_end(args);
|
||||
fprintf(stderr, RED "[ERROR]: " RESET "%s\n",buffer);
|
||||
delete [] buffer;
|
||||
clean = false;
|
||||
}
|
||||
|
||||
void printBug(const char *fmt, ...) {
|
||||
@@ -61,11 +64,17 @@ void printBug(const char *fmt, ...) {
|
||||
fprintf(stderr, RED "[ERROR]: " RESET "%s\n",buffer);
|
||||
fprintf(stderr,"Please, create a new issue with this error message on https://github.com/Dr-Noob/gpufetch/issues\n");
|
||||
delete [] buffer;
|
||||
clean = false;
|
||||
}
|
||||
|
||||
void set_log_level(bool verbose) {
|
||||
if(verbose) LOG_LEVEL = LOG_LEVEL_VERBOSE;
|
||||
else LOG_LEVEL = LOG_LEVEL_NORMAL;
|
||||
clean = true;
|
||||
}
|
||||
|
||||
bool clean_output() {
|
||||
return clean;
|
||||
}
|
||||
|
||||
int max(int a, int b) {
|
||||
|
||||
@@ -9,6 +9,7 @@ void set_log_level(bool verbose);
|
||||
void printWarn(const char *fmt, ...);
|
||||
void printErr(const char *fmt, ...);
|
||||
void printBug(const char *fmt, ...);
|
||||
bool clean_output();
|
||||
int max(int a, int b);
|
||||
int min(int a, int b);
|
||||
void* emalloc(size_t size);
|
||||
|
||||
@@ -22,6 +22,7 @@ void print_help(char *argv[]) {
|
||||
printf(" -%c, --%s %*s Set the color scheme (by default, gpufetch uses the system color scheme) See COLORS section for a more detailed explanation\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), "");
|
||||
printf(" -%c, --%s %*s List the available GPUs in the system\n", c[ARG_LIST], t[ARG_LIST], (int) (max_len-strlen(t[ARG_LIST])), "");
|
||||
printf(" -%c, --%s %*s Select the GPU to use (default: 0)\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), "");
|
||||
printf(" -%c, --%s %*s Enable verbose output\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), "");
|
||||
printf(" -%c, --%s %*s Print this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), "");
|
||||
printf(" -%c, --%s %*s Print gpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");
|
||||
|
||||
@@ -66,6 +67,8 @@ int main(int argc, char* argv[]) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
set_log_level(verbose_enabled());
|
||||
|
||||
struct gpu_list* list = get_gpu_list();
|
||||
if(list_gpus()) {
|
||||
return print_gpus_list(list);
|
||||
@@ -80,13 +83,11 @@ int main(int argc, char* argv[]) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
set_log_level(true);
|
||||
|
||||
struct gpu_info* gpu = get_gpu_info(list, get_gpu_idx());
|
||||
if(gpu == NULL)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
printf("[WARNING]: gpufetch is in beta. The provided information may be incomplete or wrong.\n\
|
||||
printf("[NOTE]: gpufetch is in beta. The provided information may be incomplete or wrong.\n\
|
||||
If you want to help to improve gpufetch, please compare the output of the program\n\
|
||||
with a reliable source which you know is right (e.g, techpowerup.com) and report\n\
|
||||
any inconsistencies to https://github.com/Dr-Noob/gpufetch/issues\n");
|
||||
|
||||
@@ -507,12 +507,14 @@ struct terminal* get_terminal_size() {
|
||||
bool print_gpufetch(struct gpu_info* gpu, STYLE s, struct color** cs) {
|
||||
struct terminal* term = get_terminal_size();
|
||||
|
||||
if(gpu->vendor == GPU_VENDOR_NVIDIA)
|
||||
if(gpu->vendor == GPU_VENDOR_NVIDIA) {
|
||||
#ifdef BACKEND_CUDA
|
||||
if(clean_output()) printf("%*s", (int) strlen(CUDA_DRIVER_START_WARNING), " ");
|
||||
return print_gpufetch_cuda(gpu, s, cs, term);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef BACKEND_INTEL
|
||||
return print_gpufetch_intel(gpu, s, cs, term);
|
||||
|
||||
@@ -100,7 +100,7 @@ struct gpu_info* get_gpu_info_cuda(int gpu_idx) {
|
||||
}
|
||||
|
||||
if(gpu_idx == 0) {
|
||||
printf("Waiting for CUDA driver to start...");
|
||||
printf("%s", CUDA_DRIVER_START_WARNING);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ struct gpu_info* get_gpu_info_cuda(int gpu_idx) {
|
||||
|
||||
if(gpu_idx == 0) {
|
||||
printf("\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if(num_gpus <= 0) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __CUDA_GPU__
|
||||
|
||||
#include "../common/gpu.hpp"
|
||||
#define CUDA_DRIVER_START_WARNING "Waiting for CUDA driver to start..."
|
||||
|
||||
struct gpu_info* get_gpu_info_cuda(int gpu_idx);
|
||||
bool print_gpu_cuda(struct gpu_info* gpu);
|
||||
|
||||
Reference in New Issue
Block a user