Skip to content
Merged
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
51 changes: 19 additions & 32 deletions deepin-devicemanager-server/customgpuinfo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,43 @@ bool getGpuBaseInfo(QMap<QString, QString> &mapInfo)

bool getGpuMemInfoForFTDTM(QMap<QString, QString> &mapInfo)
{
const QString filePath = "/sys/kernel/debug/gc/meminfo";
const QString filePath = "/sys/kernel/debug/gc/total_mem";
Comment thread
GongHeng2017 marked this conversation as resolved.
QString totalValue;
bool foundTotal = false;

QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qCritical() << "Error opening /sys/kernel/debug/gc/meminfo:" << file.errorString();
qCritical() << "Error opening /sys/kernel/debug/gc/total_mem:" << file.errorString();
return false;
}

QString content = QString::fromUtf8(file.readAll());
file.close();

if (content.isEmpty()) {
qCritical() << "Error: /sys/kernel/debug/gc/meminfo File is empty!";
qCritical() << "Error: /sys/kernel/debug/gc/total_mem File is empty!";
return false;
}

QRegularExpression system0Regex(R"(POOL SYSTEM0:*(.*?)POOL VIRTUAL:)",
QRegularExpression::DotMatchesEverythingOption);
QRegularExpressionMatch system0Match = system0Regex.match(content);
QRegularExpression regex(R"((\d+(?:\.\d+)?)\s*\(?(MB|GB|KB|B)\)?)",
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch memInfoMatch = regex.match(content);

if (!system0Match.hasMatch()) {
qCritical() << "Error: Failed to find SYSTEM0 section";
if (!memInfoMatch.hasMatch()) {
qCritical() << "Error: Failed to find memory info";
return false;
}

QString system0Content = system0Match.captured(1);
QRegularExpression totalRegex(R"(Total\s*:\s*(\d+)\s+B)");
QRegularExpressionMatch totalMatch = totalRegex.match(system0Content);
if (totalMatch.hasMatch()) {
totalValue = totalMatch.captured(1);
foundTotal = true;
}

if (!foundTotal || totalValue.isEmpty()) {
qCritical() << "Error: Failed to find Total value in SYSTEM0 content";
return false;
}

bool ok;
quint64 memSize = totalValue.trimmed().toULong(&ok, 10);
if (ok && memSize >= 1048576) {
memSize /= 1048576;
auto curSize = memSize / 1024.0;
if (curSize >= 1) {
totalValue = QString::number(curSize) + "GB";
} else {
totalValue = QString::number(memSize) + "MB";
}
double value = memInfoMatch.captured(1).toDouble();
QString unit = memInfoMatch.captured(2).toUpper();
Comment thread
GongHeng2017 marked this conversation as resolved.

if (unit == "MB") {
totalValue = QString("%1GB").arg(value / 1024.0, 0, 'f', 2);
} else if (unit == "GB") {
totalValue = QString("%1GB").arg(value, 0, 'f', 2);
} else if (unit == "KB") {
totalValue = QString("%1GB").arg(value / (1024.0 * 1024.0), 0, 'f', 2);
} else if (unit == "B") {
totalValue = QString("%1GB").arg(value / (1024.0 * 1024.0 * 1024.0), 0, 'f', 2);
}

mapInfo.insert(kGraphicsMemory, totalValue);
Comment thread
GongHeng2017 marked this conversation as resolved.
Expand Down