From 68befaace9a1d464d81cf7fde85fc6a80f228b66 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Fri, 20 Dec 2024 15:12:37 +0200 Subject: [PATCH] SysInfo caching for MacOS --- openVulkanoCpp/Host/MacOS/SystemInfo.mm | 67 ++++++++++++++++++++----- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/openVulkanoCpp/Host/MacOS/SystemInfo.mm b/openVulkanoCpp/Host/MacOS/SystemInfo.mm index ad149f1..1d0711f 100644 --- a/openVulkanoCpp/Host/MacOS/SystemInfo.mm +++ b/openVulkanoCpp/Host/MacOS/SystemInfo.mm @@ -24,7 +24,12 @@ namespace OpenVulkano size_t SystemInfo::GetSystemRam() { - return [NSProcessInfo processInfo].physicalMemory; + static size_t ram; + if (ram == 0) + { + ram = [NSProcessInfo processInfo].physicalMemory; + } + return ram; } size_t SystemInfo::GetSystemRamAvailable() @@ -67,12 +72,22 @@ namespace OpenVulkano std::string SystemInfo::GetHostName() { - return [[NSProcessInfo processInfo].hostName UTF8String]; + static std::string hostName; + if (hostName.empty()) + { + hostName = [[NSProcessInfo processInfo].hostName UTF8String]; + } + return hostName; } std::string SystemInfo::GetDeviceName() { - return "Mac"; //TODO + static std::string devName; + if (devName.empty()) + { + devName = "Mac"; //TODO + } + return devName; } std::string SystemInfo::GetDeviceVendorName() @@ -82,9 +97,14 @@ namespace OpenVulkano std::string SystemInfo::GetDeviceModelName() { - struct utsname systemInfo; - uname(&systemInfo); - return systemInfo.machine; + static std::string machine; + if (machine.empty()) + { + struct utsname systemInfo; + uname(&systemInfo); + machine = systemInfo.machine; + } + return machine; } std::string SystemInfo::GetOsName() @@ -94,15 +114,26 @@ namespace OpenVulkano OsVersion SystemInfo::GetOsVersion() { - NSOperatingSystemVersion osVersion = [NSProcessInfo processInfo].operatingSystemVersion; - return { static_cast(osVersion.majorVersion), static_cast(osVersion.minorVersion), static_cast(osVersion.patchVersion), 0 }; + static OsVersion osVersion; + if (osVersion.major == 0 && osVersion.minor == 0) + { + NSOperatingSystemVersion sysVersion = [NSProcessInfo processInfo].operatingSystemVersion; + osVersion = { static_cast(sysVersion.majorVersion), static_cast(sysVersion.minorVersion), + static_cast(sysVersion.patchVersion), 0 }; + } + return osVersion; } std::string SystemInfo::GetOsNameHumanReadable() { - std::stringstream name; - name << GetOsName() << ' ' << GetOsVersion().major; - return name.str(); + static std::string hrName; + if (hrName.empty()) + { + std::stringstream name; + name << GetOsName() << ' ' << GetOsVersion().major; + hrName = name.str(); + } + return hrName; } DeviceType SystemInfo::GetDeviceType() @@ -112,12 +143,22 @@ namespace OpenVulkano size_t SystemInfo::GetCpuCoreCount() { - return [NSProcessInfo processInfo].processorCount; + static size_t coreCount; + if (coreCount == 0) + { + coreCount = [NSProcessInfo processInfo].processorCount; + } + return coreCount; } size_t SystemInfo::GetCpuThreadCount() { - return [NSProcessInfo processInfo].activeProcessorCount; + static size_t procCount; + if (procCount == 0) + { + procCount = [NSProcessInfo processInfo].activeProcessorCount; + } + return procCount; } int32_t SystemInfo::GetCpuTemperature()