Commit d391e4fc authored by David Redondo's avatar David Redondo 🏎

Revert mixin approach.

parent 6c3cf0f2
......@@ -19,6 +19,8 @@
#include "cpu.h"
#include <KLocalizedString>
CpuObject::CpuObject(const QString &id, const QString &name, SensorContainer *parent)
: SensorObject(id, name, parent)
, m_frequency{nullptr}
......
......@@ -20,14 +20,14 @@
#ifndef CPU_H
#define CPU_H
#include <KLocalizedString>
#include <SensorObject.h>
class CpuObject : public SensorObject {
public:
CpuObject(const QString &id, const QString &name, SensorContainer *parent);
// const int physicalId; // NOTE The combination of these two ids is not necessarily unique with hyperthreading
// const int coreId;
protected:
SensorProperty *m_usage;
SensorProperty *m_system;
......@@ -37,25 +37,4 @@ protected:
SensorProperty *m_temperature;
};
template <typename T>
class AllCpusObject : public T {
public:
AllCpusObject(unsigned int cpus, unsigned int cores, SensorContainer *parent);
static_assert(std::is_base_of<CpuObject, T>::value, "Base of AllCpuObject must be a CpuObject");
};
template <typename T>
AllCpusObject<T>::AllCpusObject(unsigned int cpus, unsigned int cores, SensorContainer *parent)
: T(QStringLiteral("all"), i18nc("@title", "All"), parent)
{
delete T::m_frequency;
delete T::m_temperature;
auto cpuCount = new SensorProperty(QStringLiteral("cpuCount"), i18nc("@title", "Number of CPUs"), cpus, this);
cpuCount->setShortName(i18nc("@title, Short fort 'Number of CPUs'", "CPUs"));
cpuCount->setDescription(i18nc("@info", "Number of physical CPUs installed in the system"));
auto coreCount = new SensorProperty(QStringLiteral("coreCount"), i18nc("@title", "Number of Cores"), cores, this);
coreCount->setShortName(i18nc("@title, Short fort 'Number of Cores'", "Cores"));
coreCount->setDescription(i18nc("@info", "Number of CPU cores across all physical CPUS"));
}
#endif
......@@ -43,6 +43,7 @@ FreeBsdCpuObject::FreeBsdCpuObject(const QString &id, const QString &name, Senso
}
const QByteArray tjmax = QByteArrayLiteral("dev.cpu.") + id.right(1).toLocal8Bit() + QByteArrayLiteral(".coretemp.tjmax");
int maxTemperature;
size_t maxTemperatureSize = sizeof(maxTemperature);
// This is only availabel on Intel (using the coretemp driver)
if (readSysctl(tjmax.constData(), &maxTemperature)) {
m_temperature->setMax(maxTemperature);
......@@ -68,7 +69,7 @@ void FreeBsdCpuObject::update(long system, long user, long idle)
m_userTicks = user;
m_totalTicks = totalTicks;
if (!m_frequency) {
if (id() == QStringLiteral("all")) {
return;
}
......@@ -96,13 +97,22 @@ FreeBsdCpuPluginPrivate::FreeBsdCpuPluginPrivate(CpuPlugin* q)
for (int i = 0; i < numCpu; ++i) {
new FreeBsdCpuObject(QStringLiteral("cpu%1").arg(i), i18nc("@title", "CPU %1", i + 1), m_container);
}
m_allCpusObject = new AllCpusObject<FreeBsdCpuObject>(numCpu, numCpu, m_container);
// Add total usage sensors
auto total = new FreeBsdCpuObject(QStringLiteral("all"), i18nc("@title", "All"), m_container);
auto cpuCount = new SensorProperty(QStringLiteral("cpuCount"), i18nc("@title", "Number of CPUs"), numCpu, total);
cpuCount->setShortName(i18nc("@title, Short fort 'Number of CPUs'", "CPUs"));
cpuCount->setDescription(i18nc("@info", "Number of physical CPUs installed in the system"));
auto coreCount = new SensorProperty(QStringLiteral("coreCount"), i18nc("@title", "Number of Cores"), numCpu, total);
coreCount->setShortName(i18nc("@title, Short fort 'Number of Cores'", "Cores"));
coreCount->setDescription(i18nc("@info", "Number of CPU cores across all physical CPUS"));
}
void FreeBsdCpuPluginPrivate::update()
{
auto updateCpu = [] (FreeBsdCpuObject *cpu, long *cp_time){
cpu->update(cp_time[CP_SYS] + cp_time[CP_INTR], cp_time[CP_USER] + cp_time[CP_NICE], cp_time[CP_IDLE]);
cpu->update(cp_time[CP_SYS + CP_INTR], cp_time[CP_USER] + cp_time[CP_NICE], cp_time[CP_IDLE]);
};
unsigned int numCores = m_container->objects().count() - 1;
std::vector<long> cp_times(numCores * CPUSTATES);
......@@ -116,6 +126,6 @@ void FreeBsdCpuPluginPrivate::update()
// update total values
long cp_time[CPUSTATES];
if (readSysctl("kern.cp_time", &cp_time)) {
updateCpu(m_allCpusObject, cp_time);
updateCpu(static_cast<FreeBsdCpuObject*>(m_container->object(QStringLiteral("all"))), cp_time);
}
}
......@@ -18,8 +18,6 @@ class FreeBsdCpuPluginPrivate : public CpuPluginPrivate {
public:
FreeBsdCpuPluginPrivate(CpuPlugin *q);
void update() override;
private:
AllCpusObject<FreeBsdCpuObject> *m_allCpusObject;
};
#endif
......@@ -143,8 +143,15 @@ LinuxCpuPluginPrivate::LinuxCpuPluginPrivate(CpuPlugin *q)
m_cpusBySystemIds.insert({physicalId, coreId}, cpu);
}
const int cores = m_container->objects().size();
// Add total usage sensors
auto total = new LinuxCpuObject(QStringLiteral("all"), i18nc("@title", "All"), m_container, 0);
auto cpuCount = new SensorProperty(QStringLiteral("cpuCount"), i18nc("@title", "Number of CPUs"), numCores.size(), total);
cpuCount->setShortName(i18nc("@title, Short fort 'Number of CPUs'", "CPUs"));
cpuCount->setDescription(i18nc("@info", "Number of physical CPUs installed in the system"));
m_allCpusObject = new AllCpusObject<LinuxCpuObject>(numCores.size(), cores, m_container);
auto coreCount = new SensorProperty(QStringLiteral("coreCount"), i18nc("@title", "Number of Cores"), cores, total);
coreCount->setShortName(i18nc("@title, Short fort 'Number of Cores'", "Cores"));
coreCount->setDescription(i18nc("@info", "Number of CPU cores across all physical CPUS"));
addSensors();
}
......@@ -160,7 +167,7 @@ void LinuxCpuPluginPrivate::update()
LinuxCpuObject *cpu;
// Total values
if (line.startsWith("cpu ")) {
cpu = m_allCpusObject;
cpu = static_cast<LinuxCpuObject*>(m_container->object(QStringLiteral("all")));
} else if (line.startsWith("cpu")) {
cpu = static_cast<LinuxCpuObject*>(m_container->object(line.left(line.indexOf(' '))));
} else {
......@@ -236,7 +243,6 @@ void LinuxCpuPluginPrivate::addSensorsIntel(const sensors_chip_name * const chip
void LinuxCpuPluginPrivate::addSensorsAmd(const sensors_chip_name * const chipName)
{
#ifdef HAVE_SENSORS
// All Processors should have the Tctl pseudo temperature as temp1. Newer ones have the real die
// temperature Tdie as temp2. Some of those have temperatures for each core complex die (CCD) as
// temp3-6 or temp3-10 depending on the number of CCDS.
......@@ -276,6 +282,5 @@ void LinuxCpuPluginPrivate::addSensorsAmd(const sensors_chip_name * const chipNa
} else if (tctl) {
setSingleSensor(tctl);
}
#endif
}
......@@ -31,7 +31,7 @@ struct sensors_feature;
class LinuxCpuObject : public CpuObject
{
public:
LinuxCpuObject(const QString &id, const QString &name, SensorContainer *parent, double frequency = 0);
LinuxCpuObject(const QString &id, const QString &name, SensorContainer *parent, double frequency);
void update(unsigned long long system, unsigned long long user, unsigned long long wait, unsigned long long idle);
void setTemperatureSensor(const sensors_chip_name * const chipName, const sensors_feature * const feature);
......@@ -53,7 +53,6 @@ private:
void addSensorsIntel(const sensors_chip_name * const chipName);
void addSensorsAmd(const sensors_chip_name * const chipName);
QMultiHash<QPair<unsigned int, unsigned int>, LinuxCpuObject * const> m_cpusBySystemIds;
AllCpusObject<LinuxCpuObject> *m_allCpusObject;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment