Commit 926ec8a9 authored by David Redondo's avatar David Redondo 🏎

Do not look up cpus by id

parent f7745a69
......@@ -89,9 +89,9 @@ FreeBsdCpuPluginPrivate::FreeBsdCpuPluginPrivate(CpuPlugin* q)
int numCpu;
readSysctl("hw.ncpu", &numCpu);
for (int i = 0; i < numCpu; ++i) {
new FreeBsdCpuObject(QStringLiteral("cpu%1").arg(i), i18nc("@title", "CPU %1", i + 1), m_container);
m_cpus.push_back(new FreeBsdCpuObject(QStringLiteral("cpu%1").arg(i), i18nc("@title", "CPU %1", i + 1), m_container));
}
new FreeBsdAllCpusObject(numCpu, numCpu, m_container);
m_allCpus = new FreeBsdAllCpusObject(numCpu, numCpu, m_container);
}
void FreeBsdCpuPluginPrivate::update()
......@@ -104,13 +104,13 @@ void FreeBsdCpuPluginPrivate::update()
size_t cpTimesSize = sizeof(long) * cp_times.size();
if (readSysctl("kern.cp_times", cp_times.data(), cpTimesSize)) {//, &cpTimesSize, nullptr, 0) != -1) {
for (unsigned int i = 0; i < numCores; ++i) {
auto cpu = static_cast<FreeBsdCpuObject*>(m_container->object(QStringLiteral("cpu%1").arg(i)));
auto cpu = m_cpus[i];
updateCpu(cpu, &cp_times[CPUSTATES * i]);
}
}
// update total values
long cp_time[CPUSTATES];
if (readSysctl("kern.cp_time", &cp_time)) {
updateCpu(static_cast<FreeBsdCpuObject*>(m_container->object(QStringLiteral("all"))), cp_time);
updateCpu(m_allCpus, cp_time);
}
}
......@@ -25,6 +25,9 @@ class FreeBsdCpuPluginPrivate : public CpuPluginPrivate {
public:
FreeBsdCpuPluginPrivate(CpuPlugin *q);
void update() override;
private:
FreeBsdAllCpusObject *m_allCpus;
QVector<FreeBsdCpuObject*> m_cpus;
};
#endif
......@@ -63,9 +63,10 @@ LinuxCpuPluginPrivate::LinuxCpuPluginPrivate(CpuPlugin *q)
}
const QString name = i18nc("@title", "CPU %1 Core %2", physicalId + 1, ++numCores[physicalId]);
auto cpu = new LinuxCpuObject(QStringLiteral("cpu%1").arg(processor), name, m_container, frequency);
m_cpus.push_back(cpu);
m_cpusBySystemIds.insert({physicalId, coreId}, cpu);
}
new LinuxAllCpusObject(numCores.keys().size(), numCores.size(), m_container);
m_allCpus = new LinuxAllCpusObject(numCores.keys().size(), numCores.size(), m_container);
addSensors();
}
......@@ -94,10 +95,9 @@ void LinuxCpuPluginPrivate::update()
// Total values just start with "cpu", single cpus are numbered cpu0, cpu1, ...
if (line.startsWith("cpu ")) {
auto cpu = static_cast<LinuxAllCpusObject*>(m_container->object(QStringLiteral("all")));
cpu->update(system + irq + softirq, user + nice , iowait + steal, idle);
m_allCpus->update(system + irq + softirq, user + nice , iowait + steal, idle);
} else if (line.startsWith("cpu")) {
auto cpu = static_cast<LinuxCpuObject*>(m_container->object(line.left(line.indexOf(' '))));
auto cpu = m_cpus[std::atoi(line.mid(strlen("cpu")))];
cpu->update(system + irq + softirq, user + nice , iowait + steal, idle);
}
}
......
......@@ -25,6 +25,7 @@
struct sensors_chip_name;
class LinuxCpuObject;
class LinuxAllCpusObject;
class LinuxCpuPluginPrivate : public CpuPluginPrivate {
public:
......@@ -34,6 +35,9 @@ private:
void addSensors();
void addSensorsIntel(const sensors_chip_name * const chipName);
void addSensorsAmd(const sensors_chip_name * const chipName);
LinuxAllCpusObject *m_allCpus;
QVector<LinuxCpuObject *> m_cpus;
QMultiHash<QPair<unsigned int, unsigned int>, LinuxCpuObject * const> m_cpusBySystemIds;
};
......
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