more unfinished changes, process tab for dashboard
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <qfile.h>
|
||||
#include <qregularexpression.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace ZShell::services {
|
||||
|
||||
Memory::Memory(QObject* parent) : TickingService(parent) {}
|
||||
@@ -15,6 +17,18 @@ qreal Memory::total() const {
|
||||
return m_total;
|
||||
}
|
||||
|
||||
qreal Memory::cached() const {
|
||||
return m_cached;
|
||||
}
|
||||
|
||||
qreal Memory::readTotal() const {
|
||||
return m_readTotal;
|
||||
}
|
||||
|
||||
qreal Memory::writeTotal() const {
|
||||
return m_writeTotal;
|
||||
}
|
||||
|
||||
qreal Memory::percentage() const {
|
||||
return m_total > 0.0 ? m_used / m_total : 0.0;
|
||||
}
|
||||
@@ -31,6 +45,8 @@ void Memory::tick() {
|
||||
QStringLiteral("MemTotal: *(\\d+)"));
|
||||
static const QRegularExpression reAvail(
|
||||
QStringLiteral("MemAvailable: *(\\d+)"));
|
||||
static const QRegularExpression reCached(QStringLiteral(
|
||||
"Cached: *(\\d+)"));
|
||||
const QString text = QString::fromLatin1(data);
|
||||
|
||||
const auto totalMatch = reTotal.match(text);
|
||||
@@ -45,14 +61,50 @@ void Memory::tick() {
|
||||
return;
|
||||
}
|
||||
const quint64 usedKib = totalKib > availKib ? totalKib - availKib : 0;
|
||||
const auto cachedMatch = reCached.match(text);
|
||||
const quint64 cachedKib =
|
||||
cachedMatch.hasMatch() ? cachedMatch.captured(1).toULongLong() : 0;
|
||||
|
||||
if (totalKib == m_lastTotal && usedKib == m_lastUsed) {
|
||||
static const QRegularExpression rePgin(QStringLiteral("pgpgin (\\d+)"));
|
||||
static const QRegularExpression rePgout(QStringLiteral("pgpgout (\\d+)"));
|
||||
quint64 readKib = 0;
|
||||
quint64 writeKib = 0;
|
||||
{
|
||||
QFile vf(QStringLiteral("/proc/vmstat"));
|
||||
if (vf.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
const QString vtext = QString::fromLatin1(vf.readAll());
|
||||
vf.close();
|
||||
const double pageKib = getpagesize() / 1024.0;
|
||||
const auto pgin = rePgin.match(vtext);
|
||||
const auto pgout = rePgout.match(vtext);
|
||||
if (pgin.hasMatch()) {
|
||||
readKib = static_cast<quint64>(static_cast<double>(
|
||||
pgin.captured(1).toULongLong()) *
|
||||
pageKib);
|
||||
}
|
||||
if (pgout.hasMatch()) {
|
||||
writeKib = static_cast<quint64>(static_cast<double>(
|
||||
pgout.captured(1).toULongLong()) *
|
||||
pageKib);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalKib == m_lastTotal && usedKib == m_lastUsed &&
|
||||
cachedKib == m_lastCached && readKib == m_lastReadKib &&
|
||||
writeKib == m_lastWriteKib) {
|
||||
return;
|
||||
}
|
||||
m_lastTotal = totalKib;
|
||||
m_lastUsed = usedKib;
|
||||
m_lastCached = cachedKib;
|
||||
m_lastReadKib = readKib;
|
||||
m_lastWriteKib = writeKib;
|
||||
m_total = static_cast<qreal>(totalKib);
|
||||
m_used = static_cast<qreal>(usedKib);
|
||||
m_cached = static_cast<qreal>(cachedKib);
|
||||
m_readTotal = static_cast<qreal>(readKib);
|
||||
m_writeTotal = static_cast<qreal>(writeKib);
|
||||
Q_EMIT changed();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user