gonna redo CPUinfo class with workers and structs, started that

This commit is contained in:
Ben
2018-12-11 14:30:13 +00:00
parent 914a3457b5
commit 09f266a694
7 changed files with 65 additions and 2 deletions

Binary file not shown.

22
include/common.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include <vector>
#include <string>
#include <iostream>
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;
}

View File

View File

@@ -0,0 +1,12 @@
#pragma once
#include <cpu.h>
#include <temp.h>
#include <gpu.h>
#include <memstat.h>
struct Sys {
unsigned long long SYSTEM_UPTIME;
unsigned short CPU_CORES;
};

2
include/temp.h Normal file
View File

@@ -0,0 +1,2 @@
#pragma once

22
platform/linux/common.cpp Normal file
View File

@@ -0,0 +1,22 @@
// #include <common.h>
// #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;
// }

View File

@@ -1,5 +1,5 @@
#include <cpu.h>
#include <memstat.h>
#include <sys.h>
#include <common.h>
#include <iostream>
#include <unistd.h>
@@ -14,6 +14,11 @@ int main(int argc, char** argv) {
cpu->START_CPU_POLLING();
mem->START_MEMORY_POLLING();
std::vector<std::string> lscpu = exec("lscpu");
for (unsigned int i = 0; i < lscpu.size(); i++) {
std::cout << lscpu[i] << std::endl;
}
while(1) {
sleep(1);
std::cout << std::endl;