diff --git a/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp index d476fdee..d0ad1acf 100644 --- a/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp @@ -1306,43 +1306,31 @@ void DeviceGenerator::calAndSetCpuHeaderInfo(const QMap &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 totalL1dCache(tr("L1d cache"), strTotalL1dCache); - singleCpuHeaderInfo.push_back(totalL1dCache); + QString strL1dCache = Common::formatCacheSize(firstProcessorInfo.value("L1d cache")); + if (!strL1dCache.isEmpty()) { + QPair 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 totalL1iCache(tr("L1i cache"), strTotalL1iCache); - singleCpuHeaderInfo.push_back(totalL1iCache); + QString strL1iCache = Common::formatCacheSize(firstProcessorInfo.value("L1i cache")); + if (!strL1iCache.isEmpty()) { + QPair 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 totalL2Cache(tr("L2 cache"), strTotalL2Cache); - singleCpuHeaderInfo.push_back(totalL2Cache); + QString strL2Cache = Common::formatCacheSize(firstProcessorInfo.value("L2 cache")); + if (!strL2Cache.isEmpty()) { + QPair 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 totalL3Cache(tr("L3 cache"), strTotalL3Cache); - singleCpuHeaderInfo.push_back(totalL3Cache); + QString strL3Cache = Common::formatCacheSize(firstProcessorInfo.value("L3 cache")); + if (!strL3Cache.isEmpty()) { + QPair l3Cache(tr("L3 cache"), strL3Cache); + singleCpuHeaderInfo.push_back(l3Cache); } } diff --git a/deepin-devicemanager/src/commonfunction.cpp b/deepin-devicemanager/src/commonfunction.cpp index 8b380b11..88e17bc5 100644 --- a/deepin-devicemanager/src/commonfunction.cpp +++ b/deepin-devicemanager/src/commonfunction.cpp @@ -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(); @@ -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"; } @@ -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 diff --git a/deepin-devicemanager/src/commonfunction.h b/deepin-devicemanager/src/commonfunction.h index 2d1610a5..e3d61149 100644 --- a/deepin-devicemanager/src/commonfunction.h +++ b/deepin-devicemanager/src/commonfunction.h @@ -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