summaryrefslogtreecommitdiff
path: root/src/mongo/util/processinfo_windows.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/util/processinfo_windows.cpp')
-rw-r--r--src/mongo/util/processinfo_windows.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/mongo/util/processinfo_windows.cpp b/src/mongo/util/processinfo_windows.cpp
index 51068027b51..5f3c0514949 100644
--- a/src/mongo/util/processinfo_windows.cpp
+++ b/src/mongo/util/processinfo_windows.cpp
@@ -39,6 +39,7 @@
#include "mongo/logv2/log.h"
#include "mongo/util/processinfo.h"
+#include "mongo/util/text.h"
namespace mongo {
@@ -248,6 +249,43 @@ 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;
@@ -267,6 +305,12 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
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);
+ }
+
+
// get memory info
mse.dwLength = sizeof(mse);
if (GlobalMemoryStatusEx(&mse)) {