2018-10-26 12:05:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDebug>
|
2018-11-06 16:59:10 +01:00
|
|
|
#include <QTimer>
|
2018-12-02 21:22:12 +01:00
|
|
|
#include <QString>
|
2018-10-26 12:05:23 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <qt_windows.h>
|
|
|
|
#endif
|
|
|
|
// https://github.com/rainmeter/rainmeter/blob/master/Library/MeasureCPU.cpp
|
|
|
|
|
|
|
|
class CPU : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY(float usage READ usage NOTIFY usageChanged)
|
2018-11-06 16:59:10 +01:00
|
|
|
Q_PROPERTY(int tickRate READ tickRate WRITE setTickRate NOTIFY tickRateChanged)
|
2018-10-26 12:05:23 +02:00
|
|
|
|
2018-12-02 21:22:12 +01:00
|
|
|
|
2018-10-26 12:05:23 +02:00
|
|
|
public:
|
|
|
|
explicit CPU(QObject* parent = nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
float usage() const
|
|
|
|
{
|
|
|
|
return m_usage;
|
|
|
|
}
|
|
|
|
|
2018-11-06 16:59:10 +01:00
|
|
|
int tickRate() const
|
|
|
|
{
|
|
|
|
return m_tickRate;
|
|
|
|
}
|
|
|
|
|
2018-10-26 12:05:23 +02:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void usageChanged(float usage);
|
|
|
|
|
2018-11-06 16:59:10 +01:00
|
|
|
void tickRateChanged(int tickRate);
|
|
|
|
|
2018-12-02 21:22:12 +01:00
|
|
|
|
2018-10-26 12:05:23 +02:00
|
|
|
public slots:
|
|
|
|
void update();
|
|
|
|
|
|
|
|
void setUsage(float usage)
|
|
|
|
{
|
|
|
|
if (qFuzzyCompare(m_usage, usage))
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_usage = usage;
|
|
|
|
emit usageChanged(m_usage);
|
|
|
|
}
|
|
|
|
|
2018-11-06 16:59:10 +01:00
|
|
|
void setTickRate(int tickRate)
|
|
|
|
{
|
|
|
|
if (m_tickRate == tickRate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
qDebug() << "hat sich was geändert";
|
|
|
|
|
|
|
|
m_tickRate = tickRate;
|
|
|
|
emit tickRateChanged(m_tickRate);
|
|
|
|
}
|
|
|
|
|
2018-10-26 12:05:23 +02:00
|
|
|
|
|
|
|
|
2018-12-02 21:22:12 +01:00
|
|
|
private:
|
|
|
|
float m_usage = 0.0f;
|
2018-10-26 12:05:23 +02:00
|
|
|
|
2018-12-02 21:22:12 +01:00
|
|
|
uint64_t lastIdleTime = 0;
|
|
|
|
uint64_t lastKernelTime = 0;
|
|
|
|
uint64_t lastUserTime = 0;
|
2018-10-26 12:05:23 +02:00
|
|
|
|
2018-12-02 21:22:12 +01:00
|
|
|
int m_tickRate = 1000;
|
2018-11-06 17:00:21 +01:00
|
|
|
QTimer m_updateTimer;
|
2018-10-26 12:05:23 +02:00
|
|
|
};
|