Skip to content
Merged
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
3 changes: 1 addition & 2 deletions deepin-devicemanager-server/customgpuinfo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ bool getGpuMemInfoForFTDTM(QMap<QString, QString> &mapInfo)
int main(int argc, char *argv[])
{
QMap<QString, QString> mapInfo;
if (getGpuBaseInfo(mapInfo)) {
getGpuMemInfoForFTDTM(mapInfo);
Comment on lines -101 to -102
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: getGpuMemInfoForFTDTM return value is now used for conditional logic.

Please verify that error handling and fallback logic remain correct if getGpuMemInfoForFTDTM fails.

if (getGpuMemInfoForFTDTM(mapInfo)) {
for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it)
std::cout << it.key().toStdString() << ": " << it.value().toStdString() << std::endl;
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,22 @@ void DeviceInterface::setMonitorDeviceFlag(bool flag)

QString DeviceInterface::getGpuInfoByCustom(const QString &cmd, const QStringList &arguments)
{
static bool firstFlag = true;
static QString gpuinfo;
if (firstFlag) {
firstFlag = false;

QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
if (arguments.size() > 1) {
env.insert("DISPLAY", arguments[0]);
env.insert("XAUTHORITY", arguments[1]);
}
process.setProcessEnvironment(env);
process.start(cmd, arguments);
if (!process.waitForFinished(4000)) {
qCritical() << QString("Error executing %1 :").arg(cmd) << process.errorString();
return gpuinfo;
}

if (process.exitCode() == 0)
gpuinfo = QString::fromLocal8Bit(process.readAllStandardOutput());
QString gpuinfo;
QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
if (arguments.size() > 1) {
env.insert("DISPLAY", arguments[0]);
env.insert("XAUTHORITY", arguments[1]);
}
process.setProcessEnvironment(env);
process.start(cmd, arguments);
if (!process.waitForFinished()) {
qCritical() << QString("Error executing %1 :").arg(cmd) << process.errorString();
return gpuinfo;
}

if (process.exitCode() == 0)
gpuinfo = QString::fromLocal8Bit(process.readAllStandardOutput());

return gpuinfo;
}
13 changes: 1 addition & 12 deletions deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,7 @@ void CustomGenerator::generatorGpuDevice()
return;
}

QStringList arguments;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString display = env.value("DISPLAY");
QString xauthority = env.value("XAUTHORITY");
if (display.isEmpty() || xauthority.isEmpty()) {
qWarning() << "DISPLAY or XAUTHORITY is not set!";
} else {
arguments << display << xauthority;
}

QString tmpGpuInfo;
DBusInterface::getInstance()->getGpuInfoByCustom(cmd, arguments, tmpGpuInfo);
QString tmpGpuInfo = CommonTools::preGenerateGpuInfo();
if (tmpGpuInfo.isEmpty()) {
qCritical() << "Failed to get gpu info by commad " << cmd;
return;
Expand Down
79 changes: 79 additions & 0 deletions deepin-devicemanager/src/Tool/commontools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ using namespace DDLog;
#define ICON_SIZE_WIDTH 36
#define ICON_SIZE_HEIGHT 36

// 名称("Name") 厂商("Vendor") 型号("Model") 版本(Version) 显存("Graphics Memory")

constexpr char kName[] { "Name" };
constexpr char kVendor[] { "Vendor" };
constexpr char kModel[] { "Model" };
constexpr char kVersion[] { "Version" };
constexpr char kGraphicsMemory[] { "Graphics Memory" };

QMap<DriverType, QString> CommonTools::m_MapDriverIcon = {
{DR_Bluetooth, QString(":/icons/deepin/builtin/icons/bluetooth.svg")}
, {DR_Camera, QString(":/icons/deepin/builtin/icons/image.svg")}
Expand Down Expand Up @@ -257,3 +265,74 @@ QString CommonTools::getGpuInfoCommandFromDConfig()
cmd = dconfig->value("CommandToGetGPUInfo").toString();
return cmd;
}

QString CommonTools::preGenerateGpuInfo()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Static caching of GPU info may cause stale data if environment changes.

Caching with a static QString prevents updates if DISPLAY or XAUTHORITY change. Please review if caching is required, or implement invalidation when these environment variables are modified.

{
static QString gpuInfo { "" };

if (gpuInfo.isEmpty()) {
QStringList arguments;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString display = env.value("DISPLAY");
QString xauthority = env.value("XAUTHORITY");
if (display.isEmpty() || xauthority.isEmpty()) {
qCritical() << "DISPLAY or XAUTHORITY is not set!";
} else {
arguments << display << xauthority;
}

QDBusInterface iface("org.deepin.DeviceInfo",
"/org/deepin/DeviceInfo",
"org.deepin.DeviceInfo",
QDBusConnection::systemBus());
if (iface.isValid()) {
QDBusReply<QString> replyList = iface.call("getGpuInfoByCustom", arguments, gpuInfo);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Passing gpuInfo as an argument to DBus call may be unnecessary.

Please verify whether gpuInfo should be passed as an input to the DBus method, as it seems to be intended as an output parameter.

if (replyList.isValid()) {
gpuInfo = replyList.value();
} else {
qCritical() << "Error: failed to call dbus to get gpu memery info! ";
}
}

QMap<QString, QString> mapInfo;
if (getGpuBaseInfo(mapInfo)) {
for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it) {
QString tmpInfo = it.key() + ": " + it.value() + "\n";
gpuInfo.append(tmpInfo);
}
}
}

return gpuInfo;
}

bool CommonTools::getGpuBaseInfo(QMap<QString, QString> &mapInfo)
{
QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
process.setProcessEnvironment(env);
process.start("/usr/bin/glxinfo", QStringList() << "-B");
if (!process.waitForFinished()) {
qCritical() << "Error executing glxinfo:" << process.errorString();
return false;
}

QString output = QString::fromLocal8Bit(process.readAllStandardOutput());
QStringList lines = output.split('\n');
QRegularExpression regex("^([^:]+):\\s*(.+)$");
for (const QString &line : lines) {
QRegularExpressionMatch match = regex.match(line);
if (match.hasMatch()) {
QString key = match.captured(1).trimmed();
QString value = match.captured(2).trimmed();
if (key == "OpenGL renderer string") {
mapInfo.insert(kName, value);
Comment on lines +328 to +329
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Assigning both kName and kModel to the same value may reduce clarity.

Verify that assigning the same value to both fields matches their intended use and does not cause confusion for downstream consumers.

Suggested implementation:

            if (key == "OpenGL renderer string") {
                // Assign renderer string to kModel, not kName, for clarity
                mapInfo.insert(kModel, value);
            } else if (key == "OpenGL vendor string") {

If you want to provide a more descriptive name for kName, you could use a default value or combine vendor and renderer strings after parsing both. For now, this change ensures that kModel is set to the renderer string, which is typically more appropriate.

mapInfo.insert(kModel, value);
} else if (key == "OpenGL vendor string") {
mapInfo.insert(kVendor, value);
}
}
}

return true;
}
4 changes: 4 additions & 0 deletions deepin-devicemanager/src/Tool/commontools.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class CommonTools : public QObject

static void parseEDID(const QStringList &allEDIDS, const QString &input, bool isHW = true);
static QString getGpuInfoCommandFromDConfig();
static QString preGenerateGpuInfo();

private:
static bool getGpuBaseInfo(QMap<QString, QString> &mapInfo);

signals:

Expand Down
8 changes: 8 additions & 0 deletions deepin-devicemanager/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include "environments.h"
#include "DebugTimeManager.h"
#include "SingleDeviceManager.h"
#include "DDLog.h"

Check warning on line 12 in deepin-devicemanager/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DDLog.h" not found.
#include "commontools.h"

Check warning on line 13 in deepin-devicemanager/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "commontools.h" not found.

#include <DApplication>

Check warning on line 15 in deepin-devicemanager/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DWidgetUtil>

Check warning on line 16 in deepin-devicemanager/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DWidgetUtil> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DLog>

Check warning on line 17 in deepin-devicemanager/src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DLog> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QDBusConnection>
#include <QDBusInterface>
Expand Down Expand Up @@ -110,6 +112,12 @@
if (dbus.registerService("com.deepin.DeviceManagerNotify")) {
dbus.registerObject("/com/deepin/DeviceManagerNotify", &app, QDBusConnection::ExportScriptableSlots);
app.parseCmdLine();

QString cmd = CommonTools::getGpuInfoCommandFromDConfig();
if (!cmd.isEmpty()) {
CommonTools::preGenerateGpuInfo();
}

app.activateWindow();
return app.exec();
} else {
Expand Down