From 5ac87ba7f341181eba53340da651a56d93785e60 Mon Sep 17 00:00:00 2001 From: Emma Date: Sat, 18 Apr 2026 17:53:21 +0000 Subject: [PATCH] mac: Log CPU and OS version (#1879) --- src/Cafe/CafeSystem.cpp | 18 +++++++++++++++++- src/Common/cpu_features.cpp | 23 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/Cafe/CafeSystem.cpp b/src/Cafe/CafeSystem.cpp index 879085b9..f016773c 100644 --- a/src/Cafe/CafeSystem.cpp +++ b/src/Cafe/CafeSystem.cpp @@ -539,7 +539,23 @@ namespace CafeSystem else platform = "Linux"; #elif BOOST_OS_MACOS - platform = "MacOS"; + char productVersion[256]{}; + size_t productVersionSize = sizeof(productVersion); + const int productVersionResult = sysctlbyname("kern.osproductversion", productVersion, &productVersionSize, nullptr, 0); + + char buildVersion[256]{}; + size_t buildVersionSize = sizeof(buildVersion); + const int buildVersionResult = sysctlbyname("kern.osversion", buildVersion, &buildVersionSize, nullptr, 0); + + if (productVersionResult == 0 && buildVersionResult == 0) + buffer = fmt::format("macOS {} ({})", productVersion, buildVersion); + else if (productVersionResult == 0) + buffer = fmt::format("macOS {}", productVersion); + else + buffer = "macOS"; + + platform = buffer.c_str(); + #elif BOOST_OS_BSD #if defined(__FreeBSD__) platform = "FreeBSD"; diff --git a/src/Common/cpu_features.cpp b/src/Common/cpu_features.cpp index dfea8851..cbc90a15 100644 --- a/src/Common/cpu_features.cpp +++ b/src/Common/cpu_features.cpp @@ -1,5 +1,10 @@ #include "cpu_features.h" +#if BOOST_OS_MACOS +#include +#include +#endif + // wrappers with uniform prototype for implementation-specific x86 CPU id #if defined(ARCH_X86_64) #ifdef __GNUC__ @@ -30,7 +35,23 @@ inline void cpuidex(int cpuInfo[4], int functionId, int subFunctionId) { CPUFeaturesImpl::CPUFeaturesImpl() { -#if defined(ARCH_X86_64) +#if BOOST_OS_MACOS + std::string cpuName; + size_t size = 0; + + if (sysctlbyname("machdep.cpu.brand_string", nullptr, &size, nullptr, 0) == 0 && size > 0) + { + std::vector buffer(size); + + if (sysctlbyname("machdep.cpu.brand_string", buffer.data(), &size, nullptr, 0) == 0 && size > 0) + { + cpuName.assign(buffer.data()); + } + } + + strncpy(m_cpuBrandName, cpuName.c_str(), sizeof(m_cpuBrandName) - 1); + m_cpuBrandName[sizeof(m_cpuBrandName) - 1] = '\0'; +#elif defined(ARCH_X86_64) int cpuInfo[4]; cpuid(cpuInfo, 0x80000001); x86.lzcnt = ((cpuInfo[2] >> 5) & 1) != 0;