diff --git a/plugins/global/ksgrd/ksgrdiface.cpp b/plugins/global/ksgrd/ksgrdiface.cpp index a4cd1397..bdba56b7 100644 --- a/plugins/global/ksgrd/ksgrdiface.cpp +++ b/plugins/global/ksgrd/ksgrdiface.cpp @@ -1,399 +1,399 @@ /* Copyright (c) 2019 David Edmundson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ksgrdiface.h" #include "AggregateSensor.h" #include #include #include #include #include // TODO instantiate multiple instances with args for which host to use KSGRDIface::KSGRDIface(QObject *parent, const QVariantList &args) : SensorPlugin(parent, args) { auto registerSubsystem = [this](const QString &id) { m_subsystems[id] = new SensorContainer(id, id, this); // FIXME name resolve }; registerSubsystem("acpi"); registerSubsystem("cpu"); registerSubsystem("disk"); registerSubsystem("lmsensors"); registerSubsystem("mem"); registerSubsystem("network"); registerSubsystem("partitions"); registerSubsystem("uptime"); KSGRD::SensorMgr = new KSGRD::SensorManager(this); KSGRD::SensorMgr->engage(QStringLiteral("localhost"), QLatin1String(""), QStringLiteral("ksysguardd")); connect(KSGRD::SensorMgr, &KSGRD::SensorManager::update, this, &KSGRDIface::updateMonitorsList); updateMonitorsList(); // block for sensors to be loaded, but with a guard in case one fails to process // a non issue when we port things to be in-process QEventLoop e; auto t = new QTimer(&e); t->setInterval(2000); t->start(); connect(t, &QTimer::timeout, &e, [&e, this]() { e.quit(); }); connect(this, &KSGRDIface::sensorAdded, &e, [&e, this] { if (m_sensors.count() == m_sensorIds.count()) { e.quit(); } }); e.exec(); addAggregateSensors(); } KSGRDIface::~KSGRDIface() { } void KSGRDIface::subscribe(const QString &sensorPath) { if (!m_subscribedSensors.contains(sensorPath)) { m_subscribedSensors << sensorPath; const int index = m_sensorIds.indexOf(sensorPath); if (index != -1) { m_waitingFor++; KSGRD::SensorMgr->sendRequest(QStringLiteral("localhost"), sensorPath, (KSGRD::SensorClient *)this, index); KSGRD::SensorMgr->sendRequest(QStringLiteral("localhost"), QStringLiteral("%1?").arg(sensorPath), (KSGRD::SensorClient *)this, -(index + 2)); } } } void KSGRDIface::unsubscribe(const QString &sensorPath) { m_subscribedSensors.removeAll(sensorPath); } void KSGRDIface::updateMonitorsList() { KSGRD::SensorMgr->sendRequest(QStringLiteral("localhost"), QStringLiteral("monitors"), (KSGRD::SensorClient *)this, -1); } void KSGRDIface::onSensorMetaDataRetrieved(int id, const QList &answer) { if (answer.isEmpty() || id > m_sensorIds.count()) { qDebug() << "sensor info answer was empty, (" << answer.isEmpty() << ") or sensors does not exist to us "; return; } const QStringList newSensorInfo = QString::fromUtf8(answer[0]).split('\t'); if (newSensorInfo.count() < 4) { qDebug() << "bad sensor info, only" << newSensorInfo.count() << "entries, and we were expecting 4. Answer was " << answer; return; } const QString key = m_sensorIds.value(id); const QString &sensorName = newSensorInfo[0]; const QString &min = newSensorInfo[1]; const QString &max = newSensorInfo[2]; const QString &unit = newSensorInfo[3]; int subsystemIndex = key.indexOf('/'); int propertyIndex = key.lastIndexOf('/'); const QString subsystemId = key.left(subsystemIndex); const QString objectId = key.mid(subsystemIndex + 1, propertyIndex - (subsystemIndex + 1)); const QString propertyId = key.mid(propertyIndex + 1); auto subsystem = m_subsystems[subsystemId]; if (Q_UNLIKELY(!subsystem)) { qDebug() << "could not find subsystem" << subsystemId; return; } auto sensorObject = subsystem->object(objectId); if (!sensorObject) { sensorObject = new SensorObject(objectId, objectId, subsystem); // FIXME i18n name for object id? } auto sensor = m_sensors.value(key, nullptr); if (!sensor) { sensor = new SensorProperty(propertyId, sensorObject); } sensor->setName(sensorName); sensor->setShortName(shortNameFor(key)); sensor->setMin(min.toDouble()); sensor->setMax(max.toDouble()); sensor->setUnit(unitFromString(unit)); if (m_sensors.contains(key)) { return; } auto type = m_pendingTypes.take(key); if (type == QLatin1String("float")) { sensor->setVariantType(QVariant::Double); } else { sensor->setVariantType(QVariant::Int); } connect(sensor, &SensorProperty::subscribedChanged, this, [this, sensor](bool subscribed) { if (subscribed) { subscribe(sensor->path()); } else { unsubscribe(sensor->path()); } }); m_sensors[key] = sensor; emit sensorAdded(); } void KSGRDIface::onSensorListRetrieved(const QList &answer) { QSet sensors; int count = 0; for (const QByteArray &sens : answer) { const QString sensStr { QString::fromUtf8(sens) }; const QVector newSensorInfo = sensStr.splitRef('\t'); if (newSensorInfo.count() < 2) { continue; } auto type = newSensorInfo.at(1); if (type == QLatin1String("logfile")) { continue; // logfile data type not currently supported } const QString newSensor = newSensorInfo[0].toString(); sensors.insert(newSensor); m_sensorIds.append(newSensor); m_pendingTypes.insert(newSensor, type.toString()); //we don't emit sensorAdded yet, instead wait for the meta info to be fetched KSGRD::SensorMgr->sendRequest(QStringLiteral("localhost"), QStringLiteral("%1?").arg(newSensor), (KSGRD::SensorClient *)this, -(count + 2)); ++count; } // look for removed sensors // FIXME? foreach (const QString &sensor, m_sensorIds) { if (!sensors.contains(sensor)) { m_sensorIds.removeOne(sensor); m_sensors.remove(sensor); } } } void KSGRDIface::onSensorUpdated(int id, const QList &answer) { m_waitingFor--; const QString sensorName = m_sensorIds.at(id); if (sensorName.isEmpty()) { return; } QString reply; if (!answer.isEmpty()) { reply = QString::fromUtf8(answer[0]); } auto sensor = m_sensors[sensorName]; if (sensor) { if (sensor->info().variantType == QVariant::Double) { bool rc; double value = reply.toDouble(&rc); if (rc) { sensor->setValue(value); } } else if (sensor->info().variantType == QVariant::Int) { bool rc; int value = reply.toInt(&rc); if (rc) { sensor->setValue(value); } } else { sensor->setValue(reply); } } } KSysGuard::utils::Unit KSGRDIface::unitFromString(const QString &unitString) const { using namespace KSysGuard; static const QHash map({ { "%", utils::UnitPercent }, { "1/s", utils::UnitRate }, { "°C", utils::UnitCelsius }, { "dBm", utils::UnitDecibelMilliWatts }, { "KB", utils::UnitKiloByte }, { "KB/s", utils::UnitKiloByteRate }, { "MHz", utils::UnitMegaHertz }, { "port", utils::UnitNone }, { "rpm", utils::UnitRpm }, { "s", utils::UnitTime }, { "V", utils::UnitVolt } }); return map.value(unitString, utils::UnitNone); } void KSGRDIface::update() { for (int i = 0; i < m_subscribedSensors.count(); i++) { auto sensorName = m_subscribedSensors.at(i); int index = m_sensorIds.indexOf(sensorName); if (index < 0) { return; } m_waitingFor++; KSGRD::SensorMgr->sendRequest(QStringLiteral("localhost"), sensorName, (KSGRD::SensorClient *)this, index); } } void KSGRDIface::sensorLost(int) { m_waitingFor--; } void KSGRDIface::answerReceived(int id, const QList &answer) { //this is the response to "sensorName?" if (id < -1) { onSensorMetaDataRetrieved(-id - 2, answer); return; } //response to "monitors" if (id == -1) { onSensorListRetrieved(answer); return; } onSensorUpdated(id, answer); } void KSGRDIface::addAggregateSensors() { - auto networkAll = new SensorObject("all", i18n("All"), m_subsystems["network"]); + auto networkAll = new SensorObject("all", i18nc("@title All Network Interfaces", "All"), m_subsystems["network"]); - auto sensor = new AggregateSensor(networkAll, "receivedDataRate", i18n("Received Data Rate")); - sensor->setShortName(i18n("Down")); + auto sensor = new AggregateSensor(networkAll, "receivedDataRate", i18nc("@title", "Received Data Rate")); + sensor->setShortName(i18nc("@title Received Data Rate", "Down")); sensor->setMatchSensors(QRegularExpression("[^/]*/receiver"), QStringLiteral("data")); - sensor->setDescription(i18n("The rate at which data is received on all interfaces.")); + sensor->setDescription(i18nc("@info", "The rate at which data is received on all interfaces.")); sensor->setUnit(KSysGuard::utils::UnitKiloByteRate); - sensor = new AggregateSensor(networkAll, "totalReceivedData", i18n("Total Received Data")); - sensor->setShortName(i18n("Total Down")); + sensor = new AggregateSensor(networkAll, "totalReceivedData", i18nc("@title", "Total Received Data")); + sensor->setShortName(i18nc("@title Total Receieved Data", "Total Down")); sensor->setMatchSensors(QRegularExpression("[^/]*/receiver"), QStringLiteral("dataTotal")); - sensor->setDescription(i18n("The total amount of data received on all interfaces.")); + sensor->setDescription(i18nc("@info", "The total amount of data received on all interfaces.")); sensor->setUnit(KSysGuard::utils::UnitKiloByte); - sensor = new AggregateSensor(networkAll, "sentDataRate", i18n("Sent Data Rate")); - sensor->setShortName(i18n("Up")); + sensor = new AggregateSensor(networkAll, "sentDataRate", i18nc("@title", "Sent Data Rate")); + sensor->setShortName(i18nc("@title Sent Data Rate", "Up")); sensor->setMatchSensors(QRegularExpression("[^/]*/transmitter"), QStringLiteral("data")); - sensor->setDescription(i18n("The rate at which data is sent on all interfaces.")); + sensor->setDescription(i18nc("@info", "The rate at which data is sent on all interfaces.")); sensor->setUnit(KSysGuard::utils::UnitKiloByteRate); - sensor = new AggregateSensor(networkAll, "totalSentData", i18n("Total Sent Data")); - sensor->setShortName(i18n("Total Up")); + sensor = new AggregateSensor(networkAll, "totalSentData", i18nc("@title", "Total Sent Data")); + sensor->setShortName(i18nc("@title Total Sent Data", "Total Up")); sensor->setMatchSensors(QRegularExpression("[^/]*/transmitter"), QStringLiteral("dataTotal")); - sensor->setDescription(i18n("The total amount of data sent on all interfaces.")); + sensor->setDescription(i18nc("@info", "The total amount of data sent on all interfaces.")); sensor->setUnit(KSysGuard::utils::UnitKiloByte); - auto diskAll = new SensorObject("all", i18n("all"), m_subsystems["disk"]); - sensor = new AggregateSensor(diskAll, "read", i18n("Disk Read Accesses")); - sensor->setShortName(i18n("Read")); + auto diskAll = new SensorObject("all", i18nc("@title All Disks", "All"), m_subsystems["disk"]); + sensor = new AggregateSensor(diskAll, "read", i18nc("@title", "Disk Read Accesses")); + sensor->setShortName(i18nc("@title Disk Read Accesses", "Read")); // TODO: This regex is not exhaustive as it doesn't consider things that aren't treated as sdX devices. // However, we do not simply want to match disk/* as that would include duplicate devices. sensor->setMatchSensors(QRegularExpression("^sd[a-z]+[0-9]+_[^/]*/Rate$"), QStringLiteral("rblk")); - sensor->setDescription(i18n("Read accesses across all disk devices")); + sensor->setDescription(i18nc("@info", "Read accesses across all disk devices")); - sensor = new AggregateSensor(diskAll, "write", i18n("Disk Write Accesses")); - sensor->setShortName(i18n("Write")); + sensor = new AggregateSensor(diskAll, "write", i18nc("@title", "Disk Write Accesses")); + sensor->setShortName(i18nc("@title Disk Write Accesses", "Write")); // TODO: See above. sensor->setMatchSensors(QRegularExpression("^sd[a-z]+[0-9]+_[^/]*/Rate$"), QStringLiteral("wblk")); - sensor->setDescription(i18n("Write accesses across all disk devices")); + sensor->setDescription(i18nc("@info", "Write accesses across all disk devices")); auto memPhysical = m_subsystems["mem"]->object("physical"); Q_ASSERT(memPhysical); if (!memPhysical) { return; } - PercentageSensor *appLevel = new PercentageSensor(memPhysical, "applicationlevel", i18n("Application Memory Percentage")); - appLevel->setShortName(i18n("Application")); + PercentageSensor *appLevel = new PercentageSensor(memPhysical, "applicationlevel", i18nc("@title", "Application Memory Percentage")); + appLevel->setShortName(i18nc("@title Application Memory Percentage", "Application")); appLevel->setBaseSensor(memPhysical->sensor("application")); - appLevel->setDescription(i18n("Percentage of memory taken by applications.")); + appLevel->setDescription(i18nc("@info", "Percentage of memory taken by applications.")); - PercentageSensor *bufLevel = new PercentageSensor(memPhysical, "buflevel", i18n("Buffer Memory Percentage")); - bufLevel->setShortName(i18n("Buffer")); + PercentageSensor *bufLevel = new PercentageSensor(memPhysical, "buflevel", i18nc("@title", "Buffer Memory Percentage")); + bufLevel->setShortName(i18nc("@title Buffer Memory Percentage", "Buffer")); bufLevel->setBaseSensor(memPhysical->sensor("buf")); - bufLevel->setDescription(i18n("Percentage of memory taken by the buffer.")); + bufLevel->setDescription(i18nc("@info", "Percentage of memory taken by the buffer.")); - PercentageSensor *cacheLevel = new PercentageSensor(memPhysical, "cachelevel", i18n("Cache Memory Percentage")); - cacheLevel->setShortName(i18n("Cache")); + PercentageSensor *cacheLevel = new PercentageSensor(memPhysical, "cachelevel", i18nc("@title", "Cache Memory Percentage")); + cacheLevel->setShortName(i18nc("@title Cache Memory Percentage", "Cache")); cacheLevel->setBaseSensor(memPhysical->sensor("cached")); - cacheLevel->setDescription(i18n("Percentage of memory taken by the cache.")); + cacheLevel->setDescription(i18nc("@info", "Percentage of memory taken by the cache.")); - PercentageSensor *freeLevel = new PercentageSensor(memPhysical, "freelevel", i18n("Free Memory Percentage")); - freeLevel->setShortName(i18n("Cache")); + PercentageSensor *freeLevel = new PercentageSensor(memPhysical, "freelevel", i18nc("@title", "Free Memory Percentage")); + freeLevel->setShortName(i18nc("@title Free Memory Percentage", "Free")); freeLevel->setBaseSensor(memPhysical->sensor("free")); - freeLevel->setDescription(i18n("Percentage of free memory.")); + freeLevel->setDescription(i18nc("@info", "Percentage of free memory.")); - PercentageSensor *usedLevel = new PercentageSensor(memPhysical, "usedlevel", i18n("Used Memory Percentage")); - usedLevel->setShortName(i18n("Used")); + PercentageSensor *usedLevel = new PercentageSensor(memPhysical, "usedlevel", i18nc("@title", "Used Memory Percentage")); + usedLevel->setShortName(i18nc("@title Used Memory Percentage", "Used")); usedLevel->setBaseSensor(memPhysical->sensor("used")); - usedLevel->setDescription(i18n("Percentage of used memory.")); + usedLevel->setDescription(i18nc("@info", "Percentage of used memory.")); - PercentageSensor *availableLevel = new PercentageSensor(memPhysical, "availablelevel", i18n("Available Memory Percentage")); - availableLevel->setShortName(i18n("Available")); + PercentageSensor *availableLevel = new PercentageSensor(memPhysical, "availablelevel", i18nc("@title", "Available Memory Percentage")); + availableLevel->setShortName(i18nc("@title Available Memory Percentage", "Available")); availableLevel->setBaseSensor(memPhysical->sensor("available")); - availableLevel->setDescription(i18n("Percentage of used memory.")); + availableLevel->setDescription(i18nc("@info", "Percentage of available memory.")); - PercentageSensor *allocatedLevel = new PercentageSensor(memPhysical, "allocatedlevel", i18n("Allocated Memory Percentage")); - allocatedLevel->setShortName(i18n("Used")); + PercentageSensor *allocatedLevel = new PercentageSensor(memPhysical, "allocatedlevel", i18nc("@title", "Allocated Memory Percentage")); + allocatedLevel->setShortName(i18nc("@title Allocated Memory Percentage", "Used")); allocatedLevel->setBaseSensor(memPhysical->sensor("allocated")); - allocatedLevel->setDescription(i18n("Percentage of used memory.")); + allocatedLevel->setDescription(i18nc("@info", "Percentage of allocated memory.")); } QString KSGRDIface::shortNameFor(const QString &key) { // TODO: This is pretty ugly, but it is really hard to add this information to ksysguardd. // So for now, we just map sensor ids to short names and return that. static QHash shortNames = { - { QStringLiteral("cpu/system/TotalLoad"), i18n("Usage") }, - { QStringLiteral("mem/physical/used"), i18n("Total Used") }, - { QStringLiteral("mem/physical/cached"), i18n("Cached") }, - { QStringLiteral("mem/physical/free"), i18n("Free") }, - { QStringLiteral("mem/physical/available"), i18n("Avalable") }, - { QStringLiteral("mem/physical/application"), i18n("Application") }, - { QStringLiteral("mem/physical/buf"), i18n("Buffer") }, - { QStringLiteral("cpu/system/processors"), i18n("Processors") }, - { QStringLiteral("cpu/system/cores"), i18n("Cores") }, + { QStringLiteral("cpu/system/TotalLoad"), i18nc("@title Total CPU Usage", "Usage") }, + { QStringLiteral("mem/physical/used"), i18nc("@title Total Memory Usage", "Total Used") }, + { QStringLiteral("mem/physical/cached"), i18nc("@title Cached Memory Usage", "Cached") }, + { QStringLiteral("mem/physical/free"), i18nc("@title Free Memory Amount", "Free") }, + { QStringLiteral("mem/physical/available"), i18nc("@title Available Memory Amount", "Avalable") }, + { QStringLiteral("mem/physical/application"), i18nc("@title Application Memory Usage", "Application") }, + { QStringLiteral("mem/physical/buf"), i18nc("@title Buffer Memory Usage", "Buffer") }, + { QStringLiteral("cpu/system/processors"), i18nc("@title Number of Processors", "Processors") }, + { QStringLiteral("cpu/system/cores"), i18nc("@title Number of Cores", "Cores") }, }; return shortNames.value(key, QString {}); } K_PLUGIN_FACTORY(KSGRDPluginFactory, registerPlugin();) #include "ksgrdiface.moc" diff --git a/plugins/global/nvidia/nvidia.cpp b/plugins/global/nvidia/nvidia.cpp index 7c0d45c5..c12d6421 100644 --- a/plugins/global/nvidia/nvidia.cpp +++ b/plugins/global/nvidia/nvidia.cpp @@ -1,172 +1,182 @@ /* Copyright (c) 2019 David Edmundson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "nvidia.h" #include #include #include #include #include #include class GPU : public SensorObject { public: GPU(int index, SensorContainer *parent); ~GPU() = default; SensorProperty *powerProperty() const { return m_pwr; } SensorProperty *tempProperty() const { return m_temp; } SensorProperty *sharedMemory() const { return m_sm; } SensorProperty *memory() const { return m_mem; } SensorProperty *encoder() const { return m_enc; } SensorProperty *decoder() const { return m_dec; } SensorProperty *memoryClock() const { return m_memClock; } SensorProperty *processorClock() const { return m_processorClock; } private: SensorProperty *m_pwr; SensorProperty *m_temp; SensorProperty *m_sm; SensorProperty *m_mem; SensorProperty *m_enc; SensorProperty *m_dec; SensorProperty *m_memClock; SensorProperty *m_processorClock; }; GPU::GPU(int index, SensorContainer *parent) - : SensorObject(QStringLiteral("gpu%1").arg(index), i18n("GPU %1", index), parent) + : SensorObject(QStringLiteral("gpu%1").arg(index), i18nc("@title", "GPU %1", index + 1), parent) { + auto displayIndex = index + 1; + m_pwr = new SensorProperty(QStringLiteral("power"), this); - m_pwr->setName(i18n("Power")); + m_pwr->setName(i18nc("@title", "GPU %1 Power Usage", displayIndex)); + m_pwr->setShortName(i18nc("@title GPU Power Usage", "Power")); m_pwr->setUnit(KSysGuard::utils::UnitWatt); m_pwr->setVariantType(QVariant::UInt); m_temp = new SensorProperty(QStringLiteral("temperature"), this); - m_temp->setName(i18n("Temperature")); + m_temp->setName(i18nc("@title", "GPU %1 Temperature", displayIndex)); + m_temp->setShortName(i18nc("@title GPU Temperature", "Temperature")); m_temp->setUnit(KSysGuard::utils::UnitCelsius); m_temp->setVariantType(QVariant::Double); m_sm = new SensorProperty(QStringLiteral("sharedMemory"), this); - m_sm->setName(i18n("Shared memory")); + m_sm->setName(i18nc("@title", "GPU %1 Shared Memory Usage", displayIndex)); + m_sm->setShortName(i18nc("@title GPU Shared Memory Usage", "Shared Memory")); m_sm->setUnit(KSysGuard::utils::UnitPercent); m_sm->setVariantType(QVariant::UInt); m_mem = new SensorProperty(QStringLiteral("memory"), this); - m_mem->setName(i18n("Memory")); + m_mem->setName(i18nc("@title", "GPU %1 Memory Usage", displayIndex)); + m_mem->setShortName(i18nc("@title GPU Memory Usage", "Memory")); m_mem->setUnit(KSysGuard::utils::UnitPercent); m_mem->setVariantType(QVariant::UInt); m_enc = new SensorProperty(QStringLiteral("encoderUsage"), this); - m_enc->setName(i18n("Encoder")); + m_enc->setName(i18nc("@title", "GPU %1 Encoder Usage", displayIndex)); + m_enc->setShortName(i18nc("@title GPU Encoder Usage", "Encoder")); m_enc->setUnit(KSysGuard::utils::UnitPercent); m_enc->setVariantType(QVariant::UInt); m_dec = new SensorProperty(QStringLiteral("decoderUsage"), this); - m_dec->setName(i18n("Decoder")); + m_dec->setName(i18nc("@title", "GPU %1 Decoder Usage", displayIndex)); + m_dec->setShortName(i18nc("@title GPU Decoder Usage", "Decoder")); m_dec->setUnit(KSysGuard::utils::UnitPercent); m_dec->setVariantType(QVariant::UInt); m_memClock = new SensorProperty(QStringLiteral("memoryClock"), this); - m_memClock->setName(i18n("Memory clock")); + m_memClock->setName(i18nc("@title", "GPU %1 Memory Clock", displayIndex)); + m_memClock->setName(i18nc("@title GPU Memory Clock", "Memory Clock")); m_memClock->setUnit(KSysGuard::utils::UnitMegaHertz); m_memClock->setVariantType(QVariant::UInt); m_processorClock = new SensorProperty(QStringLiteral("processorClock"), this); - m_processorClock->setName(i18n("Processor clock")); + m_processorClock->setName(i18nc("@title", "GPU %1 Processor Clock", displayIndex)); + m_processorClock->setName(i18nc("@title GPU Processor Clock", "Processor Clock")); m_processorClock->setUnit(KSysGuard::utils::UnitMegaHertz); m_processorClock->setVariantType(QVariant::UInt); } NvidiaPlugin::NvidiaPlugin(QObject *parent, const QVariantList &args) : SensorPlugin(parent, args) { const auto sniExecutable = QStandardPaths::findExecutable("nvidia-smi"); if (sniExecutable.isEmpty()) { return; } - auto gpuSystem = new SensorContainer("nvidia", "Nvidia", this); + auto gpuSystem = new SensorContainer("nvidia", i18nc("@title NVidia GPU information", "NVidia"), this); //assuming just one GPU for now auto gpu0 = new GPU(0, gpuSystem); connect(gpu0, &SensorObject::subscribedChanged, this, &NvidiaPlugin::gpuSubscriptionChanged); m_gpus[0] = gpu0; m_process = new QProcess(this); m_process->setProgram(sniExecutable); m_process->setArguments({ QStringLiteral("dmon") }); connect(m_process, &QProcess::readyReadStandardOutput, this, [=]() { while (m_process->canReadLine()) { const QString line = m_process->readLine(); if (line.startsWith(QLatin1Char('#'))) { continue; } const QVector parts = line.splitRef(QLatin1Char(' '), Qt::SkipEmptyParts); // format at time of writing is // # gpu pwr gtemp mtemp sm mem enc dec mclk pclk if (parts.count() != 10) { continue; } bool ok; int index = parts[0].toInt(&ok); if (!ok) { continue; } GPU *gpu = m_gpus.value(index); if (!gpu) { continue; } gpu->powerProperty()->setValue(parts[1].toUInt()); gpu->tempProperty()->setValue(parts[2].toUInt()); // I have no idea what parts[3] mtemp represents..skipping for now gpu->sharedMemory()->setValue(parts[4].toUInt()); gpu->memory()->setValue(parts[5].toUInt()); gpu->encoder()->setValue(parts[6].toUInt()); gpu->decoder()->setValue(parts[7].toUInt()); gpu->memoryClock()->setValue(parts[8].toUInt()); gpu->processorClock()->setValue(parts[9].toUInt()); } }); } void NvidiaPlugin::gpuSubscriptionChanged(bool subscribed) { if (subscribed) { m_activeWatcherCount++; if (m_activeWatcherCount == 1) { m_process->start(); } } else { m_activeWatcherCount--; if (m_activeWatcherCount == 0) { m_process->terminate(); } } } K_PLUGIN_FACTORY(PluginFactory, registerPlugin();) #include "nvidia.moc" diff --git a/plugins/process/network/network.cpp b/plugins/process/network/network.cpp index cca6a7d8..2921fe3f 100644 --- a/plugins/process/network/network.cpp +++ b/plugins/process/network/network.cpp @@ -1,119 +1,119 @@ /* * This file is part of KSysGuard. * Copyright 2019 Arjen Hiemstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "network.h" #include #include #include #include #include #include #include #include #include "networklogging.h" #include "networkconstants.h" using namespace KSysGuard; NetworkPlugin::NetworkPlugin(QObject *parent, const QVariantList &args) : ProcessDataProvider(parent, args) { const auto executable = NetworkConstants::HelperLocation; if (!QFile::exists(executable)) { qCWarning(KSYSGUARD_PLUGIN_NETWORK) << "Could not find ksgrd_network_helper"; return; } qCDebug(KSYSGUARD_PLUGIN_NETWORK) << "Network plugin loading"; qCDebug(KSYSGUARD_PLUGIN_NETWORK) << "Found helper at" << qPrintable(executable); - m_inboundSensor = new ProcessAttribute(QStringLiteral("netInbound"), i18n("Download Speed"), this); - m_inboundSensor->setShortName(i18n("Download")); + m_inboundSensor = new ProcessAttribute(QStringLiteral("netInbound"), i18nc("@title", "Download Speed"), this); + m_inboundSensor->setShortName(i18nc("@title", "Download")); m_inboundSensor->setUnit(KSysGuard::UnitByteRate); m_inboundSensor->setVisibleByDefault(true); - m_outboundSensor = new ProcessAttribute(QStringLiteral("netOutbound"), i18n("Upload Speed"), this); - m_outboundSensor->setShortName(i18n("Upload")); + m_outboundSensor = new ProcessAttribute(QStringLiteral("netOutbound"), i18nc("@title", "Upload Speed"), this); + m_outboundSensor->setShortName(i18nc("@title", "Upload")); m_outboundSensor->setUnit(KSysGuard::UnitByteRate); m_outboundSensor->setVisibleByDefault(true); addProcessAttribute(m_inboundSensor); addProcessAttribute(m_outboundSensor); m_process = new QProcess(this); m_process->setProgram(executable); connect(m_process, QOverload::of(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus status) { if (exitCode != 0 || status != QProcess::NormalExit) { qCWarning(KSYSGUARD_PLUGIN_NETWORK) << "Helper process terminated abnormally!"; qCWarning(KSYSGUARD_PLUGIN_NETWORK) << m_process->readAllStandardError(); } }); connect(m_process, &QProcess::readyReadStandardOutput, this, [=]() { while (m_process->canReadLine()) { const QString line = QString::fromUtf8(m_process->readLine()); // Each line consists of: timestamp|PID|pid|IN|in_bytes|OUT|out_bytes #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) const auto parts = line.splitRef(QLatin1Char('|'), QString::SkipEmptyParts); #else const auto parts = line.splitRef(QLatin1Char('|'), Qt::SkipEmptyParts); #endif if (parts.size() < 7) { continue; } long pid = parts.at(2).toLong(); auto timeStamp = QDateTime::currentDateTimeUtc(); timeStamp.setTime(QTime::fromString(parts.at(0).toString(), QStringLiteral("HH:mm:ss"))); auto bytesIn = parts.at(4).toUInt(); auto bytesOut = parts.at(6).toUInt(); auto process = getProcess(pid); if (!process) { return; } m_inboundSensor->setData(process, bytesIn); m_outboundSensor->setData(process, bytesOut); } }); } void NetworkPlugin::handleEnabledChanged(bool enabled) { if (enabled) { qCDebug(KSYSGUARD_PLUGIN_NETWORK) << "Network plugin enabled, starting helper"; m_process->start(); } else { qCDebug(KSYSGUARD_PLUGIN_NETWORK) << "Network plugin disabled, stopping helper"; m_process->terminate(); } } K_PLUGIN_FACTORY_WITH_JSON(PluginFactory, "networkplugin.json", registerPlugin();) #include "network.moc"