Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ set(BACKEND_SOURCES
src/backend/system/capabilityprobe.cpp
src/backend/system/languagemanager.cpp
src/backend/system/uipreferencesmanager.cpp
src/backend/system/systeminfoprovider.cpp
)

set(APP_SOURCES
Expand Down
Binary file modified data/icons/hicolor/256x256/apps/ro-control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 0 additions & 44 deletions data/icons/hicolor/scalable/apps/ro-control-dial-core.svg

This file was deleted.

44 changes: 0 additions & 44 deletions data/icons/hicolor/scalable/apps/ro-control-shield-chip.svg

This file was deleted.

67 changes: 31 additions & 36 deletions data/icons/hicolor/scalable/apps/ro-control.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 157 additions & 2 deletions src/backend/monitor/gpumonitor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "gpumonitor.h"
#include "system/commandrunner.h"

#include <QDir>
#include <QFile>
#include <QRegularExpression>
#include <algorithm>

Expand Down Expand Up @@ -37,6 +39,119 @@ bool parseMetricInt(const QString &field, int *value) {
return true;
}

QString drmRootPath() {
const QString overridePath =
qEnvironmentVariable("RO_CONTROL_DRM_ROOT").trimmed();
return overridePath.isEmpty() ? QStringLiteral("/sys/class/drm")
: overridePath;
}

QString readFileText(const QString &path) {
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return {};
}

return QString::fromUtf8(file.readAll()).trimmed();
}

bool readIntegerFile(const QString &path, qint64 *value) {
if (value == nullptr) {
return false;
}

bool ok = false;
const qint64 parsedValue = readFileText(path).toLongLong(&ok);
if (!ok) {
return false;
}

*value = parsedValue;
return true;
}

bool readFirstTemperatureFromHwmon(const QString &basePath, int *value) {
const QFileInfoList hwmonEntries =
QDir(basePath).entryInfoList({QStringLiteral("hwmon*")},
QDir::Dirs | QDir::NoDotAndDotDot,
QDir::Name);
for (const QFileInfo &entry : hwmonEntries) {
const QFileInfoList inputs = QDir(entry.absoluteFilePath())
.entryInfoList({QStringLiteral("temp*_input")},
QDir::Files, QDir::Name);
for (const QFileInfo &input : inputs) {
qint64 milliC = 0;
if (readIntegerFile(input.absoluteFilePath(), &milliC) && milliC > 0) {
*value = static_cast<int>(milliC / 1000);
return true;
}
}
}

return false;
}

bool readGenericLinuxGpuMetrics(int *temperatureC, int *utilizationPercent,
int *memoryUsedMiB, int *memoryTotalMiB) {
const QFileInfoList cardEntries =
QDir(drmRootPath()).entryInfoList({QStringLiteral("card*")},
QDir::Dirs | QDir::NoDotAndDotDot,
QDir::Name);

bool anyMetric = false;
for (const QFileInfo &cardEntry : cardEntries) {
const QString devicePath =
cardEntry.absoluteFilePath() + QStringLiteral("/device");
if (!QFile::exists(devicePath)) {
continue;
}

int tempValue = 0;
if (temperatureC != nullptr &&
readFirstTemperatureFromHwmon(devicePath, &tempValue)) {
*temperatureC = tempValue;
anyMetric = true;
}

qint64 busyPercent = 0;
if (utilizationPercent != nullptr &&
readIntegerFile(devicePath + QStringLiteral("/gpu_busy_percent"),
&busyPercent)) {
*utilizationPercent =
std::clamp(static_cast<int>(busyPercent), 0, 100);
anyMetric = true;
}

qint64 usedBytes = 0;
qint64 totalBytes = 0;
const bool usedOk =
readIntegerFile(devicePath + QStringLiteral("/mem_info_vram_used"),
&usedBytes);
const bool totalOk =
readIntegerFile(devicePath + QStringLiteral("/mem_info_vram_total"),
&totalBytes);
if (usedOk && totalOk && totalBytes > 0) {
if (memoryUsedMiB != nullptr) {
*memoryUsedMiB =
std::max(0, static_cast<int>(static_cast<qint64>(usedBytes) /
(1024 * 1024)));
}
if (memoryTotalMiB != nullptr) {
*memoryTotalMiB =
std::max(0, static_cast<int>(static_cast<qint64>(totalBytes) /
(1024 * 1024)));
}
anyMetric = true;
}

if (anyMetric) {
return true;
}
}

return false;
}

} // namespace

GpuMonitor::GpuMonitor(QObject *parent) : QObject(parent) {
Expand Down Expand Up @@ -80,8 +195,48 @@ void GpuMonitor::refresh() {
options);

if (!result.success()) {
setAvailable(false);
clearMetrics();
int nextTemp = 0;
int nextUtil = 0;
int nextUsed = 0;
int nextTotal = 0;

if (!readGenericLinuxGpuMetrics(&nextTemp, &nextUtil, &nextUsed,
&nextTotal)) {
setAvailable(false);
clearMetrics();
return;
}

if (m_temperatureC != nextTemp) {
m_temperatureC = nextTemp;
emit temperatureCChanged();
}
if (m_utilizationPercent != nextUtil) {
m_utilizationPercent = nextUtil;
emit utilizationPercentChanged();
}
if (m_memoryUsedMiB != nextUsed) {
m_memoryUsedMiB = nextUsed;
emit memoryUsedMiBChanged();
}
if (m_memoryTotalMiB != nextTotal) {
m_memoryTotalMiB = nextTotal;
emit memoryTotalMiBChanged();
}

const int usagePercent =
nextTotal > 0
? std::clamp(static_cast<int>((static_cast<double>(nextUsed) /
static_cast<double>(nextTotal)) *
100.0),
0, 100)
: 0;
if (m_memoryUsagePercent != usagePercent) {
m_memoryUsagePercent = usagePercent;
emit memoryUsagePercentChanged();
}

setAvailable(true);
return;
}

Expand Down
9 changes: 0 additions & 9 deletions src/backend/monitor/rammonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,6 @@ void RamMonitor::refresh() {
memAvailableKiB = memFreeKiB + buffersKiB + cachedKiB + reclaimable - shmem;
}

// TR: Tutarsiz veri geldiyse metrikleri sifirla ve "unavailable" olarak isle.
// EN: If metrics are inconsistent, clear values and mark monitor unavailable.
if (memTotalKiB <= 0 || memAvailableKiB < 0 ||
memAvailableKiB > memTotalKiB) {
setAvailable(false);
clearMetrics();
return;
}

RamSnapshot snapshot = buildSnapshot(memTotalKiB, memAvailableKiB);
if (!snapshot.valid) {
snapshot = readSnapshotFromFree();
Expand Down
Loading
Loading