diff options
Diffstat (limited to 'src/mongo/util/processinfo_windows.cpp')
| -rw-r--r-- | src/mongo/util/processinfo_windows.cpp | 89 |
1 files changed, 21 insertions, 68 deletions
diff --git a/src/mongo/util/processinfo_windows.cpp b/src/mongo/util/processinfo_windows.cpp index 5f3c0514949..5cf7edbdee2 100644 --- a/src/mongo/util/processinfo_windows.cpp +++ b/src/mongo/util/processinfo_windows.cpp @@ -39,7 +39,6 @@ #include "mongo/logv2/log.h" #include "mongo/util/processinfo.h" -#include "mongo/util/text.h" namespace mongo { @@ -92,27 +91,13 @@ LpiRecords getLogicalProcessorInformationRecords() { return lpiRecords; } -struct ParsedProcessorInfo { - int physicalCoreCount; - int numaNodeCount; - int processorPackageCount; -}; - -ParsedProcessorInfo getProcessorInfo() { - ParsedProcessorInfo ppi{0, 0, 0}; +int getPhysicalCores() { + int processorCoreCount = 0; for (auto&& lpi : getLogicalProcessorInformationRecords()) { - switch (lpi.Relationship) { - case RelationProcessorCore: - ppi.physicalCoreCount++; - break; - case RelationNumaNode: - ppi.numaNodeCount++; - break; - case RelationProcessorPackage: - ppi.processorPackageCount++; - } + if (lpi.Relationship == RelationProcessorCore) + processorCoreCount++; } - return ppi; + return processorCoreCount; } } // namespace @@ -249,43 +234,6 @@ bool getFileVersion(const char* filePath, DWORD& fileVersionMS, DWORD& fileVersi return true; } -std::string getCpuString() { - // get descriptive CPU string from registry - HKEY hKey; - LPCWSTR cpuKey = L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"; - LPCWSTR valueName = L"ProcessorNameString"; - std::string cpuString; - - // Open the CPU key in the Windows Registry - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, cpuKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { - ScopeGuard guard([hKey] { RegCloseKey(hKey); }); - WCHAR cpuModel[128]; - DWORD bufferSize = sizeof(cpuModel); - - // Retrieve the value of ProcessorNameString - if (RegQueryValueEx(hKey, - valueName, - nullptr, - nullptr, - reinterpret_cast<LPBYTE>(cpuModel), - &bufferSize) == ERROR_SUCCESS) { - cpuString = toUtf8String(cpuModel); - } else { - auto ec = lastSystemError(); - LOGV2_WARNING(7663101, - "Failed to retrieve CPU model name from the registry", - "error"_attr = errorMessage(ec)); - } - - // Close the registry key - } else { - auto ec = lastSystemError(); - LOGV2_WARNING( - 7663102, "Failed to open CPU key in the registry", "error"_attr = errorMessage(ec)); - } - return cpuString; -} - void ProcessInfo::SystemInfo::collectSystemInfo() { BSONObjBuilder bExtra; std::stringstream verstr; @@ -297,19 +245,10 @@ void ProcessInfo::SystemInfo::collectSystemInfo() { GetNativeSystemInfo(&ntsysinfo); addrSize = (ntsysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ? 64 : 32); numCores = ntsysinfo.dwNumberOfProcessors; - auto ppi = getProcessorInfo(); - numPhysicalCores = ppi.physicalCoreCount; - numCpuSockets = ppi.processorPackageCount; - hasNuma = ppi.numaNodeCount > 1; - numNumaNodes = ppi.numaNodeCount; + numPhysicalCores = getPhysicalCores(); pageSize = static_cast<unsigned long long>(ntsysinfo.dwPageSize); bExtra.append("pageSize", static_cast<long long>(pageSize)); - - std::string cpuString = getCpuString(); - if (cpuString != nullptr) { - bExtra.append("cpuString", cpuString); - } - + bExtra.append("physicalCores", static_cast<int>(numPhysicalCores)); // get memory info mse.dwLength = sizeof(mse); @@ -413,7 +352,21 @@ void ProcessInfo::SystemInfo::collectSystemInfo() { osType = "Windows"; osVersion = verstr.str(); + hasNuma = checkNumaEnabled(); _extraStats = bExtra.obj(); } + +bool ProcessInfo::checkNumaEnabled() { + DWORD numaNodeCount = 0; + for (auto&& lpi : getLogicalProcessorInformationRecords()) { + if (lpi.Relationship == RelationNumaNode) + // Non-NUMA systems report a single record of this type. + ++numaNodeCount; + } + + // For non-NUMA machines, the count is 1 + return numaNodeCount > 1; +} + } // namespace mongo |
