Cleanup and simplify.

This commit is contained in:
Steve Checkoway
2005-10-28 14:21:23 +00:00
parent c4195979f3
commit e41570a8f8
+64 -135
View File
@@ -12,17 +12,11 @@
#include <Carbon/Carbon.h>
#undef Random_
#include <mach/thread_act.h>
#include <mach/mach.h>
#include <mach/host_info.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/time.h>
/* You would think that these would be defined somewhere. */
enum
{
kMacOSX_10_2 = 0x1020,
kMacOSX_10_3 = 0x1030
};
#if 0 // Time critical stuff
static thread_time_constraint_policy g_oldttcpolicy;
static float g_fStartedTimeCritAt;
@@ -76,158 +70,93 @@ ArchHooks_darwin::~ArchHooks_darwin()
delete TimeCritMutex;
}
#define CASE_GESTALT_M(str,code,result) case gestalt##code: str = result; break
#define CASE_GESTALT(str,code) CASE_GESTALT_M(str, code, #code)
void ArchHooks_darwin::DumpDebugInfo()
{
CString systemVersion;
long ram;
long vRam;
long processorSpeed;
CString processor;
long numProcessors;
CString machine;
OSErr err = noErr;
OSErr err;
long code;
/* Get system version */
err = Gestalt(gestaltSystemVersion, &code);
if (err == noErr)
err = Gestalt( gestaltSystemVersion, &code );
if( err == noErr )
{
systemVersion = "Mac OS X ";
if (code >= kMacOSX_10_2 && code < kMacOSX_10_3)
systemVersion += ssprintf("10.2.%ld", code - kMacOSX_10_2);
else
{
int ssv = code - kMacOSX_10_3;
if (ssv > 9)
systemVersion += "10.3+";
else
systemVersion += ssprintf("10.3.%d", ssv);
}
int major = ( (code >> 12) & 0xF ) * 10 + (code >> 8) & 0xF;
int minor = (code >> 4) & 0xF;
int revision = code & 0xF;
systemVersion = ssprintf( "Mac OS X %d.%d.%d", major, minor, revision );
}
else
systemVersion = "Unknown system version";
/* Get memory */
err = Gestalt(gestaltLogicalRAMSize, &vRam);
long ram;
long vRam;
err = Gestalt( gestaltLogicalRAMSize, &vRam );
if (err != noErr)
vRam = 0;
err = Gestalt(gestaltPhysicalRAMSize, &ram);
if (err == noErr)
err = Gestalt( gestaltPhysicalRAMSize, &ram );
if( err == noErr )
{
vRam -= ram;
if (vRam < 0)
if( vRam < 0 )
vRam = 0;
ram /= 1048576; /* 1048576 = 1024*1024 */
vRam /= 1048576;
ram >>= 20;
vRam >>= 20;
}
else
{
ram = 0;
vRam = 0;
}
/* XXX Do this in some manner other than using Gestalt */
/* Get processor */
numProcessors = MPProcessorsScheduled();
err = Gestalt(gestaltNativeCPUtype, &code);
if (err == noErr)
{
switch (code)
{
CASE_GESTALT_M(processor, CPU601, "601");
CASE_GESTALT_M(processor, CPU603, "603");
CASE_GESTALT_M(processor, CPU603e, "603e");
CASE_GESTALT_M(processor, CPU603ev, "603ev");
CASE_GESTALT_M(processor, CPU604, "604");
CASE_GESTALT_M(processor, CPU604e, "604e");
CASE_GESTALT_M(processor, CPU604ev, "604ev");
CASE_GESTALT_M(processor, CPU750, "G3");
CASE_GESTALT_M(processor, CPUG4, "G4");
CASE_GESTALT_M(processor, CPUG47450, "G4");
CASE_GESTALT_M(processor, CPUApollo, "G4 (Apollo)");
CASE_GESTALT_M(processor, CPU750FX, "G3 (Sahara)");
case 313: processor = "G5"; break;
default:
processor = ssprintf("%ld", code);
}
}
else
processor = "unknown";
err = Gestalt(gestaltProcClkSpeed, &processorSpeed);
if (err != noErr)
processorSpeed = 0;
/* Get machine */
err = Gestalt(gestaltMachineType, &code);
if (err == noErr)
{
switch (code)
{
/* PowerMacs */
CASE_GESTALT(machine, PowerMac4400);
CASE_GESTALT(machine, PowerMac4400_160);
CASE_GESTALT(machine, PowerMac5200);
CASE_GESTALT(machine, PowerMac5400);
CASE_GESTALT(machine, PowerMac5500);
CASE_GESTALT(machine, PowerMac6100_60);
CASE_GESTALT(machine, PowerMac6100_66);
CASE_GESTALT(machine, PowerMac6200);
CASE_GESTALT(machine, PowerMac6400);
CASE_GESTALT(machine, PowerMac6500);
CASE_GESTALT(machine, PowerMac7100_66);
CASE_GESTALT(machine, PowerMac7100_80);
CASE_GESTALT(machine, PowerMac7200);
CASE_GESTALT(machine, PowerMac7300);
CASE_GESTALT(machine, PowerMac7500);
CASE_GESTALT(machine, PowerMac8100_80);
CASE_GESTALT(machine, PowerMac8100_100);
CASE_GESTALT(machine, PowerMac8100_110);
CASE_GESTALT(machine, PowerMac8500);
CASE_GESTALT(machine, PowerMac9500);
/* upgrade cards */
CASE_GESTALT(machine, PowerMacLC475);
CASE_GESTALT(machine, PowerMacLC575);
CASE_GESTALT(machine, PowerMacQuadra610);
CASE_GESTALT(machine, PowerMacQuadra630);
CASE_GESTALT(machine, PowerMacQuadra650);
CASE_GESTALT(machine, PowerMacQuadra700);
CASE_GESTALT(machine, PowerMacQuadra800);
CASE_GESTALT(machine, PowerMacQuadra900);
CASE_GESTALT(machine, PowerMacQuadra950);
CASE_GESTALT(machine, PowerMacCentris610);
CASE_GESTALT(machine, PowerMacCentris650);
/* PowerBooks */
CASE_GESTALT(machine, PowerBook1400);
CASE_GESTALT(machine, PowerBook2400);
CASE_GESTALT(machine, PowerBook3400);
CASE_GESTALT(machine, PowerBook500PPCUpgrade);
CASE_GESTALT(machine, PowerBookG3);
CASE_GESTALT(machine, PowerBookG3Series);
CASE_GESTALT(machine, PowerBookG3Series2);
/* NewWorld */
CASE_GESTALT(machine, PowerMacNewWorld);
CASE_GESTALT(machine, PowerMacG3);
default:
machine = ssprintf("%ld", code);
}
}
else if (err == gestaltUndefSelectorErr )
/* Get processor information */
CString processor;
int numProcessors;
struct host_basic_info info;
mach_port_t host = mach_host_self();
mach_msg_type_number_t size = HOST_BASIC_INFO_COUNT;
kern_return_t ret = host_info( host, HOST_BASIC_INFO, (host_info_t)&info, &size );
if( ret )
{
machine = "PowerMac ";
machine += processor;
}
else
machine = "unknown machine";
numProcessors = -1;
LOG->Warn("Couldn't get host info.");
}
else
{
char *cpu_type, *cpu_subtype;
numProcessors = info.avail_cpus;
slot_name( info.cpu_type, info.cpu_subtype, &cpu_type, &cpu_subtype );
processor = cpu_subtype;
}
/* Get processor speed */
err = Gestalt( gestaltProcClkSpeed, &code );
if( err != noErr )
code = 0;
float speed;
char power;
if( code >= 1000000000 )
{
speed = code / 1000000000.0f;
power = 'G';
}
else
{
speed = code / 1000000.0f;
power = 'M';
}
/* Send all of the information to the log */
LOG->Info(machine.c_str());
LOG->Info("Processor: %s (%ld)", processor.c_str(), numProcessors);
LOG->Info("%s", systemVersion.c_str());
LOG->Info("Memory: %ld MB total, %ld MB swap", ram, vRam);
LOG->Info( "Processor: %s (%d)", processor.c_str(), numProcessors );
LOG->Info( "Clock speed %.2f %cHz", speed, power );
LOG->Info( "%s", systemVersion.c_str());
LOG->Info( "Memory: %ld MB total, %ld MB swap", ram, vRam );
}
// In archutils/darwin/PreferredLanguage.m