Need a C++ library for hardware information

This commit is contained in:
Ben
2018-12-17 16:35:11 +00:00
parent 2183e5939f
commit 034214efde
10 changed files with 72 additions and 47 deletions

View File

@@ -25,6 +25,7 @@ if (WIN32)
file(GLOB_RECURSE PlatformDepSource file(GLOB_RECURSE PlatformDepSource
${WinDep}/monitoring/*.cpp ${WinDep}/monitoring/*.cpp
${WinDep}/ui/*.cpp ${WinDep}/ui/*.cpp
${WinDep}/*.cpp
) )
endif (WIN32) endif (WIN32)
@@ -32,6 +33,7 @@ if (UNIX)
file(GLOB_RECURSE PlatformDepSource file(GLOB_RECURSE PlatformDepSource
${LinuxDep}/monitoring/*.cpp ${LinuxDep}/monitoring/*.cpp
${LinuxDep}/ui/*.cpp ${LinuxDep}/ui/*.cpp
${LinuxDep}/*.cpp
) )
endif (UNIX) endif (UNIX)

3
SystemAPIDocs.md Normal file
View File

@@ -0,0 +1,3 @@
# Documentation
> NOTE: Instantating the System class without prior initialization of CPU and Memory will cause a segmentation fault

BIN
bin/core

Binary file not shown.

Binary file not shown.

View File

@@ -5,19 +5,4 @@
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
std::vector<std::string> execcommand(std::string command) { std::vector<std::string> execcommand(std::string command);
char buffer[128];
std::vector<std::string> result;
FILE* pipe = popen(command.c_str(), "r");
try {
while (fgets(buffer, sizeof buffer, pipe) != NULL) {
result.push_back(buffer);
}
} catch (...) {
pclose(pipe);
throw;
}
pclose(pipe);
return result;
}

View File

@@ -10,3 +10,14 @@ struct Sys {
unsigned short CPU_CORES; unsigned short CPU_CORES;
}; };
class System {
public:
System();
Sys* getSystemSpec();
virtual ~System();
private:
Sys* m_Sys;
};
static System* System_Instance;

View File

@@ -1,22 +1,22 @@
// #include <common.h> #include <common.h>
// #include <iostream> #include <iostream>
// #include <stdexcept> #include <stdexcept>
// #include <stdio.h> #include <stdio.h>
// #include <string> #include <string>
// std::vector<std::string> exec(std::string command) { std::vector<std::string> execcommand(std::string command) {
// char buffer[128]; char buffer[128];
// std::vector<std::string> result; std::vector<std::string> result;
// FILE* pipe = popen(command.c_str(), "r"); FILE* pipe = popen(command.c_str(), "r");
// try { try {
// while (fgets(buffer, sizeof buffer, pipe) != NULL) { while (fgets(buffer, sizeof buffer, pipe) != NULL) {
// result.push_back(buffer); result.push_back(buffer);
// } }
// } catch (...) { } catch (...) {
// pclose(pipe); pclose(pipe);
// throw; throw;
// } }
// pclose(pipe); pclose(pipe);
// return result; return result;
// } }

View File

@@ -0,0 +1,23 @@
#include <sys.h>
System::System() {
this->m_Sys = new Sys();
if (CPU_Instance = NULL) {
CPU_Instance = new CPU();
}
if (Memory_Instance == NULL) {
Memory_Instance = new Memory();
}
}
Sys* System::getSystemSpec() {
return m_Sys;
}
System::~System() {
}

View File

@@ -1,26 +1,27 @@
#include <sys.h> #include <sys.h>
#include <memstat.h>
#include <cpu.h>
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
int main(int argc, char** argv) { int main(int argc, char** argv) {
CPU* cpu = new CPU(); CPU_Instance = new CPU();
CPU_Instance = cpu; Memory_Instance = new Memory();
System_Instance = new System();
Memory* mem = new Memory(); CPU_Instance->START_CPU_POLLING();
Memory_Instance = mem; Memory_Instance->START_MEMORY_POLLING();
cpu->START_CPU_POLLING(); sleep(1);
mem->START_MEMORY_POLLING();
std::cout << std::endl;
Sys* sys = System_Instance->getSystemSpec();
while(1) { while(1) {
sleep(1); sleep(1);
std::cout << std::endl; std::cout << std::endl;
for (unsigned int thread = 0; thread <= cpu->CPU_HARDWARE_THREADS; thread++) { for (unsigned int thread = 0; thread <= CPU_Instance->CPU_HARDWARE_THREADS; thread++) {
std::cout << "CORE " << thread << " USAGE: " << cpu->CPU_PERCENT(thread) << std::endl; std::cout << "CORE " << thread << " USAGE: " << CPU_Instance->CPU_PERCENT(thread) << std::endl;
} }
std::cout << "CPU FREQUENCY: " << cpu->cpuStat->FREQ << "MHz" << std::endl; std::cout << "CPU FREQUENCY: " << CPU_Instance->cpuStat->FREQ << "MHz" << std::endl;
} }
} }