Need a C++ library for hardware information
This commit is contained in:
@@ -25,6 +25,7 @@ if (WIN32)
|
||||
file(GLOB_RECURSE PlatformDepSource
|
||||
${WinDep}/monitoring/*.cpp
|
||||
${WinDep}/ui/*.cpp
|
||||
${WinDep}/*.cpp
|
||||
)
|
||||
endif (WIN32)
|
||||
|
||||
@@ -32,6 +33,7 @@ if (UNIX)
|
||||
file(GLOB_RECURSE PlatformDepSource
|
||||
${LinuxDep}/monitoring/*.cpp
|
||||
${LinuxDep}/ui/*.cpp
|
||||
${LinuxDep}/*.cpp
|
||||
)
|
||||
endif (UNIX)
|
||||
|
||||
|
||||
3
SystemAPIDocs.md
Normal file
3
SystemAPIDocs.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Documentation
|
||||
|
||||
> NOTE: Instantating the System class without prior initialization of CPU and Memory will cause a segmentation fault
|
||||
Binary file not shown.
@@ -5,19 +5,4 @@
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::vector<std::string> execcommand(std::string command);
|
||||
|
||||
@@ -10,3 +10,14 @@ struct Sys {
|
||||
unsigned short CPU_CORES;
|
||||
|
||||
};
|
||||
|
||||
class System {
|
||||
public:
|
||||
System();
|
||||
Sys* getSystemSpec();
|
||||
virtual ~System();
|
||||
private:
|
||||
Sys* m_Sys;
|
||||
};
|
||||
|
||||
static System* System_Instance;
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
// #include <common.h>
|
||||
#include <common.h>
|
||||
|
||||
// #include <iostream>
|
||||
// #include <stdexcept>
|
||||
// #include <stdio.h>
|
||||
// #include <string>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
// std::vector<std::string> exec(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;
|
||||
// }
|
||||
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;
|
||||
}
|
||||
|
||||
23
platform/linux/monitoring/system.cpp
Normal file
23
platform/linux/monitoring/system.cpp
Normal 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() {
|
||||
|
||||
}
|
||||
23
src/main.cpp
23
src/main.cpp
@@ -1,26 +1,27 @@
|
||||
#include <sys.h>
|
||||
#include <memstat.h>
|
||||
#include <cpu.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
CPU* cpu = new CPU();
|
||||
CPU_Instance = cpu;
|
||||
CPU_Instance = new CPU();
|
||||
Memory_Instance = new Memory();
|
||||
System_Instance = new System();
|
||||
|
||||
Memory* mem = new Memory();
|
||||
Memory_Instance = mem;
|
||||
CPU_Instance->START_CPU_POLLING();
|
||||
Memory_Instance->START_MEMORY_POLLING();
|
||||
|
||||
cpu->START_CPU_POLLING();
|
||||
mem->START_MEMORY_POLLING();
|
||||
sleep(1);
|
||||
|
||||
std::cout << std::endl;
|
||||
Sys* sys = System_Instance->getSystemSpec();
|
||||
|
||||
while(1) {
|
||||
sleep(1);
|
||||
std::cout << std::endl;
|
||||
for (unsigned int thread = 0; thread <= cpu->CPU_HARDWARE_THREADS; thread++) {
|
||||
std::cout << "CORE " << thread << " USAGE: " << cpu->CPU_PERCENT(thread) << std::endl;
|
||||
for (unsigned int thread = 0; thread <= CPU_Instance->CPU_HARDWARE_THREADS; thread++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user