- (NSString *) systemInfoString {
static NSString *systemInfoString = NULL;
if (systemInfoString) {
return systemInfoString;
}
int error = 0 ;
int value = 0 ;
unsigned long length = sizeof(value) ;
NSString *visibleCPUSubType = @"";
NSString *visibleCPUType = @"an Unknown Processor";
// CPU type (decoder info for values found here is in mach/machine.h)
error = sysctlbyname("hw.cputype", &value, &length, NULL, 0);
int cpuType = -1;
if (error == 0) {
cpuType = value;
switch(value) {
case 7: visibleCPUType=@"Intel"; break;
case 18: visibleCPUType=@"a PowerPC"; break;
default: visibleCPUType=@"an Unknown"; break;
}
}
error = sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);
if (error == 0) {
if (cpuType == 7) {
// Intel
visibleCPUSubType = @""; // If anyone knows how to tell a Core Duo from a Core Solo, please email tph@atomicbird.com
} else if (cpuType == 18) {
// PowerPC
switch(value) {
case 9: visibleCPUSubType=@" G3"; break;
case 10: case 11: visibleCPUSubType=@" G4"; break;
case 100: visibleCPUSubType=@" G5"; break;
default: visibleCPUSubType=@" Other"; break;
}
} else {
visibleCPUSubType = @"Other";
}
}
int cpuCount = 1;
// Number of CPUs
error = sysctlbyname("hw.ncpu", &value, &length, NULL, 0);
if (error == 0)
cpuCount = value;
int clockSpeed;
OSErr err;
SInt32 gestaltInfo;
err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo);
if (err == noErr)
clockSpeed = gestaltInfo;
int ram;
err = Gestalt(gestaltPhysicalRAMSizeInMegabytes,&gestaltInfo);
if (err == noErr)
ram = gestaltInfo;
NSString *extra = @"";
if (cpuCount > 7 or clockSpeed > 3100) {
extra = @" It's super fast and I love it.";
}
NSString *currentSystemVersion = SUCurrentSystemVersionString();
systemInfoString = [[NSString stringWithFormat:@"(I'm running Mac OS X %@ on %@%@, with %d CPU(s) running at %d MHz and %d MB of ram.%@)", currentSystemVersion, visibleCPUType, visibleCPUSubType, cpuCount, clockSpeed, ram, extra] retain];
return systemInfoString;
}