Skip to content

Commit

Permalink
Added logic to correctly parse ARM cpuinfo on ARM based macOS Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-odintsov committed Jul 30, 2024
1 parent 3cca3b5 commit 5f7ce6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
26 changes: 14 additions & 12 deletions src/fast_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2193,28 +2193,30 @@ bool get_cpu_flags(std::vector<std::string>& flags) {
return false;
}

std::string get_cpu_model() {
bool get_cpu_model(std::string& cpu_model) {
extern log4cpp::Category& logger;

std::ifstream cpuinfo_file("/proc/cpuinfo");
boost::regex processor_model_pattern("^model name\\s+:\\s(.*?)$");

if (!cpuinfo_file.is_open()) {
logger << log4cpp::Priority::ERROR << "License: could not open cpuinfo";
return "";
logger << log4cpp::Priority::ERROR << "Could not open /proc/cpuinfo";
return false;
}

boost::regex processor_model_pattern("^model name\\s+:\\s(.*?)$");
std::string line;

while (getline(cpuinfo_file, line)) {
boost::match_results<std::string::const_iterator> regex_results;

if (boost::regex_match(line, regex_results, processor_model_pattern)) {
return regex_results[1];
cpu_model = regex_results[1];
return true;
}
}

// For new ARMs (Cavium Thunder X for example) we do not have model name in 4.10 kernel
#ifdef __aarch64__
// For ARM CPUs we have another format
// Even if we run in x86_64 mode we can have cpuinfo with such information on ARM64 based macOS platforms
std::string implementer;
std::string part;
std::string revision;
Expand Down Expand Up @@ -2247,13 +2249,13 @@ std::string get_cpu_model() {

// If we fould all of them, use these fields as model
if (implementer.size() > 0 && part.size() > 0 && revision.size() > 0) {
return "implementer: " + implementer + " part: " + part + " revision: " + revision;
} else {
// logger << log4cpp::Priority::ERROR << "implementer: " << implementer << " part: " << part << " revision: " << revision;
cpu_model = "implementer: " + implementer + " part: " + part + " revision: " + revision;
return true;
}
#endif

return "";
// logger << log4cpp::Priority::ERROR << "implementer: " << implementer << " part: " << part << " revision: " << revision;

return false;
}

// returns forwarding status as string
Expand Down
2 changes: 1 addition & 1 deletion src/fast_library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool execute_web_request(const std::string& address_param,
const std::map<std::string, std::string>& headers,
std::string& error_text);
unsigned int get_total_memory();
std::string get_cpu_model();
bool get_cpu_model(std::string& cpu_model);
bool execute_web_request_secure(std::string address,
std::string request_type,
std::string post_data,
Expand Down
6 changes: 5 additions & 1 deletion src/fastnetmon_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,11 @@ void send_usage_data_to_reporting_server() {
stats["traffic_db"] = false;
stats["prometheus"] = false;

stats["cpu_model"] = get_cpu_model();
std::string cpu_model;
get_cpu_model(cpu_model);

stats["cpu_model"] = cpu_model;

stats["cpu_logical_cores"] = get_logical_cpus_number();

// Mbytes
Expand Down

0 comments on commit 5f7ce6b

Please sign in to comment.