mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 00:15:51 +00:00
Fix retrieval of CPU info (number of CPUs, speed, flags, vendor) on FreeBSD,
using 'dmesg' and 'sysctl' instead of /proc/cpuinfo that is Linux-specific.
This commit is contained in:
@@ -208,27 +208,28 @@ bool SystemStats::isOperatingSystem64Bit()
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
namespace BSDStatsHelpers
|
namespace BSDStatsHelpers
|
||||||
{
|
{
|
||||||
String getCpuInfo (const char* const key)
|
String getDmesgInfo (const char* const key)
|
||||||
{
|
{
|
||||||
StringArray lines;
|
StringArray lines;
|
||||||
File ("/proc/cpuinfo").readLines (lines);
|
File ("/var/run/dmesg.boot").readLines (lines);
|
||||||
|
|
||||||
for (int i = lines.size(); --i >= 0;) // (NB - it's important that this runs in reverse order)
|
for (int i = lines.size(); --i >= 0;) // (NB - it's important that this runs in reverse order)
|
||||||
if (lines[i].startsWithIgnoreCase (key))
|
if (lines[i].startsWith (key))
|
||||||
return lines[i].fromFirstOccurrenceOf (":", false, false).trim();
|
return lines[i].substring (strlen (key)).trim();
|
||||||
|
|
||||||
return String::empty;
|
return String::empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String SystemStats::getCpuVendor()
|
String SystemStats::getCpuVendor()
|
||||||
{
|
{
|
||||||
return BSDStatsHelpers::getCpuInfo ("vendor_id");
|
return BSDStatsHelpers::getDmesgInfo (" Origin =").upToFirstOccurrenceOf (" ", false, false).unquoted();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SystemStats::getCpuSpeedInMegaherz()
|
int SystemStats::getCpuSpeedInMegaherz()
|
||||||
{
|
{
|
||||||
return roundToInt (BSDStatsHelpers::getCpuInfo ("cpu MHz").getFloatValue());
|
return roundToInt (BSDStatsHelpers::getDmesgInfo ("CPU:").fromLastOccurrenceOf ("(", false, false).upToFirstOccurrenceOf ("-MHz", false, false).getFloatValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
int SystemStats::getMemorySizeInMegabytes()
|
int SystemStats::getMemorySizeInMegabytes()
|
||||||
@@ -298,15 +299,19 @@ String SystemStats::getDisplayLanguage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
SystemStats::CPUFlags::CPUFlags()
|
void CPUInformation::initialise() noexcept
|
||||||
{
|
{
|
||||||
const String flags (BSDStatsHelpers::getCpuInfo ("flags"));
|
const String features (BSDStatsHelpers::getDmesgInfo (" Features="));
|
||||||
hasMMX = flags.contains ("mmx");
|
hasMMX = features.contains ("MMX");
|
||||||
hasSSE = flags.contains ("sse");
|
hasSSE = features.contains ("SSE");
|
||||||
hasSSE2 = flags.contains ("sse2");
|
hasSSE2 = features.contains ("SSE2");
|
||||||
has3DNow = flags.contains ("3dnow");
|
const String features2 (BSDStatsHelpers::getDmesgInfo (" Features2="));
|
||||||
|
hasSSE3 = features2.contains ("SSE3");
|
||||||
|
const String amdfeatures2 (BSDStatsHelpers::getDmesgInfo (" AMD Features2="));
|
||||||
|
has3DNow = amdfeatures2.contains ("3DNow!");
|
||||||
|
|
||||||
numCpus = BSDStatsHelpers::getCpuInfo ("processor").getIntValue() + 1;
|
GETSYSCTL("hw.ncpu", numCpus);
|
||||||
|
if (numCpus == -1) numCpus = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user