diff --git a/bin/resource-monitor b/bin/resource-monitor index a3d3a9e..fa59323 100755 Binary files a/bin/resource-monitor and b/bin/resource-monitor differ diff --git a/platform/linux/monitoring/cpu.cpp b/platform/linux/monitoring/cpu.cpp index db1ad6b..28c442e 100644 --- a/platform/linux/monitoring/cpu.cpp +++ b/platform/linux/monitoring/cpu.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -95,15 +96,24 @@ void CPU::CPU_POLL(CPU* cpu) { std::vector lscpu = execcommand("lscpu"); for (unsigned int i = 0; i < lscpu.size(); i++) { + std::regex architecture("Architecture.*?((?:[a-z][a-z0-9_]*))"); + std::regex maxMHz ("CPU max MHz.*?((?:[0-9].*))"); + std::regex minMHz ("CPU min MHz.*?((?:[0-9].*))"); + std::regex MHz ("CPU MHz.*?((?:[0-9].*))"); + std::smatch m; + cpu->CPU_Mutex.lock(); - if (lscpu[i].find("Architecture:")) { - std::string architecture(10, ' '); - sscanf(lscpu[i].c_str(), "Architecture: %*s", &architecture[0], architecture.size()); - cpu->cpuStat->ARCHITECTURE = architecture; - std::cout << architecture; - } - + if (std::regex_search(lscpu[i], m, architecture)) { + cpu->cpuStat->ARCHITECTURE = m[1].str(); + } else if (std::regex_search(lscpu[i], m, maxMHz)) { + cpu->cpuStat->MAX_FREQ = std::stod(m[1].str()); + } else if (std::regex_search(lscpu[i], m, minMHz)) { + cpu->cpuStat->MIN_FREQ = std::stod(m[1].str()); + } else if (std::regex_search(lscpu[i], m, MHz)) { + cpu->cpuStat->FREQ = std::stod(m[1].str()); + } + cpu->CPU_Mutex.unlock(); } diff --git a/src/main.cpp b/src/main.cpp index 8103a12..4258ba9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,5 +21,6 @@ int main(int argc, char** argv) { for (unsigned int thread = 0; thread <= cpu->CPU_HARDWARE_THREADS; thread++) { std::cout << "CORE " << thread << " USAGE: " << cpu->CPU_PERCENT(thread) << std::endl; } + std::cout << "CPU FREQUENCY: " << cpu->cpuStat->FREQ << "MHz" << std::endl; } }