I\'m working on a cross platform profiling suite, and would like to add information about the machine\'s CPU (architecture/clock speed/cores) and RAM(total) to the report of
On Solaris:
-For memory
prtconf | grep Memory
-For CPU
psrinfo -v | grep MHz
On Windows you can use GlobalMemoryStatusEx to get the amount of actual RAM.
Processor information can be obtained via GetSystemInfo.
Here is one method for getting the information you want on a Windows machine. I copied and pasted it from an actual project with some minor modifications, so feel free to clean it up to make more sense.
int CPUInfo[4] = {-1};
unsigned nExIds, i = 0;
char CPUBrandString[0x40];
// Get the information associated with each extended ID.
__cpuid(CPUInfo, 0x80000000);
nExIds = CPUInfo[0];
for (i=0x80000000; i<=nExIds; ++i)
{
__cpuid(CPUInfo, i);
// Interpret CPU brand string
if (i == 0x80000002)
memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
else if (i == 0x80000003)
memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
else if (i == 0x80000004)
memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
}
//string includes manufacturer, model and clockspeed
cout << "CPU Type: " << CPUBrandString << endl;
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
cout << "Number of Cores: " << sysInfo.dwNumberOfProcessors << endl;
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx(&statex);
cout << "Total System Memory: " << (statex.ullTotalPhys/1024)/1024 << "MB" << endl;
For more information, see GetSystemInfo, GlobalMemoryStatusEx and __cpuid. Although I didn't include it, you can also determine if the OS is 32 or 64 bit via the GetSystemInfo function.
I've written some code which uses the WMI service to get the Max Clock Speed, I know it's VB.net but it shows the idea:
''' <summary>
''' Use WMI to get the Clock Speed in Hz
''' </summary>
Public Function GetMaxClockSpeedInHz() As Double
Dim manObj = New ManagementObject("Win32_Processor.DeviceID='CPU0'")
manObj.Get()
GetMaxClockSpeedInHz = Convert.ToInt32(manObj.Properties("MaxClockSpeed").Value)
End Function
Win32_OperatingSystem reference : http://msdn.microsoft.com/en-us/library/Aa394239
WMI Reference : http://msdn.microsoft.com/en-us/library/aa394572(v=VS.85).aspx
On Linux you can parse /proc/cpuinfo (contains a block of info on each processor) and /proc/meminfo (contains a variety of general memory statistics, including MemTotal).
http://en.wikipedia.org/wiki/CPUID Might help for the CPUID