temp-monitor/include/cpu_monitor.h
2026-03-11 17:02:13 +01:00

45 lines
957 B
C++

#ifndef CPU_MONITOR_H
#define CPU_MONITOR_H
#include <string>
#include <vector>
#include <cstdint>
struct CpuStats {
double totalUsagePercent; // Overall CPU usage (0-100%)
std::vector<double> coreUsagePercent; // Per-core usage
};
class CpuMonitor {
public:
explicit CpuMonitor();
// Get overall CPU usage and per-core usage
CpuStats getCpuUsage();
private:
struct CpuTick {
int64_t user;
int64_t nice;
int64_t system;
int64_t idle;
int64_t iowait;
int64_t irq;
int64_t softirq;
};
struct CpuCoreState {
CpuTick previous;
CpuTick current;
bool initialized;
};
std::vector<CpuCoreState> coreStates; // Index 0 is aggregate, 1+ are cores
std::vector<CpuTick> readCpuStats();
double calculateUsagePercent(const CpuTick &prev, const CpuTick &curr);
int getNumberOfCores();
};
#endif // CPU_MONITOR_H