diff options
author | Bernd Weimer <bernd.weimer@qt.io> | 2023-05-11 15:17:20 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-05-15 17:22:11 +0000 |
commit | 0bba42383835e71a90ca2063c98465863c12c82e (patch) | |
tree | 66286854ec38c2330796f0b8b189174b1bedd956 | |
parent | 1f14372e609dea84078a4d5ee3d0ca1acfde9dbb (diff) | |
download | qtapplicationmanager-0bba42383835e71a90ca2063c98465863c12c82e.tar.gz |
Fix some more obvious issues in GPU reader
Reference count has been fixed to properly terminate underlying GPU
memory tracing process, no warning is printed any more when the process
finishes and parsing intel_gpu_top output has been adapted to pick the
actual load value (subject to future changes in the tool).
Change-Id: I7f02e7b48b826da2d6b10f1d67470b560a3c7c21
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
(cherry picked from commit 880837be13cec8784a771b0b32ebb30be6da676f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/monitor-lib/systemreader.cpp | 41 | ||||
-rw-r--r-- | src/shared-main-lib/gpustatus.cpp | 5 | ||||
-rw-r--r-- | src/shared-main-lib/gpustatus.h | 1 |
3 files changed, 20 insertions, 27 deletions
diff --git a/src/monitor-lib/systemreader.cpp b/src/monitor-lib/systemreader.cpp index 64088bce..e141c39b 100644 --- a/src/monitor-lib/systemreader.cpp +++ b/src/monitor-lib/systemreader.cpp @@ -210,22 +210,19 @@ public: setArguments({ qSL("dmon"), qSL("--select"), qSL("u") }); } - QObject::connect(this, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), - this, [this](int exitCode, QProcess::ExitStatus) { - if (m_refCount) { - qCWarning(LogSystem) << "Failed to run GPU monitoring tool:" - << program() << arguments().join(qSL(" ")) << " - " - << "exited with code:" << exitCode; - } + connect(this, static_cast<void(QProcess::*)(QProcess::ProcessError error)>(&QProcess::errorOccurred), + this, [this](QProcess::ProcessError error) { + if (m_refCount) + qCWarning(LogSystem) << "GPU monitoring tool:" << program() << "caused error:" << error; }); - QObject::connect(this, &QProcess::readyReadStandardOutput, this, [this]() { + connect(this, &QProcess::readyReadStandardOutput, this, [this]() { while (canReadLine()) { const QByteArray str = readLine(); if (str.isEmpty() || (str.at(0) == '#')) continue; - int pos = 0; + int pos = (GpuVendor::get() == GpuVendor::Intel) ? 50 : 0; QVector<qreal> values; while (pos < str.size() && values.size() < 2) { @@ -246,11 +243,11 @@ public: switch (GpuVendor::get()) { case GpuVendor::Intel: - if (values.size() >= 2) - m_lastValue = values.at(1) / 100; + if (values.size() > 0) + m_lastValue = values.at(0) / 100; break; case GpuVendor::Nvidia: - if (values.size() >= 2) { + if (values.size() > 1) { if (qFuzzyIsNull(values.at(0))) // hardcoded to first gfx card m_lastValue = values.at(1) / 100; } @@ -265,25 +262,15 @@ public: void ref() { - if (m_refCount.ref()) { - if (!isRunning()) { - start(QIODevice::ReadOnly); - if (!waitForStarted(2000)) { - qCWarning(LogSystem) << "Could not start GPU monitoring tool:" - << program() << arguments().join(qSL(" ")) << " - " - << errorString(); - } - } - } + if (m_refCount.ref() && !isRunning()) + start(QIODevice::ReadOnly); } void deref() { - if (!m_refCount.deref()) { - if (isRunning()) { - kill(); - waitForFinished(); - } + if (!m_refCount.deref() && isRunning()) { + kill(); + waitForFinished(); } } diff --git a/src/shared-main-lib/gpustatus.cpp b/src/shared-main-lib/gpustatus.cpp index c5ff6d9a..72696ece 100644 --- a/src/shared-main-lib/gpustatus.cpp +++ b/src/shared-main-lib/gpustatus.cpp @@ -94,6 +94,11 @@ GpuStatus::GpuStatus(QObject *parent) m_gpuReader->setActive(true); } +GpuStatus::~GpuStatus() +{ + m_gpuReader->setActive(false); +} + /*! \qmlproperty real GpuStatus::gpuLoad \readonly diff --git a/src/shared-main-lib/gpustatus.h b/src/shared-main-lib/gpustatus.h index 2a0df87d..06eb5b83 100644 --- a/src/shared-main-lib/gpustatus.h +++ b/src/shared-main-lib/gpustatus.h @@ -63,6 +63,7 @@ class GpuStatus : public QObject public: GpuStatus(QObject *parent = nullptr); + ~GpuStatus() override; qreal gpuLoad() const; |