mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2026-02-03 06:49:47 +00:00
gpu memory demo
This commit is contained in:
@@ -43,6 +43,10 @@ AWDataEngineMapper::AWDataEngineMapper(QObject *_parent, AWFormatterHelper *_cus
|
||||
m_formatter["uptot"] = AWPluginFormatterMemoryMB::instance();
|
||||
m_formatter["uptotkb"] = AWPluginFormatterMemory::instance();
|
||||
m_formatter["upunits"] = AWPluginFormatterNetUnits::instance();
|
||||
// gpu memory
|
||||
m_formatter["gpumem"] = AWPluginFormatterFloat::instance();
|
||||
m_formatter["gpufreemb"] = AWPluginFormatterMemoryMB::instance();
|
||||
m_formatter["gpufreegb"] = AWPluginFormatterMemoryGB::instance();
|
||||
}
|
||||
|
||||
|
||||
@@ -109,4 +113,12 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
void AWDataEngineMapper::setDevices(const AWPluginMatcherSettings &_settings)
|
||||
{
|
||||
m_settings = _settings;
|
||||
|
||||
// update formatters
|
||||
// gpu memory per device
|
||||
for (auto i = 0; i < m_settings.gpu.count(); ++i) {
|
||||
m_formatter[QString("gpumem%1").arg(i)] = AWPluginFormatterFloat::instance();
|
||||
m_formatter[QString("gpufreemb%1").arg(i)] = AWPluginFormatterMemoryMB::instance();
|
||||
m_formatter[QString("gpufreegb%1").arg(i)] = AWPluginFormatterMemoryGB::instance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,12 +70,12 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
qCDebug(LOG_AW) << "Looking for required keys in" << _keys << _bars << "using tooltip settings" << _tooltip;
|
||||
|
||||
// initial copy
|
||||
QSet<QString> used(_keys.cbegin(), _keys.cend());
|
||||
QSet used(_keys.cbegin(), _keys.cend());
|
||||
used.unite(QSet(_bars.cbegin(), _bars.cend()));
|
||||
used.unite(QSet(_userKeys.cbegin(), _userKeys.cend()));
|
||||
// insert keys from tooltip
|
||||
for (auto [key, value] : _tooltip.asKeyValueRange()) {
|
||||
if ((key.endsWith("Tooltip")) && value.toBool()) {
|
||||
if (key.endsWith("Tooltip") && value.toBool()) {
|
||||
auto local = key;
|
||||
local.remove("Tooltip");
|
||||
used << local;
|
||||
@@ -84,7 +84,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
|
||||
// insert keys which depend on others, refer to AWKeys::calculateValues()
|
||||
// network keys
|
||||
QStringList netKeys(
|
||||
static QStringList netKeys(
|
||||
{"up", "upkb", "uptot", "uptotkb", "upunits", "down", "downkb", "downtot", "downtotkb", "downunits"});
|
||||
for (auto &key : netKeys) {
|
||||
if (!used.contains(key))
|
||||
@@ -96,11 +96,13 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
// netdev key
|
||||
if (std::any_of(netKeys.cbegin(), netKeys.cend(), [&used](auto &key) { return used.contains(key); }))
|
||||
used << "netdev";
|
||||
|
||||
// HACK append dummy if there are no other keys. This hack is required
|
||||
// because empty list leads to the same behaviour as skip checking
|
||||
if (used.isEmpty())
|
||||
used << "dummy";
|
||||
// gpu memory keys
|
||||
static auto gpuMemoryCalculatedRegExp = QRegularExpression("^gpu(mem|freemb|freegb)");
|
||||
for (auto key : _keys.filter(gpuMemoryCalculatedRegExp)) {
|
||||
auto index = key.remove(gpuMemoryCalculatedRegExp);
|
||||
used << QString("gpuusedmb%1").arg(index) << QString("gputotmb%1").arg(index)
|
||||
<< QString("gpuusedgb%1").arg(index) << QString("gputotgb%1").arg(index);
|
||||
}
|
||||
|
||||
return used.values();
|
||||
}
|
||||
|
||||
@@ -85,6 +85,13 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
// gpu
|
||||
for (auto i = 0; i < m_devices.gpu.count(); ++i) {
|
||||
allKeys.append(QString("gpu%1").arg(i));
|
||||
allKeys.append(QString("gpumem%1").arg(i));
|
||||
allKeys.append(QString("gpufreemb%1").arg(i));
|
||||
allKeys.append(QString("gpufreegb%1").arg(i));
|
||||
allKeys.append(QString("gputotmb%1").arg(i));
|
||||
allKeys.append(QString("gputotgb%1").arg(i));
|
||||
allKeys.append(QString("gpuusedmb%1").arg(i));
|
||||
allKeys.append(QString("gpuusedgb%1").arg(i));
|
||||
allKeys.append(QString("gputemp%1").arg(i));
|
||||
}
|
||||
// hdd
|
||||
|
||||
@@ -248,6 +248,19 @@ void AWKeys::calculateValues()
|
||||
m_values["uptotkb"] = m_values[QString("uptotkb%1").arg(netIndex)];
|
||||
m_values["upunits"] = m_values[QString("upunits%1").arg(netIndex)];
|
||||
|
||||
// gpu memory keys
|
||||
m_values["gpufreemb"] = m_values["gputotmb"].toLongLong() - m_values["gpuusedmb"].toLongLong();
|
||||
m_values["gpufreegb"] = m_values["gputotgb"].toDouble() - m_values["gpuusedgb"].toDouble();
|
||||
m_values["gpumem"] = 100.0 * m_values["gpuusedmb"].toDouble() / m_values["gputotmb"].toDouble();
|
||||
for (auto i = 0; i < devices.gpu.count(); ++i) {
|
||||
m_values[QString("gpufreemb%1").arg(i)] = m_values[QString("gputotmb%1").arg(i)].toLongLong()
|
||||
- m_values[QString("gpuusedmb%1").arg(i)].toLongLong();
|
||||
m_values[QString("gpufreegb%1").arg(i)]
|
||||
= m_values[QString("gputotgb%1").arg(i)].toDouble() - m_values[QString("gpuusedgb%1").arg(i)].toDouble();
|
||||
m_values[QString("gpumem%1").arg(i)] = 100.0 * m_values[QString("gpuusedmb%1").arg(i)].toDouble()
|
||||
/ m_values[QString("gputotmb%1").arg(i)].toDouble();
|
||||
}
|
||||
|
||||
// user defined keys
|
||||
for (auto &key : m_keyOperator->userKeys())
|
||||
m_values[key] = m_values[m_keyOperator->userKeySource(key)];
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "awpluginformatterac.h"
|
||||
#include "awpluginformattercustom.h"
|
||||
#include "awpluginformatterdouble.h"
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awpluginmatchergpumemorytotal.h"
|
||||
|
||||
#include "formatters/formatters.h"
|
||||
|
||||
|
||||
QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherGPUMemoryTotal::keys(const QString &, const KSysGuard::Unit,
|
||||
const AWPluginMatcherSettings &) const
|
||||
{
|
||||
return {
|
||||
{"gputotmb", AWPluginFormatterMemoryMB::instance()},
|
||||
{"gputotgb", AWPluginFormatterMemoryGB::instance()},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
bool AWPluginMatcherGPUMemoryTotal::matches(const QString &_source) const
|
||||
{
|
||||
return _source == "gpu/all/totalVram";
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "awpluginmatcher.h"
|
||||
|
||||
|
||||
class AWPluginMatcherGPUMemoryTotal : public AWPluginMatcher<AWPluginMatcherGPUMemoryTotal>
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit,
|
||||
const AWPluginMatcherSettings &) const override;
|
||||
[[nodiscard]] bool matches(const QString &_source) const override;
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awpluginmatchergpumemorytotalcore.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "formatters/formatters.h"
|
||||
|
||||
|
||||
QHash<QString, AWPluginFormaterInterface *>
|
||||
AWPluginMatcherGPUMemoryTotalCore::keys(const QString &_source, const KSysGuard::Unit,
|
||||
const AWPluginMatcherSettings &_settings) const
|
||||
{
|
||||
auto index = AWPluginMatcher::index(_source, _settings.gpu);
|
||||
if (index == -1)
|
||||
return {};
|
||||
|
||||
return {
|
||||
{QString("gputotmb%1").arg(index), AWPluginFormatterMemoryMB::instance()},
|
||||
{QString("gputotgb%1").arg(index), AWPluginFormatterMemoryGB::instance()},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
bool AWPluginMatcherGPUMemoryTotalCore::matches(const QString &_source) const
|
||||
{
|
||||
static auto regexp = QRegularExpression("^gpu/gpu.*/totalVram$");
|
||||
return _source.contains(regexp);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "awpluginmatcher.h"
|
||||
|
||||
|
||||
class AWPluginMatcherGPUMemoryTotalCore : public AWPluginMatcher<AWPluginMatcherGPUMemoryTotalCore>
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] QHash<QString, AWPluginFormaterInterface *>
|
||||
keys(const QString &_source, KSysGuard::Unit, const AWPluginMatcherSettings &_settings) const override;
|
||||
[[nodiscard]] bool matches(const QString &_source) const override;
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awpluginmatchergpumemoryused.h"
|
||||
|
||||
#include "formatters/formatters.h"
|
||||
|
||||
|
||||
QHash<QString, AWPluginFormaterInterface *> AWPluginMatcherGPUMemoryUsed::keys(const QString &, const KSysGuard::Unit,
|
||||
const AWPluginMatcherSettings &) const
|
||||
{
|
||||
return {
|
||||
{"gpuusedmb", AWPluginFormatterMemoryMB::instance()},
|
||||
{"gpuusedgb", AWPluginFormatterMemoryGB::instance()},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
bool AWPluginMatcherGPUMemoryUsed::matches(const QString &_source) const
|
||||
{
|
||||
return _source == "gpu/all/usedVram";
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "awpluginmatcher.h"
|
||||
|
||||
|
||||
class AWPluginMatcherGPUMemoryUsed : public AWPluginMatcher<AWPluginMatcherGPUMemoryUsed>
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] QHash<QString, AWPluginFormaterInterface *> keys(const QString &, KSysGuard::Unit,
|
||||
const AWPluginMatcherSettings &) const override;
|
||||
[[nodiscard]] bool matches(const QString &_source) const override;
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awpluginmatchergpumemoryusedcore.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "formatters/formatters.h"
|
||||
|
||||
|
||||
QHash<QString, AWPluginFormaterInterface *>
|
||||
AWPluginMatcherGPUMemoryUsedCore::keys(const QString &_source, const KSysGuard::Unit,
|
||||
const AWPluginMatcherSettings &_settings) const
|
||||
{
|
||||
auto index = AWPluginMatcher::index(_source, _settings.gpu);
|
||||
if (index == -1)
|
||||
return {};
|
||||
|
||||
return {
|
||||
{QString("gpuusedmb%1").arg(index), AWPluginFormatterMemoryMB::instance()},
|
||||
{QString("gpuusedgb%1").arg(index), AWPluginFormatterMemoryGB::instance()},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
bool AWPluginMatcherGPUMemoryUsedCore::matches(const QString &_source) const
|
||||
{
|
||||
static auto regexp = QRegularExpression("^gpu/gpu.*/usedVram$");
|
||||
return _source.contains(regexp);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "awpluginmatcher.h"
|
||||
|
||||
|
||||
class AWPluginMatcherGPUMemoryUsedCore : public AWPluginMatcher<AWPluginMatcherGPUMemoryUsedCore>
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] QHash<QString, AWPluginFormaterInterface *>
|
||||
keys(const QString &_source, KSysGuard::Unit, const AWPluginMatcherSettings &_settings) const override;
|
||||
[[nodiscard]] bool matches(const QString &_source) const override;
|
||||
};
|
||||
@@ -15,6 +15,8 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "awpluginmatcherac.h"
|
||||
#include "awpluginmatcherbattery.h"
|
||||
#include "awpluginmatcherbrightness.h"
|
||||
@@ -28,6 +30,10 @@
|
||||
#include "awpluginmatcherdesktopnumber.h"
|
||||
#include "awpluginmatchergpu.h"
|
||||
#include "awpluginmatchergpucore.h"
|
||||
#include "awpluginmatchergpumemorytotal.h"
|
||||
#include "awpluginmatchergpumemorytotalcore.h"
|
||||
#include "awpluginmatchergpumemoryused.h"
|
||||
#include "awpluginmatchergpumemoryusedcore.h"
|
||||
#include "awpluginmatchergputemperature.h"
|
||||
#include "awpluginmatcherhdd.h"
|
||||
#include "awpluginmatcherhddfree.h"
|
||||
@@ -80,6 +86,10 @@ static QList<AWPluginMatcherInterface *> matchers = {
|
||||
AWPluginMatcherDesktopNumber::instance(),
|
||||
AWPluginMatcherGPU::instance(),
|
||||
AWPluginMatcherGPUCore::instance(),
|
||||
AWPluginMatcherGPUMemoryTotal::instance(),
|
||||
AWPluginMatcherGPUMemoryTotalCore::instance(),
|
||||
AWPluginMatcherGPUMemoryUsed::instance(),
|
||||
AWPluginMatcherGPUMemoryUsedCore::instance(),
|
||||
AWPluginMatcherGPUTemperature::instance(),
|
||||
AWPluginMatcherHDD::instance(),
|
||||
AWPluginMatcherHDDFree::instance(),
|
||||
|
||||
@@ -70,6 +70,13 @@ static const char STATIC_KEYS[] = "time,"
|
||||
"cpucl,"
|
||||
"cpu,"
|
||||
"gpu,"
|
||||
"gpumem,"
|
||||
"gpufreemb,"
|
||||
"gpufreegb,"
|
||||
"gputotmb,"
|
||||
"gputotgb,"
|
||||
"gpuusedmb,"
|
||||
"gpuusedgb,"
|
||||
"memmb,"
|
||||
"memgb,"
|
||||
"memfreemb,"
|
||||
|
||||
Reference in New Issue
Block a user