[v0.86][OPTIONS] Replace levels option with debug option, which does the same on x86, but also exists on ARM, which prints MIDR registers (need work to be properly implemented)

This commit is contained in:
Dr-Noob
2020-11-18 23:41:42 +01:00
parent c44a646cd1
commit 7d707916fb
9 changed files with 46 additions and 40 deletions

View File

@@ -195,6 +195,22 @@ char* get_soc_name(struct cpuInfo* cpu) {
return cpu->soc_name; return cpu->soc_name;
} }
//TODO: Fix wrong implementation
void print_debug(struct cpuInfo* cpu) {
int ncores = get_ncores_from_cpuinfo();
if(ncores >= 10) {
for(int i=0; i < ncores; i++) {
printf("[Core %02d] 0x%.8X\n", i, cpu->midr);
}
}
else {
for(int i=0; i < ncores; i++) {
printf("[Core %d] 0x%.8X\n", i, cpu->midr);
}
}
}
void free_topo_struct(struct topology* topo) { void free_topo_struct(struct topology* topo) {
free(topo); free(topo);
} }

View File

@@ -13,6 +13,7 @@ char* get_soc_name(struct cpuInfo* cpu);
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket); char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket);
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq); char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
void print_debug(struct cpuInfo* cpu);
void free_topo_struct(struct topology* topo); void free_topo_struct(struct topology* topo);
// Code taken from cpuinfo (https://github.com/pytorch/cpuinfo/blob/master/src/arm/midr.h) // Code taken from cpuinfo (https://github.com/pytorch/cpuinfo/blob/master/src/arm/midr.h)

View File

@@ -21,15 +21,13 @@ enum {
ARG_CHAR_STYLE, ARG_CHAR_STYLE,
ARG_CHAR_COLOR, ARG_CHAR_COLOR,
ARG_CHAR_HELP, ARG_CHAR_HELP,
#ifdef ARCH_X86 ARG_CHAR_DEBUG,
ARG_CHAR_LEVELS,
#endif
ARG_CHAR_VERBOSE, ARG_CHAR_VERBOSE,
ARG_CHAR_VERSION ARG_CHAR_VERSION
}; };
struct args_struct { struct args_struct {
bool levels_flag; bool debug_flag;
bool help_flag; bool help_flag;
bool verbose_flag; bool verbose_flag;
bool version_flag; bool version_flag;
@@ -55,8 +53,8 @@ bool show_version() {
return args.version_flag; return args.version_flag;
} }
bool show_levels() { bool show_debug() {
return args.levels_flag; return args.debug_flag;
} }
bool verbose_enabled() { bool verbose_enabled() {
@@ -166,7 +164,7 @@ bool parse_args(int argc, char* argv[]) {
opterr = 0; opterr = 0;
bool color_flag = false; bool color_flag = false;
args.levels_flag = false; args.debug_flag = false;
args.verbose_flag = false; args.verbose_flag = false;
args.help_flag = false; args.help_flag = false;
args.style = STYLE_EMPTY; args.style = STYLE_EMPTY;
@@ -176,9 +174,7 @@ bool parse_args(int argc, char* argv[]) {
{"style", required_argument, 0, ARG_CHAR_STYLE }, {"style", required_argument, 0, ARG_CHAR_STYLE },
{"color", required_argument, 0, ARG_CHAR_COLOR }, {"color", required_argument, 0, ARG_CHAR_COLOR },
{"help", no_argument, 0, ARG_CHAR_HELP }, {"help", no_argument, 0, ARG_CHAR_HELP },
#ifdef ARCH_X86 {"debug", no_argument, 0, ARG_CHAR_DEBUG },
{"levels", no_argument, 0, ARG_CHAR_LEVELS },
#endif
{"verbose", no_argument, 0, ARG_CHAR_VERBOSE }, {"verbose", no_argument, 0, ARG_CHAR_VERBOSE },
{"version", no_argument, 0, ARG_CHAR_VERSION }, {"version", no_argument, 0, ARG_CHAR_VERSION },
{0, 0, 0, 0} {0, 0, 0, 0}
@@ -223,15 +219,13 @@ bool parse_args(int argc, char* argv[]) {
} }
args.verbose_flag = true; args.verbose_flag = true;
} }
#ifdef ARCH_X86 else if(c == ARG_CHAR_DEBUG) {
else if(c == ARG_CHAR_LEVELS) { if(args.debug_flag) {
if(args.levels_flag) { printErr("Debug option specified more than once");
printErr("Levels option specified more than once");
return false; return false;
} }
args.levels_flag = true; args.debug_flag = true;
} }
#endif
else if (c == ARG_CHAR_VERSION) { else if (c == ARG_CHAR_VERSION) {
if(args.version_flag) { if(args.version_flag) {
printErr("Version option specified more than once"); printErr("Version option specified more than once");

View File

@@ -30,7 +30,7 @@ enum {
bool parse_args(int argc, char* argv[]); bool parse_args(int argc, char* argv[]);
bool show_help(); bool show_help();
bool show_levels(); bool show_debug();
bool show_version(); bool show_version();
bool verbose_enabled(); bool verbose_enabled();
void free_colors_struct(struct colors* cs); void free_colors_struct(struct colors* cs);

View File

@@ -53,7 +53,7 @@ void printBug(const char *fmt, ...) {
vsnprintf(buffer,buffer_size, fmt, args); vsnprintf(buffer,buffer_size, fmt, args);
va_end(args); va_end(args);
fprintf(stderr,RED "[ERROR]: "RESET "%s\n",buffer); fprintf(stderr,RED "[ERROR]: "RESET "%s\n",buffer);
fprintf(stderr,"Please, create a new issue with this error message and your CPU model in https://github.com/Dr-Noob/cpufetch/issues\n"); fprintf(stderr,"Please, create a new issue with this error message the output of 'cpufetch --debug' in https://github.com/Dr-Noob/cpufetch/issues\n");
} }
void set_log_level(bool verbose) { void set_log_level(bool verbose) {

View File

@@ -8,19 +8,15 @@
#ifdef ARCH_X86 #ifdef ARCH_X86
static const char* ARCH_STR = "x86_64 build"; static const char* ARCH_STR = "x86_64 build";
#include "../x86/cpuid.h" #include "../x86/cpuid.h"
#else #elif ARCH_ARM
static const char* ARCH_STR = "ARM build"; static const char* ARCH_STR = "ARM build";
#include "../arm/midr.h" #include "../arm/midr.h"
#endif #endif
static const char* VERSION = "0.85"; static const char* VERSION = "0.86";
void print_help(char *argv[]) { void print_help(char *argv[]) {
#ifdef ARCH_X86 printf("Usage: %s [--version] [--help] [--debug] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n", argv[0]);
printf("Usage: %s [--version] [--help] [--levels] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n", argv[0]);
#else
printf("Usage: %s [--version] [--help] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n", argv[0]);
#endif
printf("Options: \n\ printf("Options: \n\
--color Set the color scheme. By default, cpufetch uses the system color scheme. This option \n\ --color Set the color scheme. By default, cpufetch uses the system color scheme. This option \n\
@@ -38,7 +34,9 @@ void print_help(char *argv[]) {
* \"legacy\": Fallback style for terminals that does not support colors \n\n"); * \"legacy\": Fallback style for terminals that does not support colors \n\n");
#ifdef ARCH_X86 #ifdef ARCH_X86
printf(" --levels Prints CPU model and cpuid levels (debug purposes)\n\n"); printf(" --debug Prints CPU model and cpuid levels (debug purposes)\n\n");
#elif ARCH_ARM
printf(" --debug Prints main ID register values for all cores (debug purposes)\n\n");
#endif #endif
printf(" --verbose Prints extra information (if available) about how cpufetch tried fetching information\n\n\ printf(" --verbose Prints extra information (if available) about how cpufetch tried fetching information\n\n\
@@ -77,13 +75,11 @@ int main(int argc, char* argv[]) {
if(cpu == NULL) if(cpu == NULL)
return EXIT_FAILURE; return EXIT_FAILURE;
#ifdef ARCH_X86 if(show_debug()) {
if(show_levels()) {
print_version(); print_version();
print_levels(cpu); print_debug(cpu);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
#endif
struct frequency* freq = get_frequency_info(cpu); struct frequency* freq = get_frequency_info(cpu);
if(freq == NULL) if(freq == NULL)

View File

@@ -526,13 +526,3 @@ bool print_cpufetch(struct cpuInfo* cpu, struct cache* cach, struct frequency* f
return true; return true;
} }
#ifdef ARCH_X86
void print_levels(struct cpuInfo* cpu) {
printf("%s\n", cpu->cpu_name);
printf("- Max standart level: 0x%.8X\n", cpu->maxLevels);
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
free_cpuinfo_struct(cpu);
}
#endif

View File

@@ -828,6 +828,14 @@ char* get_str_fma(struct cpuInfo* cpu) {
/*** DEBUG ***/ /*** DEBUG ***/
void print_debug(struct cpuInfo* cpu) {
printf("%s\n", cpu->cpu_name);
printf("- Max standart level: 0x%.8X\n", cpu->maxLevels);
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
free_cpuinfo_struct(cpu);
}
void debug_cpu_info(struct cpuInfo* cpu) { void debug_cpu_info(struct cpuInfo* cpu) {
printf("AVX=%s\n", cpu->AVX ? "true" : "false"); printf("AVX=%s\n", cpu->AVX ? "true" : "false");
printf("AVX2=%s\n", cpu->AVX2 ? "true" : "false"); printf("AVX2=%s\n", cpu->AVX2 ? "true" : "false");

View File

@@ -14,6 +14,7 @@ char* get_str_fma(struct cpuInfo* cpu);
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket); char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket);
char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq); char* get_str_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t freq);
void print_debug(struct cpuInfo* cpu);
void debug_cpu_info(struct cpuInfo* cpu); void debug_cpu_info(struct cpuInfo* cpu);
void debug_cache(struct cache* cach); void debug_cache(struct cache* cach);
void debug_frequency(struct frequency* freq); void debug_frequency(struct frequency* freq);