diff --git a/Makefile b/Makefile index 753c815..8d54ed0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.7 +# Generated by "Unix Makefiles" Generator, CMake Version 3.12 # Default target executed when no arguments are given to make. default_target: all @@ -48,10 +48,10 @@ RM = /usr/bin/cmake -E remove -f EQUALS = = # The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/ben/Desktop/universal-system-monitor +CMAKE_SOURCE_DIR = /home/ben/Programming/resource-monitor # The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/ben/Desktop/universal-system-monitor +CMAKE_BINARY_DIR = /home/ben/Programming/resource-monitor #============================================================================= # Targets provided globally by CMake. @@ -80,9 +80,9 @@ edit_cache/fast: edit_cache # The main all target all: cmake_check_build_system - $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Desktop/universal-system-monitor/CMakeFiles /home/ben/Desktop/universal-system-monitor/CMakeFiles/progress.marks + $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/resource-monitor/CMakeFiles /home/ben/Programming/resource-monitor/CMakeFiles/progress.marks $(MAKE) -f CMakeFiles/Makefile2 all - $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Desktop/universal-system-monitor/CMakeFiles 0 + $(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/resource-monitor/CMakeFiles 0 .PHONY : all # The main clean target @@ -184,8 +184,8 @@ help: @echo "... clean" @echo "... depend" @echo "... rebuild_cache" - @echo "... edit_cache" @echo "... ./bin/resource-monitor" + @echo "... edit_cache" @echo "... platform/linux/monitoring/cpu.o" @echo "... platform/linux/monitoring/cpu.i" @echo "... platform/linux/monitoring/cpu.s" diff --git a/bin/resource-monitor b/bin/resource-monitor index 4abee26..f22857c 100755 Binary files a/bin/resource-monitor and b/bin/resource-monitor differ diff --git a/include/cpu.h b/include/cpu.h index 3601593..dc95b6d 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -1,9 +1,9 @@ #pragma once -#include -#include #include +#include #include +#include class CPU { public: diff --git a/include/memory.h b/include/memory.h index e69de29..835d8d3 100644 --- a/include/memory.h +++ b/include/memory.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include + +class Memory { +public: + Memory(); + + std::mutex Memory_Mutex; + + long double MEMORY_TOTAL_MB; + long double MEMORY_FREE_MB; + long double MEMORY_AVAILABLE_MB; + long double MEMORY_ACTIVE_MB; + long double MEMORY_INACTIVE_MB; + + int UPDATE_INTERVAL; // s + + void START_MEMORY_POLLING(); + static void MEMORY_POLL(Memory* mem); + void END_MEMORY_POLLING(); + + virtual ~Memory(); +private: + std::thread* m_pollThread; + bool m_isPolling; +}; + +static Memory* Memory_Instance; diff --git a/platform/linux/monitoring/cpu.cpp b/platform/linux/monitoring/cpu.cpp index 412a98b..fe05dbf 100644 --- a/platform/linux/monitoring/cpu.cpp +++ b/platform/linux/monitoring/cpu.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -35,12 +36,16 @@ void CPU::CPU_POLL(CPU* cpu) { cpu->CPU_Mutex.unlock(); // READ TOTAL CPU + std::vector ProcStatLines; unsigned long long luser, nice, system, idle, iowait, irq, softirq = 0; - FILE* ProcStatCPU = fopen("/proc/stat", "r"); - fscanf(ProcStatCPU, "cpu %llu %llu %llu %llu %llu %llu %llu", &luser, + + std::ifstream ProcStatFile("/proc/stat"); + for (std::string str; std::getline(ProcStatFile, str); ) + ProcStatLines.push_back(str); + + sscanf(ProcStatLines[0].c_str(), "cpu %llu %llu %llu %llu %llu %llu %llu", &luser, &nice, &system, &idle, &iowait, &irq, &softirq); - fclose(ProcStatCPU); cpu->CPU_Mutex.lock(); @@ -54,15 +59,12 @@ void CPU::CPU_POLL(CPU* cpu) { for (unsigned int thread = 0; thread < cpu->CPU_HARDWARE_THREADS; thread++) { // READ TOTAL THREAD CPU + unsigned int currentThread = thread + 1; unsigned long long tluser, tnice, tsystem, tidle, tiowait, - tirq, tsoftirq = 0; - FILE* ProcStatCPUThread = fopen("/proc/stat", "r"); - fscanf(ProcStatCPUThread, "%*s %llu %llu %llu %llu %llu %llu %llu", - &tluser, &tnice, &tsystem, &tidle, &tiowait, &tirq, &tsoftirq); // WONT WORK - fclose(ProcStatCPUThread); + tirq, tsoftirq = 0;[[]] - std::cout << tluser << " " << tnice << " " << tsystem << " " << tidle - << " " << tiowait << " " << tirq << " " << tsoftirq << std::endl; + sscanf(ProcStatLines[currentThread].c_str(), "%*s %llu %llu %llu %llu %llu %llu %llu", + &tluser, &tnice, &tsystem, &tidle, &tiowait, &tirq, &tsoftirq); cpu->CPU_Mutex.lock(); diff --git a/platform/linux/monitoring/memory.cpp b/platform/linux/monitoring/memory.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp index ad850a7..92298a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,20 @@ #include #include +#include #include int main(int argc, char** argv) { CPU* cpu = new CPU(); CPU_Instance = cpu; + // Memory* mem = new Memory(); + // Memory_Instance = mem; + cpu->START_CPU_POLLING(); + // mem->START_MEMORY_POLLING(); while(1) { sleep(1); - // 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->CPU_HARDWARE_THREADS; thread++) { std::cout << "CORE " << thread << " USAGE: " << cpu->CPU_PERCENT(thread) << std::endl; }