Commit 118c4bdf authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Set proper initial values for many SensorProperties

SensorProperty in libksysguard was changed to reset the value of a
sensor on unsubscribe. However, this caused a number of "static" sensors
to break and only provide their value once. To fix this, SensorProperty
will now only reset the value if a valid initial value was provided.

This changes many SensorProperties to have valid initial values. This
has been applied primarily to sensors that are very volatile and which
provide a different value almost every update, like the various rate
sensors as well as the usage percentage sensors. For these sensors, it
is unlikely thata a historical value makes any sense.

Other sensors, like memory usage, are less volatile and will generally
not vary wildly, so providing a historical value for those seems better
than an empty value.

BUG: 446414


(cherry picked from commit 40be1b73)
parent 90b9b9bd
Pipeline #174689 passed with stage
in 44 seconds
......@@ -15,10 +15,10 @@ BaseCpuObject::BaseCpuObject(const QString &id, const QString &name, KSysGuard::
void BaseCpuObject::makeSensors()
{
m_usage = new KSysGuard::SensorProperty(QStringLiteral("usage"), this);
m_system = new KSysGuard::SensorProperty(QStringLiteral("system"), this);
m_user = new KSysGuard::SensorProperty(QStringLiteral("user"), this);
m_wait = new KSysGuard::SensorProperty(QStringLiteral("wait"), this);
m_usage = new KSysGuard::SensorProperty(QStringLiteral("usage"), QStringLiteral("usage"), 0, this);
m_system = new KSysGuard::SensorProperty(QStringLiteral("system"), QStringLiteral("system"), 0, this);
m_user = new KSysGuard::SensorProperty(QStringLiteral("user"), QStringLiteral("user"), 0, this);
m_wait = new KSysGuard::SensorProperty(QStringLiteral("wait"), QStringLiteral("wait"), 0, this);
auto n = new KSysGuard::SensorProperty(QStringLiteral("name"), i18nc("@title", "Name"), name(), this);
n->setVariantType(QVariant::String);
}
......@@ -67,8 +67,8 @@ void CpuObject::makeSensors()
{
BaseCpuObject::makeSensors();
m_frequency = new KSysGuard::SensorProperty(QStringLiteral("frequency"), this);
m_temperature = new KSysGuard::SensorProperty(QStringLiteral("temperature"), this);
m_frequency = new KSysGuard::SensorProperty(QStringLiteral("frequency"), QStringLiteral("frequency"), 0, this);
m_temperature = new KSysGuard::SensorProperty(QStringLiteral("temperature"), QStringLiteral("temperature"), 0, this);
}
void CpuObject::initialize()
......
......@@ -72,8 +72,8 @@ void FreeBsdCpuObject::makeSensors()
{
BaseCpuObject::makeSensors();
m_frequency = new KSysGuard::SysctlSensor<int>(QStringLiteral("frequency"), m_sysctlPrefix + QByteArrayLiteral(".freq"), this);
m_temperature = new KSysGuard::SysctlSensor<int>(QStringLiteral("temperature"), m_sysctlPrefix + QByteArrayLiteral(".temperature"), this);
m_frequency = new KSysGuard::SysctlSensor<int>(QStringLiteral("frequency"), m_sysctlPrefix + QByteArrayLiteral(".freq"), 0, this);
m_temperature = new KSysGuard::SysctlSensor<int>(QStringLiteral("temperature"), m_sysctlPrefix + QByteArrayLiteral(".temperature"), 0, this);
}
void FreeBsdCpuObject::initialize()
......
......@@ -11,9 +11,9 @@
LoadAverages::LoadAverages(KSysGuard::SensorContainer *parent)
: KSysGuard::SensorObject(QStringLiteral("loadaverages"), i18nc("@title", "Load Averages"), parent)
, average1Minute{new KSysGuard::SensorProperty(QStringLiteral("loadaverage1"), i18nc("@title", "Load average (1 minute)"), this)}
, average5Minutes{new KSysGuard::SensorProperty(QStringLiteral("loadaverage5"), i18nc("@title", "Load average (5 minutes)"), this)}
, average15Minutes{new KSysGuard::SensorProperty(QStringLiteral("loadaverage15"), i18nc("@title", "Load average (15 minute)"), this)}
, average1Minute{new KSysGuard::SensorProperty(QStringLiteral("loadaverage1"), i18nc("@title", "Load average (1 minute)"), 0, this)}
, average5Minutes{new KSysGuard::SensorProperty(QStringLiteral("loadaverage5"), i18nc("@title", "Load average (5 minutes)"), 0, this)}
, average15Minutes{new KSysGuard::SensorProperty(QStringLiteral("loadaverage15"), i18nc("@title", "Load average (15 minute)"), 0, this)}
{
average1Minute->setShortName(i18nc("@title, Short for 'Load average (1 minute)", "Load average (1m)"));
average5Minutes->setShortName(i18nc("@title, Short for 'Load average (5 minutes)", "Load average (5m)"));
......
......@@ -89,13 +89,13 @@ VolumeObject::VolumeObject(const Solid::Device &device, KSysGuard::SensorContain
m_free->setVariantType(QVariant::ULongLong);
m_free->setMax(volume->size());
m_readRate = new KSysGuard::SensorProperty("read", i18nc("@title", "Read Rate"), this);
m_readRate = new KSysGuard::SensorProperty("read", i18nc("@title", "Read Rate"), 0, this);
m_readRate->setPrefix(name());
m_readRate->setShortName(i18nc("@title Short for 'Read Rate'", "Read"));
m_readRate->setUnit(KSysGuard::UnitByteRate);
m_readRate->setVariantType(QVariant::Double);
m_writeRate = new KSysGuard::SensorProperty("write", i18nc("@title", "Write Rate"), this);
m_writeRate = new KSysGuard::SensorProperty("write", i18nc("@title", "Write Rate"), 0, this);
m_writeRate->setPrefix(name());
m_writeRate->setShortName(i18nc("@title Short for 'Write Rate'", "Write"));
m_writeRate->setUnit(KSysGuard::UnitByteRate);
......@@ -252,13 +252,13 @@ void DisksPlugin::addAggregateSensors()
used->setMax(total->value().toULongLong());
used->setMatchSensors(QRegularExpression("^(?!all).*$"), "used");
auto readRate = new KSysGuard::AggregateSensor(allDisks, "read", i18nc("@title", "Read Rate"));
auto readRate = new KSysGuard::AggregateSensor(allDisks, "read", i18nc("@title", "Read Rate"), 0);
readRate->setShortName(i18nc("@title Short for 'Read Rate'", "Read"));
readRate->setUnit(KSysGuard::UnitByteRate);
readRate->setVariantType(QVariant::Double);
readRate->setMatchSensors(QRegularExpression("^(?!all).*$"), "read");
auto writeRate = new KSysGuard::AggregateSensor(allDisks, "write", i18nc("@title", "Write Rate"));
auto writeRate = new KSysGuard::AggregateSensor(allDisks, "write", i18nc("@title", "Write Rate"), 0);
writeRate->setShortName(i18nc("@title Short for 'Write Rate'", "Write"));
writeRate->setUnit(KSysGuard::UnitByteRate);
writeRate->setVariantType(QVariant::Double);
......
......@@ -13,7 +13,7 @@
AllGpus::AllGpus(KSysGuard::SensorContainer *parent)
: SensorObject(QStringLiteral("all"), i18nc("@title", "All GPUs"), parent)
{
m_usageSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("usage"), i18nc("@title", "All GPUs Usage"));
m_usageSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("usage"), i18nc("@title", "All GPUs Usage"), 0);
m_usageSensor->setShortName(i18nc("@title Short for 'All GPUs Usage'", "Usage"));
m_usageSensor->setMatchSensors(QRegularExpression{QStringLiteral("^(?!all).*$")}, QStringLiteral("usage"));
m_usageSensor->setAggregateFunction([this](const QVariant &first, const QVariant &second) {
......
......@@ -58,10 +58,10 @@ void GpuDevice::update()
void GpuDevice::makeSensors()
{
m_nameProperty = new KSysGuard::SensorProperty(QStringLiteral("name"), this);
m_usageProperty = new KSysGuard::SensorProperty(QStringLiteral("usage"), this);
m_usageProperty = new KSysGuard::SensorProperty(QStringLiteral("usage"), QStringLiteral("usage"), 0, this);
m_totalVramProperty = new KSysGuard::SensorProperty(QStringLiteral("totalVram"), this);
m_usedVramProperty = new KSysGuard::SensorProperty(QStringLiteral("usedVram"), this);
m_coreFrequencyProperty = new KSysGuard::SensorProperty(QStringLiteral("coreFrequency"), this);
m_memoryFrequencyProperty = new KSysGuard::SensorProperty(QStringLiteral("memoryFrequency"), this);
m_temperatureProperty = new KSysGuard::SensorProperty(QStringLiteral("temperature"), this);
m_coreFrequencyProperty = new KSysGuard::SensorProperty(QStringLiteral("coreFrequency"), QStringLiteral("coreFrequency"), 0, this);
m_memoryFrequencyProperty = new KSysGuard::SensorProperty(QStringLiteral("memoryFrequency"), QStringLiteral("memoryFrequency"), 0, this);
m_temperatureProperty = new KSysGuard::SensorProperty(QStringLiteral("temperature"), QStringLiteral("temperature"), 0, this);
}
......@@ -88,7 +88,7 @@ void LinuxAmdGpu::makeSensors()
m_nameProperty = new KSysGuard::SensorProperty(QStringLiteral("name"), this);
m_totalVramProperty = new KSysGuard::SensorProperty(QStringLiteral("totalVram"), this);
auto sensor = new KSysGuard::SysFsSensor(QStringLiteral("usage"), devicePath % QStringLiteral("/gpu_busy_percent"), this);
auto sensor = new KSysGuard::SysFsSensor(QStringLiteral("usage"), devicePath % QStringLiteral("/gpu_busy_percent"), 0, this);
m_usageProperty = sensor;
m_sysFsSensors << sensor;
......@@ -96,14 +96,14 @@ void LinuxAmdGpu::makeSensors()
m_usedVramProperty = sensor;
m_sysFsSensors << sensor;
sensor = new KSysGuard::SysFsSensor(QStringLiteral("coreFrequency"), devicePath % QStringLiteral("/pp_dpm_sclk"), this);
sensor = new KSysGuard::SysFsSensor(QStringLiteral("coreFrequency"), devicePath % QStringLiteral("/pp_dpm_sclk"), 0, this);
sensor->setConvertFunction([](const QByteArray &input) {
return ppTableGetCurrent(input);
});
m_coreFrequencyProperty = sensor;
m_sysFsSensors << sensor;
sensor = new KSysGuard::SysFsSensor(QStringLiteral("memoryFrequency"), devicePath % QStringLiteral("/pp_dpm_mclk"), this);
sensor = new KSysGuard::SysFsSensor(QStringLiteral("memoryFrequency"), devicePath % QStringLiteral("/pp_dpm_mclk"), 0, this);
sensor->setConvertFunction([](const QByteArray &input) {
return ppTableGetCurrent(input);
});
......
......@@ -15,22 +15,22 @@
AllDevicesObject::AllDevicesObject(KSysGuard::SensorContainer *parent)
: SensorObject(QStringLiteral("all"), i18nc("@title", "All Network Devices"), parent)
{
m_downloadSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("download"), i18nc("@title", "Download Rate"));
m_downloadSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("download"), i18nc("@title", "Download Rate"), 0);
m_downloadSensor->setShortName(i18nc("@title Short for Download Rate", "Download"));
m_downloadSensor->setUnit(KSysGuard::UnitByteRate);
m_downloadSensor->setMatchSensors(QRegularExpression{QStringLiteral("^(?!all).*$")}, QStringLiteral("download"));
m_uploadSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("upload"), i18nc("@title", "Upload Rate"));
m_uploadSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("upload"), i18nc("@title", "Upload Rate"), 0);
m_uploadSensor->setShortName(i18nc("@title Short for Upload Rate", "Upload"));
m_uploadSensor->setUnit(KSysGuard::UnitByteRate);
m_uploadSensor->setMatchSensors(QRegularExpression{QStringLiteral("^(?!all).*$")}, QStringLiteral("upload"));
m_downloadBitsSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("downloadBits"), i18nc("@title", "Download Rate"));
m_downloadBitsSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("downloadBits"), i18nc("@title", "Download Rate"), 0);
m_downloadBitsSensor->setShortName(i18nc("@title Short for Download Rate", "Download"));
m_downloadBitsSensor->setUnit(KSysGuard::UnitBitRate);
m_downloadBitsSensor->setMatchSensors(QRegularExpression{"^(?!all).*$"}, QStringLiteral("downloadBits"));
m_uploadBitsSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("uploadBits"), i18nc("@title", "Upload Rate"));
m_uploadBitsSensor = new KSysGuard::AggregateSensor(this, QStringLiteral("uploadBits"), i18nc("@title", "Upload Rate"), 0);
m_uploadBitsSensor->setShortName(i18nc("@title Short for Upload Rate", "Upload"));
m_uploadBitsSensor->setUnit(KSysGuard::UnitBitRate);
m_uploadBitsSensor->setMatchSensors(QRegularExpression{"^(?!all).*$"}, QStringLiteral("uploadBits"));
......
......@@ -15,7 +15,7 @@ NetworkDevice::NetworkDevice(const QString &id, const QString &name)
m_networkSensor->setShortName(i18nc("@title Short of Network Name", "Name"));
m_networkSensor->setPrefix(name);
m_signalSensor = new KSysGuard::SensorProperty(QStringLiteral("signal"), i18nc("@title", "Signal Strength"), this);
m_signalSensor = new KSysGuard::SensorProperty(QStringLiteral("signal"), i18nc("@title", "Signal Strength"), 0, this);
m_signalSensor->setShortName(i18nc("@title Short of Signal Strength", "Signal"));
m_signalSensor->setUnit(KSysGuard::UnitPercent);
m_signalSensor->setMin(0);
......@@ -30,22 +30,22 @@ NetworkDevice::NetworkDevice(const QString &id, const QString &name)
m_ipv6Sensor->setShortName(i18nc("@title Short of IPv6 Address", "IPv6"));
m_ipv6Sensor->setPrefix(name);
m_downloadSensor = new KSysGuard::SensorProperty(QStringLiteral("download"), i18nc("@title", "Download Rate"), this);
m_downloadSensor = new KSysGuard::SensorProperty(QStringLiteral("download"), i18nc("@title", "Download Rate"), 0, this);
m_downloadSensor->setShortName(i18nc("@title Short for Download Rate", "Download"));
m_downloadSensor->setUnit(KSysGuard::UnitByteRate);
m_downloadSensor->setPrefix(name);
m_uploadSensor = new KSysGuard::SensorProperty(QStringLiteral("upload"), i18nc("@title", "Upload Rate"), this);
m_uploadSensor = new KSysGuard::SensorProperty(QStringLiteral("upload"), i18nc("@title", "Upload Rate"), 0, this);
m_uploadSensor->setShortName(i18nc("@title Short for Upload Rate", "Upload"));
m_uploadSensor->setUnit(KSysGuard::UnitByteRate);
m_uploadSensor->setPrefix(name);
m_downloadBitsSensor = new KSysGuard::SensorProperty(QStringLiteral("downloadBits"), i18nc("@title", "Download Rate"), this);
m_downloadBitsSensor = new KSysGuard::SensorProperty(QStringLiteral("downloadBits"), i18nc("@title", "Download Rate"), 0, this);
m_downloadBitsSensor->setShortName(i18nc("@title Short for Download Rate", "Download"));
m_downloadBitsSensor->setUnit(KSysGuard::UnitBitRate);
m_downloadBitsSensor->setPrefix(name);
m_uploadBitsSensor = new KSysGuard::SensorProperty(QStringLiteral("uploadBits"), i18nc("@title", "Upload Rate"), this);
m_uploadBitsSensor = new KSysGuard::SensorProperty(QStringLiteral("uploadBits"), i18nc("@title", "Upload Rate"), 0, this);
m_uploadBitsSensor->setShortName(i18nc("@title Short for Upload Rate", "Upload"));
m_uploadBitsSensor->setUnit(KSysGuard::UnitBitRate);
m_uploadBitsSensor->setPrefix(name);
......
......@@ -106,26 +106,26 @@ OSInfoPrivate::OSInfoPrivate(OSInfoPlugin *qq)
container = new KSysGuard::SensorContainer(QStringLiteral("os"), i18nc("@title", "Operating System"), q);
kernelObject = new KSysGuard::SensorObject(QStringLiteral("kernel"), i18nc("@title", "Kernel"), container);
kernelNameProperty = new KSysGuard::SensorProperty(QStringLiteral("name"), i18nc("@title", "Kernel Name"), QString{}, kernelObject);
kernelVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("version"), i18nc("@title", "Kernel Version"), QString{}, kernelObject);
kernelPrettyNameProperty = new KSysGuard::SensorProperty(QStringLiteral("prettyName"), i18nc("@title", "Kernel Name and Version"), QString{}, kernelObject);
kernelNameProperty = new KSysGuard::SensorProperty(QStringLiteral("name"), i18nc("@title", "Kernel Name"), kernelObject);
kernelVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("version"), i18nc("@title", "Kernel Version"), kernelObject);
kernelPrettyNameProperty = new KSysGuard::SensorProperty(QStringLiteral("prettyName"), i18nc("@title", "Kernel Name and Version"), kernelObject);
kernelPrettyNameProperty->setShortName(i18nc("@title Kernel Name and Version", "Kernel"));
systemObject = new KSysGuard::SensorObject(QStringLiteral("system"), i18nc("@title", "System"), container);
hostnameProperty = new KSysGuard::SensorProperty(QStringLiteral("hostname"), i18nc("@title", "Hostname"), QString{}, systemObject);
osNameProperty = new KSysGuard::SensorProperty(QStringLiteral("name"), i18nc("@title", "Operating System Name"), QString{}, systemObject);
osVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("version"), i18nc("@title", "Operating System Version"), QString{}, systemObject);
osPrettyNameProperty = new KSysGuard::SensorProperty(QStringLiteral("prettyName"), i18nc("@title", "Operating System Name and Version"), QString{}, systemObject);
hostnameProperty = new KSysGuard::SensorProperty(QStringLiteral("hostname"), i18nc("@title", "Hostname"), systemObject);
osNameProperty = new KSysGuard::SensorProperty(QStringLiteral("name"), i18nc("@title", "Operating System Name"), systemObject);
osVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("version"), i18nc("@title", "Operating System Version"), systemObject);
osPrettyNameProperty = new KSysGuard::SensorProperty(QStringLiteral("prettyName"), i18nc("@title", "Operating System Name and Version"), systemObject);
osPrettyNameProperty->setShortName(i18nc("@title Operating System Name and Version", "OS"));
osLogoProperty = new KSysGuard::SensorProperty(QStringLiteral("logo"), i18nc("@title", "Operating System Logo"), QString{}, systemObject);
osUrlProperty = new KSysGuard::SensorProperty(QStringLiteral("url"), i18nc("@title", "Operating System URL"), QString{}, systemObject);
uptimeProperty = new KSysGuard::SensorProperty(QStringLiteral("uptime"), i18nc("@title", "Uptime"), QString{}, systemObject);
osLogoProperty = new KSysGuard::SensorProperty(QStringLiteral("logo"), i18nc("@title", "Operating System Logo"), systemObject);
osUrlProperty = new KSysGuard::SensorProperty(QStringLiteral("url"), i18nc("@title", "Operating System URL"), systemObject);
uptimeProperty = new KSysGuard::SensorProperty(QStringLiteral("uptime"), i18nc("@title", "Uptime"), systemObject);
uptimeProperty->setUnit(KSysGuard::UnitTime);
plasmaObject = new KSysGuard::SensorObject(QStringLiteral("plasma"), i18nc("@title", "KDE Plasma"), container);
qtVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("qtVersion"), i18nc("@title", "Qt Version"), QString{}, plasmaObject);
kfVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("kfVersion"), i18nc("@title", "KDE Frameworks Version"), QString{}, plasmaObject);
plasmaVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("plasmaVersion"), i18nc("@title", "KDE Plasma Version"), QString{}, plasmaObject);
qtVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("qtVersion"), i18nc("@title", "Qt Version"), plasmaObject);
kfVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("kfVersion"), i18nc("@title", "KDE Frameworks Version"), plasmaObject);
plasmaVersionProperty = new KSysGuard::SensorProperty(QStringLiteral("plasmaVersion"), i18nc("@title", "KDE Plasma Version"), plasmaObject);
}
OSInfoPlugin::~OSInfoPlugin() = default;
......
......@@ -87,12 +87,13 @@ Battery::Battery(const Solid::Device &device, const QString &name, KSysGuard::Se
connect(battery, &Solid::Battery::chargePercentChanged, chargePercent, &KSysGuard::SensorProperty::setValue);
// Solid reports negative of charging and positive for discharging
auto chargeRate = new KSysGuard::SensorProperty("chargeRate", i18nc("@title", "Charging Rate"), -battery->energyRate(), this);
auto chargeRate = new KSysGuard::SensorProperty("chargeRate", i18nc("@title", "Charging Rate"), 0, this);
chargeRate->setShortName(i18nc("@title", "Charging Rate"));
chargeRate->setPrefix(name);
chargeRate->setDescription(i18n("Power that the battery is being charged with (positive) or discharged (negative)"));
chargeRate->setUnit(KSysGuard::UnitWatt);
chargeRate->setVariantType(QVariant::Double);
chargeRate->setValue(-battery->energyRate());
connect(battery, &Solid::Battery::energyRateChanged, chargeRate, [chargeRate] (double rate) {
chargeRate->setValue(-rate);
});
......
Supports Markdown
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