2020-07-06 17:31:40 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef MANGOHUD_CPU_H
|
|
|
|
#define MANGOHUD_CPU_H
|
|
|
|
|
2020-02-01 23:55:24 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <cstdint>
|
2020-03-14 20:59:43 +00:00
|
|
|
#include <cstdio>
|
2020-02-01 23:55:24 +00:00
|
|
|
|
|
|
|
typedef struct CPUData_ {
|
2020-03-13 14:35:11 +00:00
|
|
|
unsigned long long int totalTime;
|
|
|
|
unsigned long long int userTime;
|
|
|
|
unsigned long long int systemTime;
|
|
|
|
unsigned long long int systemAllTime;
|
|
|
|
unsigned long long int idleAllTime;
|
|
|
|
unsigned long long int idleTime;
|
|
|
|
unsigned long long int niceTime;
|
|
|
|
unsigned long long int ioWaitTime;
|
|
|
|
unsigned long long int irqTime;
|
|
|
|
unsigned long long int softIrqTime;
|
|
|
|
unsigned long long int stealTime;
|
|
|
|
unsigned long long int guestTime;
|
2020-02-01 23:55:24 +00:00
|
|
|
|
2020-03-13 14:35:11 +00:00
|
|
|
unsigned long long int totalPeriod;
|
|
|
|
unsigned long long int userPeriod;
|
|
|
|
unsigned long long int systemPeriod;
|
|
|
|
unsigned long long int systemAllPeriod;
|
|
|
|
unsigned long long int idleAllPeriod;
|
|
|
|
unsigned long long int idlePeriod;
|
|
|
|
unsigned long long int nicePeriod;
|
|
|
|
unsigned long long int ioWaitPeriod;
|
|
|
|
unsigned long long int irqPeriod;
|
|
|
|
unsigned long long int softIrqPeriod;
|
|
|
|
unsigned long long int stealPeriod;
|
|
|
|
unsigned long long int guestPeriod;
|
|
|
|
float percent;
|
|
|
|
int mhz;
|
|
|
|
int temp;
|
2020-02-01 23:55:24 +00:00
|
|
|
} CPUData;
|
|
|
|
|
|
|
|
class CPUStats
|
|
|
|
{
|
|
|
|
public:
|
2020-03-13 14:35:11 +00:00
|
|
|
CPUStats();
|
2020-03-14 20:59:43 +00:00
|
|
|
~CPUStats();
|
2020-03-13 14:35:11 +00:00
|
|
|
bool Init();
|
|
|
|
bool Updated()
|
|
|
|
{
|
|
|
|
return m_updatedCPUs;
|
|
|
|
}
|
2020-02-01 23:55:24 +00:00
|
|
|
|
2020-03-13 14:35:11 +00:00
|
|
|
bool UpdateCPUData();
|
|
|
|
bool UpdateCoreMhz();
|
|
|
|
bool UpdateCpuTemp();
|
|
|
|
bool GetCpuFile();
|
|
|
|
double GetCPUPeriod() { return m_cpuPeriod; }
|
2020-02-01 23:55:24 +00:00
|
|
|
|
2020-03-13 14:35:11 +00:00
|
|
|
const std::vector<CPUData>& GetCPUData() const {
|
|
|
|
return m_cpuData;
|
|
|
|
}
|
|
|
|
const CPUData& GetCPUDataTotal() const {
|
|
|
|
return m_cpuDataTotal;
|
|
|
|
}
|
2020-02-01 23:55:24 +00:00
|
|
|
private:
|
2020-03-13 14:35:11 +00:00
|
|
|
unsigned long long int m_boottime = 0;
|
|
|
|
std::vector<CPUData> m_cpuData;
|
|
|
|
CPUData m_cpuDataTotal {};
|
|
|
|
std::vector<int> m_coreMhz;
|
|
|
|
double m_cpuPeriod = 0;
|
|
|
|
bool m_updatedCPUs = false; // TODO use caching or just update?
|
|
|
|
bool m_inited = false;
|
2020-03-14 20:59:43 +00:00
|
|
|
FILE *m_cpuTempFile = nullptr;
|
2020-02-01 23:55:24 +00:00
|
|
|
};
|
|
|
|
|
2020-05-10 12:11:56 +00:00
|
|
|
extern CPUStats cpuStats;
|
2020-07-06 17:31:40 +00:00
|
|
|
|
|
|
|
#endif //MANGOHUD_CPU_H
|