diff options
author | Daniel d'Andrada <daniel.dandrada@luxoft.com> | 2018-01-26 13:48:03 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2018-02-02 08:18:56 +0000 |
commit | 2c25646930b20b176a0925cb49517eedddf04169 (patch) | |
tree | f654672dab6d1882c16f0f36b488f4a2ff249f26 | |
parent | bad6f90edc1cf0fac97b2c0f1918039fc0eb4435 (diff) | |
download | qtapplicationmanager-2c25646930b20b176a0925cb49517eedddf04169.tar.gz |
SystemMonitor: add cpuLoad and memoryUsed properties
If application code is interested only in the latest readings it currently has
to deal with signals from SystemMonitor. But it's way more convenient and
natural for QML code to manipulate properties than signals as the former leads
to declarative code.
Change-Id: I8cd2f8ee6410ac2620f7a1d6ee3d4bed759e91c2
Reviewed-by: Vladimir Minenko <vladimir.minenko@pelagicore.com>
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | src/monitor-lib/systemmonitor.cpp | 48 | ||||
-rw-r--r-- | src/monitor-lib/systemmonitor.h | 4 |
2 files changed, 46 insertions, 6 deletions
diff --git a/src/monitor-lib/systemmonitor.cpp b/src/monitor-lib/systemmonitor.cpp index fef6e28e..c867cd82 100644 --- a/src/monitor-lib/systemmonitor.cpp +++ b/src/monitor-lib/systemmonitor.cpp @@ -178,6 +178,13 @@ */ /*! + \qmlproperty int SystemMonitor::memoryUsed + \readonly + + This property holds the amount of physical memory (RAM) used in bytes. +*/ + +/*! \qmlproperty int SystemMonitor::cpuCores \readonly @@ -185,6 +192,14 @@ */ /*! + \qmlproperty int SystemMonitor::cpuLoad + \readonly + + This property holds the current CPU utilization as a value ranging from 0 (inclusive, completely + idle) to 1 (inclusive, fully busy). +*/ + +/*! \qmlproperty bool SystemMonitor::memoryReportingEnabled A boolean value that determines whether periodic memory reporting is enabled. @@ -339,6 +354,14 @@ public: // model QHash<int, QByteArray> roleNames; + int latestReportPos() const + { + if (reportPos == 0) + return reports.size() - 1; + else + return reportPos - 1; + } + XProcessMonitor *getProcess(const QString &appId) { Q_Q(SystemMonitor); @@ -433,9 +456,7 @@ public: reportProcess = !reportProcess; if (reportCpu) { - qreal cpuVal = cpu->readLoadValue(); - emit q->cpuLoadReportingChanged(cpuVal); - r.cpuLoad = cpuVal; + r.cpuLoad = cpu->readLoadValue(); roles.append(CpuLoad); } else if (cpuTail > 0) { --cpuTail; @@ -443,9 +464,7 @@ public: } if (reportMem) { - quint64 memVal = memory->readUsedValue(); - emit q->memoryReportingChanged(memVal); - r.memoryUsed = memVal; + r.memoryUsed = memory->readUsedValue(); roles.append(MemoryUsed); } else if (memTail > 0) { --memTail; @@ -501,6 +520,11 @@ public: q->endMoveRows(); q->dataChanged(q->index(0), q->index(0), roles); + if (reportMem) + emit q->memoryReportingChanged(r.memoryUsed); + if (reportCpu) + emit q->cpuLoadReportingChanged(r.cpuLoad); + setupTimer(); // we might be able to stop this timer, when end of tail reached } else if (te && te->timerId() == idleTimerId) { @@ -705,11 +729,23 @@ quint64 SystemMonitor::totalMemory() const return d->memory->totalValue(); } +quint64 SystemMonitor::memoryUsed() const +{ + Q_D(const SystemMonitor); + return d->reports[d->latestReportPos()].memoryUsed; +} + int SystemMonitor::cpuCores() const { return QThread::idealThreadCount(); } +qreal SystemMonitor::cpuLoad() const +{ + Q_D(const SystemMonitor); + return d->reports[d->latestReportPos()].cpuLoad; +} + /*! \qmlmethod bool SystemMonitor::setMemoryWarningThresholds(real lowWarning, real criticalWarning); diff --git a/src/monitor-lib/systemmonitor.h b/src/monitor-lib/systemmonitor.h index 34c4b61f..49b9c6a4 100644 --- a/src/monitor-lib/systemmonitor.h +++ b/src/monitor-lib/systemmonitor.h @@ -60,7 +60,9 @@ class SystemMonitor : public QAbstractListModel Q_PROPERTY(int reportingRange READ reportingRange WRITE setReportingRange NOTIFY reportingRangeChanged) // deprecated Q_PROPERTY(qreal idleLoadThreshold READ idleLoadThreshold WRITE setIdleLoadThreshold NOTIFY idleLoadThresholdChanged) Q_PROPERTY(quint64 totalMemory READ totalMemory CONSTANT) + Q_PROPERTY(quint64 memoryUsed READ memoryUsed NOTIFY memoryReportingChanged) Q_PROPERTY(int cpuCores READ cpuCores CONSTANT) + Q_PROPERTY(qreal cpuLoad READ cpuLoad NOTIFY cpuLoadReportingChanged) Q_PROPERTY(bool memoryReportingEnabled READ isMemoryReportingEnabled WRITE setMemoryReportingEnabled NOTIFY memoryReportingEnabledChanged) Q_PROPERTY(bool cpuLoadReportingEnabled READ isCpuLoadReportingEnabled WRITE setCpuLoadReportingEnabled NOTIFY cpuLoadReportingEnabledChanged) Q_PROPERTY(bool fpsReportingEnabled READ isFpsReportingEnabled WRITE setFpsReportingEnabled NOTIFY fpsReportingEnabledChanged) @@ -83,7 +85,9 @@ public: Q_INVOKABLE QVariantMap get(int index) const; quint64 totalMemory() const; + quint64 memoryUsed() const; int cpuCores() const; + qreal cpuLoad() const; void setIdleLoadThreshold(qreal loadThreshold); qreal idleLoadThreshold() const; |