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
44 changes: 16 additions & 28 deletions deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,43 +1306,31 @@ void DeviceGenerator::calAndSetCpuHeaderInfo(const QMap<QString, QString> &first
singleCpuHeaderInfo.push_back(threadPerCore);
}
if (firstProcessorInfo.contains("L1d cache")) {
QString strL1dCache = firstProcessorInfo.value("L1d cache");
int sharedCount = Common::parseSharedCpuCount(firstProcessorInfo.value("L1d shared cpu list"));
int groupCount = (sharedCount > 0 && logicalNum > 0) ? logicalNum / sharedCount : coreNum;
QString strTotalL1dCache = Common::formatTotalCache(strL1dCache, groupCount);
if (!strTotalL1dCache.isEmpty()) {
QPair<QString, QString> totalL1dCache(tr("L1d cache"), strTotalL1dCache);
singleCpuHeaderInfo.push_back(totalL1dCache);
QString strL1dCache = Common::formatCacheSize(firstProcessorInfo.value("L1d cache"));
if (!strL1dCache.isEmpty()) {
QPair<QString, QString> l1dCache(tr("L1d cache"), strL1dCache);
singleCpuHeaderInfo.push_back(l1dCache);
}
}
if (firstProcessorInfo.contains("L1i cache")) {
QString strL1iCache = firstProcessorInfo.value("L1i cache");
int sharedCount = Common::parseSharedCpuCount(firstProcessorInfo.value("L1i shared cpu list"));
int groupCount = (sharedCount > 0 && logicalNum > 0) ? logicalNum / sharedCount : coreNum;
QString strTotalL1iCache = Common::formatTotalCache(strL1iCache, groupCount);
if (!strTotalL1iCache.isEmpty()) {
QPair<QString, QString> totalL1iCache(tr("L1i cache"), strTotalL1iCache);
singleCpuHeaderInfo.push_back(totalL1iCache);
QString strL1iCache = Common::formatCacheSize(firstProcessorInfo.value("L1i cache"));
if (!strL1iCache.isEmpty()) {
QPair<QString, QString> l1iCache(tr("L1i cache"), strL1iCache);
singleCpuHeaderInfo.push_back(l1iCache);
}
}
if (firstProcessorInfo.contains("L2 cache")) {
QString strL2Cache = firstProcessorInfo.value("L2 cache");
int sharedCount = Common::parseSharedCpuCount(firstProcessorInfo.value("L2 shared cpu list"));
int groupCount = (sharedCount > 0 && logicalNum > 0) ? logicalNum / sharedCount : coreNum;
QString strTotalL2Cache = Common::formatTotalCache(strL2Cache, groupCount);
if (!strTotalL2Cache.isEmpty()) {
QPair<QString, QString> totalL2Cache(tr("L2 cache"), strTotalL2Cache);
singleCpuHeaderInfo.push_back(totalL2Cache);
QString strL2Cache = Common::formatCacheSize(firstProcessorInfo.value("L2 cache"));
if (!strL2Cache.isEmpty()) {
QPair<QString, QString> l2Cache(tr("L2 cache"), strL2Cache);
singleCpuHeaderInfo.push_back(l2Cache);
}
}
if (firstProcessorInfo.contains("L3 cache")) {
QString strL3Cache = firstProcessorInfo.value("L3 cache");
int sharedCount = Common::parseSharedCpuCount(firstProcessorInfo.value("L3 shared cpu list"));
int groupCount = (sharedCount > 0 && logicalNum > 0) ? logicalNum / sharedCount : 1;
QString strTotalL3Cache = Common::formatTotalCache(strL3Cache, groupCount);
if (!strTotalL3Cache.isEmpty()) {
QPair<QString, QString> totalL3Cache(tr("L3 cache"), strTotalL3Cache);
singleCpuHeaderInfo.push_back(totalL3Cache);
QString strL3Cache = Common::formatCacheSize(firstProcessorInfo.value("L3 cache"));
if (!strL3Cache.isEmpty()) {
QPair<QString, QString> l3Cache(tr("L3 cache"), strL3Cache);
singleCpuHeaderInfo.push_back(l3Cache);
}
}

Expand Down
62 changes: 15 additions & 47 deletions deepin-devicemanager/src/commonfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ bool Common::isShowScreenSize()
return showScreenSize;
}

QString Common::formatTotalCache(const QString &perThreadCache, int coreCount)
QString Common::formatCacheSize(const QString &cacheSize)
{
// 1. 清理并分离数字与单位
QString s = perThreadCache.trimmed();
QString s = cacheSize.trimmed();
if (s.isEmpty())
return QString();

Expand All @@ -278,37 +278,35 @@ QString Common::formatTotalCache(const QString &perThreadCache, int coreCount)
if (!ok)
return QString();

// 2. 将单核/单线程缓存转换为 KiB
double perCoreKiB = 0.0;
// 2. 将缓存大小转换为 KiB(单实例大小,不再按实例数累加)
double cacheKiB = 0.0;
if (unitStr.startsWith("K") || unitStr == "KB" || unitStr == "KIB") {
perCoreKiB = num;
cacheKiB = num;
} else if (unitStr.startsWith("M") || unitStr == "MB" || unitStr == "MIB") {
perCoreKiB = num * 1024.0;
cacheKiB = num * 1024.0;
} else if (unitStr.startsWith("G") || unitStr == "GB" || unitStr == "GIB") {
perCoreKiB = num * 1024.0 * 1024.0;
cacheKiB = num * 1024.0 * 1024.0;
} else if (unitStr.startsWith("T") || unitStr == "TB" || unitStr == "TIB") {
perCoreKiB = num * 1024.0 * 1024.0 * 1024.0;
cacheKiB = num * 1024.0 * 1024.0 * 1024.0;
} else if (unitStr.isEmpty() || unitStr == "B") {
// 无单位或纯字节,视为字节并转为 KiB
perCoreKiB = num / 1024.0;
cacheKiB = num / 1024.0;
} else {
// 未知单位,按原数值当作 KiB 处理
perCoreKiB = num;
cacheKiB = num;
}

double totalKiB = perCoreKiB * coreCount;

// 3. 选择最合适的单位并格式化数值
double value;
QString unit;
if (totalKiB >= 1024.0 * 1024.0) {
value = totalKiB / (1024.0 * 1024.0);
if (cacheKiB >= 1024.0 * 1024.0) {
value = cacheKiB / (1024.0 * 1024.0);
unit = "GiB";
} else if (totalKiB >= 1024.0) {
value = totalKiB / 1024.0;
} else if (cacheKiB >= 1024.0) {
value = cacheKiB / 1024.0;
unit = "MiB";
} else {
value = totalKiB;
value = cacheKiB;
unit = "KiB";
}

Expand All @@ -321,36 +319,6 @@ QString Common::formatTotalCache(const QString &perThreadCache, int coreCount)
}
}

int Common::parseSharedCpuCount(const QString &sharedCpuList)
{
QString s = sharedCpuList.trimmed();
if (s.isEmpty())
return 0;

int count = 0;
QStringList parts = s.split(',', QString::SkipEmptyParts);
for (const QString &part : parts) {
QString trimmed = part.trimmed();
if (trimmed.contains('-')) {
QStringList range = trimmed.split('-');
if (range.size() == 2) {
bool ok1 = false, ok2 = false;
int start = range[0].trimmed().toInt(&ok1);
int end = range[1].trimmed().toInt(&ok2);
if (ok1 && ok2 && end >= start) {
count += end - start + 1;
}
}
} else {
bool ok = false;
if (trimmed.toInt(&ok) || ok) {
count += 1;
}
}
}
return count;
}

QString Common::formatNetworkSpeed(const QString& speed)
{
// 1. Trim whitespace; return original if empty
Expand Down
4 changes: 1 addition & 3 deletions deepin-devicemanager/src/commonfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class Common
static QByteArray executeClientCmd(const QString& cmd, const QStringList& args = QStringList(), const QString& workPath = QString(), int msecsWaiting = 30000);

static bool isShowScreenSize();
static QString formatTotalCache(const QString& perThreadCache, int coreCount);

static int parseSharedCpuCount(const QString &sharedCpuList);
static QString formatCacheSize(const QString& cacheSize);

/**
* @brief formatNetworkSpeed: Convert network speed units to Mbps
Expand Down
Loading