More detailed system stats

Fixed physical core count always returning logical core count (this engine does not run on the AMD Phenom processor).
This commit is contained in:
Kawe Mazidjatari 2022-04-18 16:45:26 +02:00
parent ecfc380f84
commit 1e7b746356
7 changed files with 87 additions and 34 deletions

View File

@ -114,7 +114,7 @@
void Systems_Init() void Systems_Init()
{ {
spdlog::info("+-------------------------------------------------------------+\n"); spdlog::info("+-------------------------------------------------------------+\n");
QueryCPUInfo(); QuerySystemInfo();
CFastTimer initTimer; CFastTimer initTimer;
initTimer.Start(); initTimer.Start();
@ -343,7 +343,7 @@ void WS_Shutdown()
std::cerr << "Failed to stop winsock via WSACleanup: (" << NET_ErrorString(WSAGetLastError()) << ")" << std::endl; std::cerr << "Failed to stop winsock via WSACleanup: (" << NET_ErrorString(WSAGetLastError()) << ")" << std::endl;
} }
} }
void QueryCPUInfo() void QuerySystemInfo()
{ {
const CPUInformation& pi = GetCPUInformation(); const CPUInformation& pi = GetCPUInformation();
@ -355,17 +355,35 @@ void QueryCPUInfo()
} }
} }
spdlog::info("CPU Vendor ID '{:s}'\n", pi.m_szProcessorID); spdlog::info("CPU model identifier : '{:s}'\n", pi.m_szProcessorBrand);
spdlog::info("Logical processors '{:d}'\n", pi.m_nLogicalProcessors); spdlog::info("CPU vendor identifier : '{:s}'\n", pi.m_szProcessorID);
spdlog::info("Physical processors '{:d}'\n", pi.m_nPhysicalProcessors); spdlog::info("CPU core count : '{:10d}' ({:s})\n", pi.m_nPhysicalProcessors, "Physical");
spdlog::info("L1 cache (KiB) '{:d}'\n", pi.m_nL1CacheSizeKb); spdlog::info("CPU core count : '{:10d}' ({:s})\n", pi.m_nLogicalProcessors, "Logical");
spdlog::info("L1 cache (Dsc) '0x{:x}'\n", pi.m_nL1CacheDesc); spdlog::info("L1 cache (KiB): '{:10d}'\n", pi.m_nL1CacheSizeKb);
spdlog::info("L2 cache (KiB) '{:d}'\n", pi.m_nL2CacheSizeKb); spdlog::info("L1 cache (Dsc): '{:#10x}'\n" , pi.m_nL1CacheDesc);
spdlog::info("L2 cache (Dsc) '0x{:x}'\n", pi.m_nL2CacheDesc); spdlog::info("L2 cache (KiB): '{:10d}'\n", pi.m_nL2CacheSizeKb);
spdlog::info("L3 cache (KiB) '{:d}'\n", pi.m_nL3CacheSizeKb); spdlog::info("L2 cache (Dsc): '{:#10x}'\n" , pi.m_nL2CacheDesc);
spdlog::info("L3 cache (Dsc) '0x{:x}'\n", pi.m_nL3CacheDesc); spdlog::info("L3 cache (KiB): '{:10d}'\n", pi.m_nL3CacheSizeKb);
spdlog::info("Clock rate (CPS) '{:d}'\n", pi.m_Speed); spdlog::info("L3 cache (Dsc): '{:#10x}'\n" , pi.m_nL3CacheDesc);
spdlog::info("Clock speed (CPS): '{:10d}'\n", pi.m_Speed);
MEMORYSTATUSEX statex{};
statex.dwLength = sizeof(statex);
if (GlobalMemoryStatusEx(&statex))
{
spdlog::info("Total system memory (MiB): '{:10d}' ({:s})\n", (statex.ullTotalPhys / 1024) / 1024, "Physical");
spdlog::info("Avail system memory (MiB): '{:10d}' ({:s})\n", (statex.ullAvailPhys / 1024) / 1024, "Physical");
spdlog::info("Total system memory (MiB): '{:10d}' ({:s})\n", (statex.ullTotalVirtual / 1024) / 1024, "Virtual");
spdlog::info("Avail system memory (MiB): '{:10d}' ({:s})\n", (statex.ullAvailVirtual / 1024) / 1024, "Virtual");
} }
else
{
spdlog::error("Unable to retrieve system memory information: {:s}\n",
std::system_category().message(static_cast<int>(::GetLastError())));
}
}
void PrintHAddress() // Test the sigscan results void PrintHAddress() // Test the sigscan results
{ {
std::cout << "+----------------------------------------------------------------+" << std::endl; std::cout << "+----------------------------------------------------------------+" << std::endl;

View File

@ -13,5 +13,5 @@ void Systems_Shutdown();
void WS_Init(); void WS_Init();
void WS_Shutdown(); void WS_Shutdown();
void QueryCPUInfo(); void QuerySystemInfo();
void PrintHAddress(); void PrintHAddress();

View File

@ -458,7 +458,7 @@ void CConsole::FindFromPartial(void)
} }
else { break; } else { break; }
} }
std::sort(m_vsvSuggest.begin(), m_vsvSuggest.end(), CheckStringLexicographically); std::sort(m_vsvSuggest.begin(), m_vsvSuggest.end(), CompareStringLexicographically);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -20,11 +20,14 @@ string ConvertToWinPath(const string& svInput);
string Base64Encode(const string& svInput); string Base64Encode(const string& svInput);
string Base64Decode(const string& svInput); string Base64Decode(const string& svInput);
bool CompareStringAlphabetically(const string& svA, const string& svB);
bool CompareStringLexicographically(const string& svA, const string& svB);
bool StringReplace(string& svInput, const string& svFrom, const string& svTo); bool StringReplace(string& svInput, const string& svFrom, const string& svTo);
string StringEscape(const string& svInput); string StringEscape(const string& svInput);
string StringUnescape(const string& svInput); string StringUnescape(const string& svInput);
vector<int> StringToBytes(const string& svInput, bool bNullTerminator); vector<int> StringToBytes(const string& svInput, bool bNullTerminator);
vector<int> PatternToBytes(const string& svInput); vector<int> PatternToBytes(const string& svInput);
bool CheckStringLexicographically(const string& svA, const string& svB); vector<int> IntToDigits(int value);
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -332,6 +332,26 @@ string Base64Decode(const string& svInput)
return results; return results;
} }
///////////////////////////////////////////////////////////////////////////////
// For comparing input strings alphabetically
bool CompareStringAlphabetically(const string& svA, const string& svB)
{
int i = 0;
while (svA[i] != '\0' && svA[i] == svB[i])
{
i++;
}
return (svA[i] - svB[i]) < 0;
}
///////////////////////////////////////////////////////////////////////////////
// For comparing input strings lexicographically
bool CompareStringLexicographically(const string& svA, const string& svB)
{
return svA < svB;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// For replacing parts of a given string. // For replacing parts of a given string.
bool StringReplace(string& svInput, const string& svFrom, const string& svTo) bool StringReplace(string& svInput, const string& svFrom, const string& svTo)
@ -443,8 +463,14 @@ vector<int> PatternToBytes(const string& svInput)
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// For comparing input strings lexicographically // For converting a integer into digits
bool CheckStringLexicographically(const string& svA, const string& svB) vector<int> IntToDigits(int value)
{ {
return svA < svB; vector<int> vDigits;
for (; value > 0; value /= 10)
{
vDigits.push_back(value % 10);
}
std::reverse(vDigits.begin(), vDigits.end());
return vDigits;
} }

View File

@ -274,7 +274,7 @@ const char* GetProcessorVendorId(void)
return s_CpuVendorID; return s_CpuVendorID;
} }
const char* GetProcessorBrand(void) const char* GetProcessorBrand(bool bRemovePadding = true)
{ {
if (s_bCpuBrandInitialized) if (s_bCpuBrandInitialized)
{ {
@ -282,12 +282,12 @@ const char* GetProcessorBrand(void)
} }
s_bCpuBrandInitialized = true; s_bCpuBrandInitialized = true;
memset(&s_CpuBrand, 0, sizeof(s_CpuBrand)); memset(&s_CpuBrand, '\0', sizeof(s_CpuBrand));
const char* pchVendor = GetProcessorVendorId(); const char* pchVendor = GetProcessorVendorId();
if (0 == _stricmp(pchVendor, "GenuineIntel")) if (0 == _stricmp(pchVendor, "AuthenticAMD") || 0 == _stricmp(pchVendor, "GenuineIntel"))
{ {
// Intel brand string. // AMD/Intel brand string.
if (cpuid(0x80000000).eax >= 0x80000004) if (cpuid(0x80000000).eax >= 0x80000004)
{ {
s_CpuBrand.cpuid[0] = cpuid(0x80000002); s_CpuBrand.cpuid[0] = cpuid(0x80000002);
@ -295,6 +295,21 @@ const char* GetProcessorBrand(void)
s_CpuBrand.cpuid[2] = cpuid(0x80000004); s_CpuBrand.cpuid[2] = cpuid(0x80000004);
} }
} }
if (bRemovePadding)
{
for (int i = 0; i < sizeof(s_CpuBrand.name) - 1; i++)
{
if (s_CpuBrand.name[i] == ' ')
{
if (s_CpuBrand.name[i + 1] == ' ')
{
s_CpuBrand.name[i] = '\0';
}
}
}
}
return s_CpuBrand.name; return s_CpuBrand.name;
} }
@ -429,17 +444,8 @@ const CPUInformation& GetCPUInformation(void)
// This is contrary to MSDN documentation on GetSystemInfo(). // This is contrary to MSDN documentation on GetSystemInfo().
pi.m_nLogicalProcessors = si.dwNumberOfProcessors; pi.m_nLogicalProcessors = si.dwNumberOfProcessors;
if (bAuthenticAMD)
{
// Quick fix for AMD Phenom: it reports 3 logical cores and 4 physical cores;
// No AMD CPUs by the end of 2009 have HT, so we'll override HT detection here.
pi.m_nPhysicalProcessors = pi.m_nLogicalProcessors;
}
else
{
CpuTopology topo; CpuTopology topo;
pi.m_nPhysicalProcessors = topo.NumberOfSystemCores(); pi.m_nPhysicalProcessors = topo.NumberOfSystemCores();
}
// Make sure I always report at least one, when running WinXP with the /ONECPU switch, // Make sure I always report at least one, when running WinXP with the /ONECPU switch,
// it likes to report 0 processors for some reason. // it likes to report 0 processors for some reason.

View File

@ -14,7 +14,7 @@ bool CheckSSE42Technology(void);
bool CheckSSE4aTechnology(void); bool CheckSSE4aTechnology(void);
const char* GetProcessorVendorId(void); const char* GetProcessorVendorId(void);
const char* GetProcessorBrand(void); const char* GetProcessorBrand(bool bRemovePadding);
const CPUInformation& GetCPUInformation(void); const CPUInformation& GetCPUInformation(void);