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::parse()
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())
165 os.writeEntry(
"vendor_id", vendor_id);
167 if (!model_name.empty())
169 os.writeEntry(
"model_name", model_name);
172 os.writeEntryIfDifferent<
int>(
"cpu_family", -1, cpu_family);
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);