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