Commit 3359c6fb authored by David Redondo's avatar David Redondo 🏎

Do no work if no objects are subscribed

parent 926ec8a9
......@@ -50,6 +50,10 @@ FreeBsdCpuObject::FreeBsdCpuObject(const QString &id, const QString &name, Senso
void FreeBsdCpuObject::update(long system, long user, long idle)
{
if (!isSubscribed()) {
return;
}
// No wait usage on FreeBSD
m_usageComputer.setTicks(system, user, 0, idle);
......@@ -96,6 +100,10 @@ FreeBsdCpuPluginPrivate::FreeBsdCpuPluginPrivate(CpuPlugin* q)
void FreeBsdCpuPluginPrivate::update()
{
auto isSubscribed = [] (const SensorObject *o) {return o->isSubscribed();};
if (std::none_of(m_container->objects().cbegin(), m_container->objects().cend(), isSubscribed)) {
return;
}
auto updateCpu = [] (auto *cpu, long *cp_time){
cpu->update(cp_time[CP_SYS + CP_INTR], cp_time[CP_USER] + cp_time[CP_NICE], cp_time[CP_IDLE]);
};
......
......@@ -57,6 +57,10 @@ void LinuxCpuObject::setTemperatureSensor(const sensors_chip_name * const chipNa
void LinuxCpuObject::update(unsigned long long system, unsigned long long user, unsigned long long wait, unsigned long long idle)
{
if (!isSubscribed()) {
return;
}
// First update usages
m_usageComputer.setTicks(system, user, wait, idle);
......
......@@ -73,6 +73,11 @@ LinuxCpuPluginPrivate::LinuxCpuPluginPrivate(CpuPlugin *q)
void LinuxCpuPluginPrivate::update()
{
auto isSubscribed = [] (const SensorObject *o) {return o->isSubscribed();};
if (std::none_of(m_container->objects().cbegin(), m_container->objects().cend(), isSubscribed)) {
return;
}
// Parse /proc/stat to get usage values. The format is described at
// https://www.kernel.org/doc/html/latest/filesystems/proc.html#miscellaneous-kernel-statistics-in-proc-stat
QFile stat("/proc/stat");
......
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