Added some methods to get some CPU Informations

This commit is contained in:
netbenixcn 2020-06-03 08:51:12 +02:00
parent c55e7551b2
commit e9b8368830
5 changed files with 85 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.vscode
glade/test_window.glade~
output.log
main.o

View file

@ -9,5 +9,5 @@ void outputHelp(){
printf("--help : this help page\n");
printf("--gtk-test : opens the gtk test\n");
printf("--sql-test : make a test connection to a mysql server\n");
printf("--os-info : shows your os informations\n");
printf("--os-info : shows informations about your os\n");
}

View file

@ -1,5 +1,5 @@
CC= gcc
ARGS= -export-dynamic
ARGS= -export-dynamic -ansi -std=gnu99
CFLAGS= $(shell pkg-config --cflags gtk+-3.0) -I/usr/include/mysql
LDLIBS= $(shell pkg-config --libs gtk+-3.0) -L/usr/lib/mysql -lmysqlclient
OBJ= main.o logo.o logger.o help.o os_info.o gtk_test.o sql_test.o
@ -15,7 +15,7 @@ logger.o: utils/logger.c
help.o: commands/help.c
$(CC) $(CFLAGS) -c commands/help.c
os_info.o: utils/os_info.c
$(CC) $(CFLAGS) -c utils/os_info.c
$(CC) $(CFLAGS) $(ARGS) -c utils/os_info.c
gtk_test.o: commands/gtk_test.c
$(CC) $(CFLAGS) -c commands/gtk_test.c
sql_test.o: commands/sql_test.c

View file

@ -3,9 +3,80 @@
#include <unistd.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#include "os_info.h"
#include "logger.h"
#include <cpuid.h>
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
unsigned int *ecx, unsigned int *edx){
#ifndef __GNUC__
#define __asm__ asm
#endif
asm volatile ("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "0" (*eax), "2" (*ecx));
}
unsigned int getCPUStepping(){
unsigned eax,ebx,ecx,edx;
unsigned int stepping;
eax=1;
native_cpuid(&eax, &ebx, &ecx, &edx);
stepping = (eax >> 0) & 0xF;
return stepping;
}
unsigned int getCPUFamily(){
unsigned eax,ebx,ecx,edx;
unsigned int family;
eax = 1;
native_cpuid(&eax, &ebx, &ecx, &edx);
family = (eax >> 8) & 0xF;
return family;
}
char* getCPUType(){
unsigned eax,ebx,ecx,edx;
unsigned int type_id;
char* type;
type = malloc(sizeof(char) * 40);
eax = 1;
native_cpuid(&eax, &ebx, &ecx, &edx);
type_id = (eax >> 12) & 0xF;
if(type_id == 00){
strcpy(type, "Original OEM Processor");
}else if(type_id == 01){
strcpy(type, "Intel Overdrive Processor");
}else if(type_id == 10){
strcpy(type, "Dual processor");
}else{
strcpy(type, "Reserved value");
}
return type;
}
double getCPUClockSpeed(){
clock_t start, end;
double tmp;
start = clock();
for(int i = 0; i < 10000; i++){
tmp = i * i /2;
}
end = clock();
return ((double) (end-start)) / CLOCKS_PER_SEC;
}
char* getOS(){
char *os;
@ -13,7 +84,7 @@ char* getOS(){
#ifdef linux
strcpy(os, "Linux");
#endif
return os;
}
@ -33,6 +104,10 @@ char* getArch(){
void print_Specs(){
printf("OS: %s\n", getOS());
printf("Architecture: %s\n", getArch());
printf("CPU Stepping: %u\n", getCPUStepping());
printf("CPU Family: %u\n", getCPUFamily());
printf("CPU Type: %s\n", getCPUType());
printf("CPU Clock: %d\n", getCPUClockSpeed());
free(NULL);
}

View file

@ -1,6 +1,11 @@
#ifndef _OS_INFO_H_
#define _OS_INFO_H_
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx);
unsigned int getCPUStepping();
unsigned int getCPUFamily();
double getCPUClockSpeed();
char* getCPUType();
char* getOS();
char* getArch();
void print_Specs();