10 #include <sys/types.h>
11 #include <sys/sysctl.h>
12 #include <sys/utsname.h>
13 #include <mach/mach.h>
14 #import <Foundation/Foundation.h>
15 #include <Availability.h>
23 static char tmp_buf[4096];
24 size_t size =
sizeof(tmp_buf);
27 if (strcmp(name,
"kern.boottime") == 0)
33 if (sysctlbyname(name, (
void *)&tv, &size,
NULL, 0) == 0)
39 strftime(tmp_buf,
sizeof(tmp_buf),
"%Y-%m-%d %H:%M:%S", tm);
45 else if (strcmp(name,
"hw.memsize") == 0)
51 if (sysctlbyname(name, (
void *)&v, &size,
NULL, 0) == 0)
53 std::ostringstream oss;
59 else if (strcmp(name,
"hw.logicalcpu") == 0)
65 if (sysctlbyname(name, (
void *)&v, &size,
NULL, 0) == 0)
67 std::ostringstream oss;
73 else if (strcmp(name,
"aja.osversion") == 0)
77 #if defined(__MAC_10_10) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_10
78 NSOperatingSystemVersion v = [[NSProcessInfo processInfo] operatingSystemVersion];
79 std::ostringstream oss;
80 oss << v.majorVersion <<
"." << v.minorVersion <<
"." << v.patchVersion;
83 SInt32 majorVersion,minorVersion,pointVersion;
84 Gestalt(gestaltSystemVersionMajor, &majorVersion);
85 Gestalt(gestaltSystemVersionMinor, &minorVersion);
86 Gestalt(gestaltSystemVersionBugFix, &pointVersion);
88 std::ostringstream oss;
89 oss << majorVersion <<
"." << minorVersion <<
"." << pointVersion;
94 else if (sysctlbyname(name, tmp_buf, &size,
NULL, 0) == 0)
107 for (CFIndex i = 0; i<CFArrayGetCount(inArray); i++)
109 CFDictionaryRef theDictionary = CFDictionaryRef(CFArrayGetValueAtIndex(inArray, i));
113 if (CFDictionaryContainsValue(theDictionary, inDataType))
115 CFRetain(theDictionary);
116 return theDictionary;
124 CFArrayRef itemsArray = CFArrayRef(CFDictionaryGetValue(inDictionary, CFSTR(
"_items")));
125 if (itemsArray !=
NULL)
128 CFRetain(itemsArray);
135 std::ostringstream oss;
138 std::vector<char> streamBuffer(512*512);
139 FILE *sys_profile = popen(
"system_profiler SPDisplaysDataType -xml",
"r");
140 size_t bytesRead = fread(&streamBuffer[0],
sizeof(
char), streamBuffer.size(), sys_profile);
146 oss <<
"CPU Type not found";
151 CFDataRef xmlData = CFDataCreate(kCFAllocatorDefault, (
const UInt8*)&streamBuffer[0], bytesRead);
154 CFArrayRef propertyArray = CFArrayRef(CFPropertyListCreateWithData(kCFAllocatorDefault, xmlData, kCFPropertyListImmutable,
NULL,
NULL));
164 for (CFIndex i=0; i < CFArrayGetCount(itemsArray); i++)
167 CFDictionaryRef dict = CFDictionaryRef(CFArrayGetValueAtIndex(itemsArray, i));
168 CFStringRef key = CFSTR(
"sppci_model");
169 CFStringRef outputString = CFStringRef(CFDictionaryGetValue(dict, key));
172 std::vector<char> tmp(CFStringGetLength(outputString)+1);
173 if (CFStringGetCString(outputString, &tmp[0], tmp.size(), kCFStringEncodingUTF8))
181 CFRelease(outputString);
184 CFRelease(itemsArray);
186 CFRelease(hwInfoDict);
234 mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
235 vm_statistics64_data_t vmstat;
236 if(KERN_SUCCESS == host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t)&vmstat, &count))
238 int64_t memtotalbytes;
239 size_t size =
sizeof(memtotalbytes);
240 if (sysctlbyname(
"hw.memsize", (
void *)&memtotalbytes, &size,
NULL, 0) == 0)
242 double totalPages = vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count;
243 double freePercent = (vmstat.free_count) / totalPages;
244 double usedPercent = (vmstat.inactive_count + vmstat.wire_count + vmstat.active_count) / totalPages;
246 std::string unitsLabel;
247 double divisor = 1.0;
264 divisor = 1073741824.0;
268 std::ostringstream t,u,f;
269 t << int64_t(memtotalbytes / divisor) <<
" " << unitsLabel;
270 u << int64_t(memtotalbytes * usedPercent / divisor) <<
" " << unitsLabel;
271 f << int64_t(memtotalbytes * freePercent / divisor) <<
" " << unitsLabel;
290 const char* homePath = getenv(
"HOME");
291 if (homePath !=
NULL)