mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Fix typo in frequency. Little refactoring and simple unity change
This commit is contained in:
8
01h.c
8
01h.c
@@ -218,17 +218,17 @@ char* getString_FMA(struct cpuInfo* cpu) {
|
||||
char* getString_AES(struct cpuInfo* cpu) {
|
||||
char* string = malloc(sizeof(char)*3+1);
|
||||
if(cpu->AES == BOOLEAN_TRUE)
|
||||
snprintf(string,3+1,"Yes");
|
||||
snprintf(string,3+1,STRING_YES);
|
||||
else
|
||||
snprintf(string,2+1,"No");
|
||||
snprintf(string,2+1,STRING_NO);
|
||||
return string;
|
||||
}
|
||||
|
||||
char* getString_SHA(struct cpuInfo* cpu) {
|
||||
char* string = malloc(sizeof(char)*3+1);
|
||||
if(cpu->SHA == BOOLEAN_TRUE)
|
||||
snprintf(string,3+1,"Yes");
|
||||
snprintf(string,3+1,STRING_YES);
|
||||
else
|
||||
snprintf(string,2+1,"No");
|
||||
snprintf(string,2+1,STRING_NO);
|
||||
return string;
|
||||
}
|
||||
|
||||
2
01h.h
2
01h.h
@@ -1,6 +1,8 @@
|
||||
#ifndef __01h__
|
||||
#define __01h__
|
||||
|
||||
#define STRING_YES "Yes"
|
||||
#define STRING_NO "No"
|
||||
struct cpuInfo;
|
||||
|
||||
struct cpuInfo* getCPUInfo();
|
||||
|
||||
2
main.c
2
main.c
@@ -10,7 +10,7 @@ SAMPLE OUTPUT
|
||||
|
||||
Name: Intel Core i7-4790K
|
||||
Arch: 64 Bits
|
||||
Frecuency: 4.0 GHz
|
||||
Frequency: 4.0 GHz
|
||||
NºCores: 4 cores(8 threads)
|
||||
AXV: AVX,AVX2
|
||||
SSE: SSE,SSE2,SSE4.1,SSE4.2
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#define TITLE_NAME "Name: "
|
||||
#define TITLE_ARCH "Arch: "
|
||||
#define TITLE_FREQUENCY "Frecuency: "
|
||||
#define TITLE_FREQUENCY "Frequency: "
|
||||
#define TITLE_NCORES "N.Cores: "
|
||||
#define TITLE_AVX "AVX: "
|
||||
#define TITLE_SSE "SSE: "
|
||||
|
||||
54
udev.c
54
udev.c
@@ -61,19 +61,28 @@ int getCache(char* path) {
|
||||
int fd = fileno(file);
|
||||
int bytes_read = 0;
|
||||
int offset = 0;
|
||||
int block = 1;
|
||||
int block = DEFAULT_BLOCK_SIZE;
|
||||
char* buf = malloc(sizeof(char)*DEFAULT_FILE_SIZE);
|
||||
memset(buf, 0, sizeof(char)*DEFAULT_FILE_SIZE);
|
||||
|
||||
while ( (bytes_read = read(fd, buf+offset, block)) > 0 ) {
|
||||
do {
|
||||
bytes_read = read(fd, buf+offset, block);
|
||||
offset += bytes_read;
|
||||
}
|
||||
} while(bytes_read > 0);
|
||||
|
||||
//Move size from kb to bytes
|
||||
int ret = getSize(buf,offset)*1024;
|
||||
free(buf);
|
||||
fclose(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***
|
||||
|
||||
Returns CPU frequency in Hz
|
||||
|
||||
***/
|
||||
|
||||
int getFrequency(char* path) {
|
||||
FILE *file = fopen(path, "r");
|
||||
|
||||
@@ -100,7 +109,7 @@ int getFrequency(char* path) {
|
||||
printf("error in getFrequency\n");
|
||||
return NO_CACHE;
|
||||
}
|
||||
return ret/1000;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*** GET_STRING ***/
|
||||
@@ -110,21 +119,21 @@ char* getString_L1(struct cache* cach) {
|
||||
//and 14 for '(Instructions)'
|
||||
int size = (2*(2+2)+6+14+1);
|
||||
char* string = malloc(sizeof(char)*size);
|
||||
snprintf(string,size,"%dKB(Data)%dKB(Instructions)",cach->L1d/1024,cach->L1i/1024);
|
||||
snprintf(string,size,"%d"STRING_KILOBYTES"(Data)%d"STRING_KILOBYTES"(Instructions)",cach->L1d/1024,cach->L1i/1024);
|
||||
return string;
|
||||
}
|
||||
|
||||
char* getString_L2(struct cache* cach) {
|
||||
if(cach->L2 == NO_CACHE) {
|
||||
char* string = malloc(sizeof(char)*5);
|
||||
snprintf(string,5,"None");
|
||||
snprintf(string,5,STRING_NONE);
|
||||
return string;
|
||||
}
|
||||
else {
|
||||
//Max 4 digits and 2 for 'KB'
|
||||
int size = (4+2+1);
|
||||
char* string = malloc(sizeof(char)*size);
|
||||
snprintf(string,size,"%dKB",cach->L2/1024);
|
||||
snprintf(string,size,"%d"STRING_KILOBYTES,cach->L2/1024);
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -132,27 +141,30 @@ char* getString_L2(struct cache* cach) {
|
||||
char* getString_L3(struct cache* cach) {
|
||||
if(cach->L3 == NO_CACHE) {
|
||||
char* string = malloc(sizeof(char)*5);
|
||||
snprintf(string,5,"None");
|
||||
snprintf(string,5,STRING_NONE);
|
||||
return string;
|
||||
}
|
||||
else {
|
||||
//Max 4 digits and 2 for 'KB'
|
||||
int size = (4+2+1);
|
||||
char* string = malloc(sizeof(char)*size);
|
||||
snprintf(string,size,"%dKB",cach->L3/1024);
|
||||
snprintf(string,size,"%d"STRING_KILOBYTES,cach->L3/1024);
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
char* getString_MaxFrequency(struct frequency* freq) {
|
||||
//Max 4 digits and 3 for 'MHz' plus 1 for '\0'
|
||||
//Max 3 digits and 3 for '(M/G)Hz' plus 1 for '\0'
|
||||
int size = (4+3+1);
|
||||
char* string = malloc(sizeof(char)*size);
|
||||
snprintf(string,size,"%dMHz",freq->max);
|
||||
if(freq->max >= 1000000)
|
||||
snprintf(string,size,"%.2f"STRING_GIGAHERZ,(float)(freq->max)/1000000);
|
||||
else
|
||||
snprintf(string,size,"%.2f"STRING_MEGAHERZ,(float)(freq->max)/100000);
|
||||
return string;
|
||||
}
|
||||
|
||||
/*** CREATE DEBUGING AND FREES ***/
|
||||
/*** CREATES AND FREES ***/
|
||||
|
||||
struct cache* new_cache(struct cache* cach) {
|
||||
cach = malloc(sizeof(struct cache));
|
||||
@@ -170,6 +182,16 @@ struct frequency* new_frequency(struct frequency* freq) {
|
||||
return freq;
|
||||
}
|
||||
|
||||
void freeCache(struct cache* cach) {
|
||||
free(cach);
|
||||
}
|
||||
|
||||
void freeFrequency(struct frequency* freq) {
|
||||
free(freq);
|
||||
}
|
||||
|
||||
/*** DEBUGING ***/
|
||||
|
||||
void debugCache(struct cache* cach) {
|
||||
printf("L1i=%dB\n",cach->L1i);
|
||||
printf("L1d=%dB\n",cach->L1d);
|
||||
@@ -181,11 +203,3 @@ void debugFrequency(struct frequency* freq) {
|
||||
printf("max f=%dMhz\n",freq->max);
|
||||
printf("min f=%dMhz\n",freq->min);
|
||||
}
|
||||
|
||||
void freeCache(struct cache* cach) {
|
||||
free(cach);
|
||||
}
|
||||
|
||||
void freeFrequency(struct frequency* freq) {
|
||||
free(freq);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user