diff --git a/.gitignore b/.gitignore index 5ca868f..93de002 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vscode glade/test_window.glade~ output.log main.o diff --git a/commands/help.c b/commands/help.c index c9ee0d9..a156ea3 100644 --- a/commands/help.c +++ b/commands/help.c @@ -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"); } \ No newline at end of file diff --git a/makefile b/makefile index bdb00b1..79e1d0f 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/utils/os_info.c b/utils/os_info.c index 7c52133..1386377 100644 --- a/utils/os_info.c +++ b/utils/os_info.c @@ -3,9 +3,80 @@ #include #include #include +#include #include "os_info.h" #include "logger.h" +#include + + +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); } diff --git a/utils/os_info.h b/utils/os_info.h index a9bf644..452ba8d 100644 --- a/utils/os_info.h +++ b/utils/os_info.h @@ -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();