39 static bool split(
const std::string& line, std::string&
key, std::string& val)
44 const auto keyLen = line.find_first_of(
"\t:");
45 const auto sep = line.find(
':');
47 if (keyLen == std::string::npos || sep == std::string::npos)
52 const auto begVal = line.find_first_not_of(
" :", sep);
54 if (begVal == std::string::npos)
59 key = line.substr(0, keyLen);
60 val = line.substr(begVal);
63 for (
auto iter =
key.begin(); iter <
key.end(); ++iter)
112 void Foam::cpuInfo::populate()
115 std::string line,
key, val;
117 std::ifstream is(
"/proc/cpuinfo");
118 while (is.good() && std::getline(is, line))
125 if (
key ==
"processor")
132 else if (
key ==
"vendor_id") { vendor_id = val; }
133 else if (
key ==
"model_name") { model_name = val; }
134 else if (
key ==
"cpu_family") { cpu_family = std::stoi(val); }
135 else if (
key ==
"model") { model = std::stoi(val); }
136 else if (
key ==
"cpu_MHz") { cpu_MHz = std::stof(val); }
137 else if (
key ==
"cpu_cores") { cpu_cores = std::stoi(val); }
138 else if (
key ==
"siblings") { siblings = std::stoi(val); }
163 if (!vendor_id.empty())
167 if (!model_name.empty())
cpuInfo()
Construct and populate with information.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Ostream & writeEntryIfDifferent(const word &key, const T &refValue, const T &value)
Write a keyword/value entry only if the value differs from the reference value.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void writeEntry(const word &keyword, Ostream &os) const
Write cpu-info as dictionary.
A class for handling words, derived from Foam::string.
virtual Ostream & endBlock()
Write end block group.
void writeEntries(Ostream &os) const
Write cpu-info as dictionary entries.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
static bool split(const std::string &line, std::string &key, std::string &val)
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.