fix: fix nvidia update interval on config change + more robust read path for generic
This commit is contained in:
@@ -1,31 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "tickingservice.hpp"
|
||||
#include "config/enums.hpp"
|
||||
|
||||
#include <qprocess.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
namespace ZShell::services {
|
||||
|
||||
using GpuType = config::GpuType::Enum;
|
||||
|
||||
struct VramFiles {
|
||||
QString used;
|
||||
QString total;
|
||||
};
|
||||
|
||||
class Gpu : public TickingService {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
Auto, // user override is empty (config "") — defer to detected autoType
|
||||
None, // no usable GPU
|
||||
Nvidia, // queried via nvidia-smi
|
||||
Generic, // queried via /sys/class/drm/card*/device/gpu_busy_percent
|
||||
};
|
||||
Q_ENUM(Type)
|
||||
|
||||
private:
|
||||
Q_PROPERTY(Type type READ type NOTIFY typeChanged)
|
||||
Q_PROPERTY(Type userType READ userType NOTIFY userTypeChanged)
|
||||
Q_PROPERTY(Type autoType READ autoType NOTIFY autoTypeChanged)
|
||||
Q_PROPERTY(GpuType type READ type NOTIFY typeChanged)
|
||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||
Q_PROPERTY(bool detecting READ detecting NOTIFY detectingChanged)
|
||||
Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
|
||||
Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged)
|
||||
Q_PROPERTY(qreal memoryUsed READ memoryUsed NOTIFY memoryUsedChanged)
|
||||
@@ -33,11 +31,11 @@ class Gpu : public TickingService {
|
||||
|
||||
public:
|
||||
explicit Gpu(QObject* parent = nullptr);
|
||||
~Gpu() override;
|
||||
|
||||
[[nodiscard]] Type type() const;
|
||||
[[nodiscard]] Type userType() const;
|
||||
[[nodiscard]] Type autoType() const;
|
||||
[[nodiscard]] GpuType type() const;
|
||||
[[nodiscard]] QString name() const;
|
||||
[[nodiscard]] bool detecting() const;
|
||||
[[nodiscard]] qreal percentage() const;
|
||||
[[nodiscard]] qreal temperature() const;
|
||||
[[nodiscard]] qreal memoryUsed() const;
|
||||
@@ -45,9 +43,8 @@ class Gpu : public TickingService {
|
||||
|
||||
signals:
|
||||
void typeChanged();
|
||||
void userTypeChanged();
|
||||
void autoTypeChanged();
|
||||
void nameChanged();
|
||||
void detectingChanged();
|
||||
void percentageChanged();
|
||||
void temperatureChanged();
|
||||
void memoryUsedChanged();
|
||||
@@ -55,35 +52,52 @@ class Gpu : public TickingService {
|
||||
|
||||
protected:
|
||||
void tick() override;
|
||||
void onStopped() override;
|
||||
|
||||
private:
|
||||
void detectTypeOnce();
|
||||
void detectNameOnce();
|
||||
void resolveGpu();
|
||||
|
||||
[[nodiscard]] int probeEnd() const;
|
||||
|
||||
void tryNameSource(int index, int generation);
|
||||
void finishNameSource(int index, int generation, QString name);
|
||||
|
||||
void readGenericUsage();
|
||||
void stopNvidiaUsage();
|
||||
void startNvidiaUsage();
|
||||
void readGpuTemperature();
|
||||
void readGenericMemory();
|
||||
void resetUsage();
|
||||
|
||||
void setUserType(Type value);
|
||||
void setAutoType(Type value);
|
||||
void runProcess(
|
||||
const QString& program,
|
||||
const QStringList& args,
|
||||
std::function<void(const QByteArray&)> callback);
|
||||
|
||||
void setType(GpuType value);
|
||||
void setName(QString value);
|
||||
void setDetecting(bool value);
|
||||
void setMemoryUsed(qreal value);
|
||||
void setMemoryTotal(qreal value);
|
||||
|
||||
[[nodiscard]] static Type parseType(const QString& s);
|
||||
[[nodiscard]] static QString cleanName(QString s);
|
||||
void refreshSysfsCache();
|
||||
|
||||
Type m_userType = Auto;
|
||||
Type m_autoType = None;
|
||||
GpuType m_userType = GpuType::Auto;
|
||||
GpuType m_type = GpuType::None;
|
||||
QString m_name;
|
||||
bool m_detecting = false;
|
||||
qreal m_percentage = 0.0;
|
||||
qreal m_temperature = 0.0;
|
||||
qreal m_memoryUsed = 0.0;
|
||||
qreal m_memoryTotal = 0.0;
|
||||
|
||||
QProcess* m_typeProc = nullptr;
|
||||
QProcess* m_nameProc = nullptr;
|
||||
QStringList m_busyFiles;
|
||||
QList<VramFiles> m_vramFiles;
|
||||
int m_generation = 0;
|
||||
bool m_nvidiaQuerying = false;
|
||||
|
||||
QProcess* m_nvidiaProc = nullptr;
|
||||
QTimer* m_restartTimer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ZShell::services
|
||||
|
||||
Reference in New Issue
Block a user