mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-26 00:10:38 +01:00
[v0.98][Refactoring] Use int for peak performance, which makes code cleaner
This commit is contained in:
@@ -151,24 +151,25 @@ char* get_str_freq(struct frequency* freq) {
|
||||
return string;
|
||||
}
|
||||
|
||||
char* get_str_peak_performance(double flops, bool valid_flops) {
|
||||
char* get_str_peak_performance(int64_t flops) {
|
||||
char* str;
|
||||
|
||||
if(!valid_flops) {
|
||||
if(flops == -1) {
|
||||
str = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
|
||||
strncpy(str, STRING_UNKNOWN, strlen(STRING_UNKNOWN) + 1);
|
||||
}
|
||||
|
||||
// 7 for digits (e.g, XXXX.XX), 7 for XFLOP/s
|
||||
double flopsd = (double) flops;
|
||||
uint32_t max_size = 7+1+7+1;
|
||||
str = ecalloc(max_size, sizeof(char));
|
||||
|
||||
if(flops >= (double)1000000000000.0)
|
||||
snprintf(str, max_size, "%.2f TFLOP/s", flops/1000000000000);
|
||||
else if(flops >= 1000000000.0)
|
||||
snprintf(str, max_size, "%.2f GFLOP/s", flops/1000000000);
|
||||
if(flopsd >= (double)1000000000000.0)
|
||||
snprintf(str, max_size, "%.2f TFLOP/s", flopsd/1000000000000);
|
||||
else if(flopsd >= 1000000000.0)
|
||||
snprintf(str, max_size, "%.2f GFLOP/s", flopsd/1000000000);
|
||||
else
|
||||
snprintf(str, max_size, "%.2f MFLOP/s", flops/1000000);
|
||||
snprintf(str, max_size, "%.2f MFLOP/s", flopsd/1000000);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ struct cpuInfo {
|
||||
struct cache* cach;
|
||||
struct topology* topo;
|
||||
struct features* feat;
|
||||
int64_t peak_performance;
|
||||
|
||||
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
||||
// CPU name from model
|
||||
@@ -161,7 +162,7 @@ char* get_str_l1d(struct cache* cach);
|
||||
char* get_str_l2(struct cache* cach);
|
||||
char* get_str_l3(struct cache* cach);
|
||||
char* get_str_freq(struct frequency* freq);
|
||||
char* get_str_peak_performance(double flops, bool valid_pp);
|
||||
char* get_str_peak_performance(int64_t flops);
|
||||
|
||||
void init_topology_struct(struct topology* topo, struct cache* cach);
|
||||
void init_cache_struct(struct cache* cach);
|
||||
|
||||
@@ -446,9 +446,6 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
||||
if(art == NULL)
|
||||
return false;
|
||||
|
||||
double flops;
|
||||
bool valid_pp = get_peak_performance(cpu, cpu->topo, get_freq(cpu->freq), &flops);
|
||||
|
||||
char* uarch = get_str_uarch(cpu);
|
||||
char* manufacturing_process = get_str_process(cpu);
|
||||
char* sockets = get_str_sockets(cpu->topo);
|
||||
@@ -463,7 +460,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
||||
char* l1d = get_str_l1d(cpu->cach);
|
||||
char* l2 = get_str_l2(cpu->cach);
|
||||
char* l3 = get_str_l3(cpu->cach);
|
||||
char* pp = get_str_peak_performance(flops, valid_pp);
|
||||
char* pp = get_str_peak_performance(cpu->peak_performance);
|
||||
|
||||
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
|
||||
if(cpu->hv->present) {
|
||||
@@ -570,9 +567,6 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
||||
if(art == NULL)
|
||||
return false;
|
||||
|
||||
double flops;
|
||||
bool valid_pp = get_peak_performance(cpu, cpu->topo, get_freq(cpu->freq), &flops);
|
||||
|
||||
char* uarch = get_str_uarch(cpu);
|
||||
char* manufacturing_process = get_str_process(cpu);
|
||||
char* sockets = get_str_sockets(cpu->topo);
|
||||
@@ -586,7 +580,7 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
||||
char* l1d = get_str_l1d(cpu->cach);
|
||||
char* l2 = get_str_l2(cpu->cach);
|
||||
char* l3 = get_str_l3(cpu->cach);
|
||||
char* pp = get_str_peak_performance(flops, valid_pp);
|
||||
char* pp = get_str_peak_performance(cpu->peak_performance);
|
||||
|
||||
if(cpu_name != NULL) {
|
||||
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
|
||||
@@ -792,9 +786,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
||||
}
|
||||
}
|
||||
}
|
||||
double flops;
|
||||
bool valid_pp = get_peak_performance(cpu, &flops);
|
||||
char* pp = get_str_peak_performance(flops, valid_pp);
|
||||
char* pp = get_str_peak_performance(cpu->peak_performance);
|
||||
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
||||
|
||||
if(art->n_attributes_set > NUMBER_OF_LINES) {
|
||||
|
||||
Reference in New Issue
Block a user