39static 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)
112void Foam::cpuInfo::populate()
115 std::string line,
key, val;
117 std::ifstream is(
"/proc/cpuinfo");
118 while (is.good() && std::getline(is, line))
120 if (!
split(line, key, val))
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())
165 os.writeEntry(
"vendor_id", vendor_id);
167 if (!model_name.empty())
169 os.writeEntry(
"model_name", model_name);
173 os.writeEntryIfDifferent<
int>(
"model", -1, model);
174 os.writeEntryIfDifferent<
float>(
"cpu_MHz", 0, cpu_MHz);
175 os.writeEntryIfDifferent<
int>(
"cpu_cores", 0, cpu_cores);
176 os.writeEntryIfDifferent<
int>(
"siblings", 0, siblings);
182 os.beginBlock(keyword);
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
void writeEntries(Ostream &os) const
Write cpu-info as dictionary entries.
void writeEntry(const word &keyword, Ostream &os) const
Write cpu-info as dictionary.
cpuInfo()
Construct and populate with information.
A class for handling words, derived from Foam::string.
static bool split(const std::string &line, std::string &key, std::string &val)
OBJstream os(runTime.globalPath()/outputName)
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.