From 39612397fa12c590594703c6d9c062458748c6d6 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 10 Dec 2014 22:44:39 -0500 Subject: [PATCH] #1057 Sysinfo for Mac OS X --- src/PlatformUtils-mac.mm | 65 +++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/src/PlatformUtils-mac.mm b/src/PlatformUtils-mac.mm index 20e72321..45157921 100644 --- a/src/PlatformUtils-mac.mm +++ b/src/PlatformUtils-mac.mm @@ -1,5 +1,8 @@ #include "PlatformUtils.h" #import +#include +#include +#include std::string PlatformUtils::pathSeparatorChar() { @@ -37,44 +40,30 @@ unsigned long PlatformUtils::stackLimit() std::string PlatformUtils::sysinfo() { - std::string result; - -#if 0 - struct utsname osinfo; - if (uname(&osinfo) == 0) { - result += osinfo.sysname; - result += " "; - result += osinfo.release; - result += " "; - result += osinfo.version; - result += " "; - result += osinfo.machine; - } else { -#endif - result += "Unknown MacOS"; -#if 0 - } - - long numcpu = sysconf(_SC_NPROCESSORS_ONLN); - if (numcpu > 0) { - result += " "; - result += boost::lexical_cast(numcpu); - result += " CPU"; - if (numcpu > 1) { - result += "s"; - } - } - - long pages = sysconf(_SC_PHYS_PAGES); - long pagesize = sysconf(_SC_PAGE_SIZE); - if ((pages > 0) && (pagesize > 0)) { - result += " "; - result += PlatformUtils::toMemorySizeString(pages * pagesize, 2); - result += " RAM"; - } -#endif - - return result; + std::string result; + + result += "Mac OS X "; + result += [[[NSProcessInfo processInfo] operatingSystemVersionString] UTF8String]; + + int mib[2]; + int64_t physical_memory; + int32_t numcpu; + size_t length64 = sizeof(int64_t); + size_t length32 = sizeof(int32_t);; + + sysctlbyname("hw.memsize", &physical_memory, &length64, NULL, 0); + sysctlbyname("hw.physicalcpu", &numcpu, &length32, NULL, 0); + + result += " "; + result += boost::lexical_cast(numcpu); + result += " CPU"; + if (numcpu > 1) result += "s"; + + result += " "; + result += PlatformUtils::toMemorySizeString(physical_memory, 2); + result += " RAM"; + + return result; } void PlatformUtils::ensureStdIO(void) {}