Integrate cpu_features library to extend system-info output with CPU details

This commit is contained in:
Simon Fels 2018-06-21 07:34:53 +02:00
commit 93c4dfb39f
3 changed files with 46 additions and 0 deletions

View file

@ -2,3 +2,4 @@ add_subdirectory(process-cpp-minimal)
add_subdirectory(android-emugl) add_subdirectory(android-emugl)
add_subdirectory(xdg) add_subdirectory(xdg)
add_subdirectory(backtrace-cpp) add_subdirectory(backtrace-cpp)
add_subdirectory(cpu_features)

View file

@ -30,6 +30,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/external/android-emugl/host/libs/renderControl_dec ${CMAKE_SOURCE_DIR}/external/android-emugl/host/libs/renderControl_dec
${CMAKE_BINARY_DIR}/external/android-emugl/host/libs/renderControl_dec ${CMAKE_BINARY_DIR}/external/android-emugl/host/libs/renderControl_dec
${CMAKE_SOURCE_DIR}/external/glm ${CMAKE_SOURCE_DIR}/external/glm
${CMAKE_SOURCE_DIR}/external/cpu_features/include
) )
protobuf_generate_cpp( protobuf_generate_cpp(
@ -247,6 +248,7 @@ target_link_libraries(anbox-core
${MIRCLIENT_LIBRARIES} ${MIRCLIENT_LIBRARIES}
${LIBSYSTEMD_LDFLAGS} ${LIBSYSTEMD_LDFLAGS}
${LIBSYSTEMD_LIBRARIES} ${LIBSYSTEMD_LIBRARIES}
cpu_features
pthread pthread
process-cpp process-cpp
emugl_common emugl_common

View file

@ -30,6 +30,9 @@
#include "OpenGLESDispatch/EGLDispatch.h" #include "OpenGLESDispatch/EGLDispatch.h"
#include "cpu_features_macros.h"
#include "cpuinfo_x86.h"
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
namespace { namespace {
@ -44,6 +47,7 @@ constexpr const char *os_release_version{"VERSION"};
class SystemInformation { class SystemInformation {
public: public:
SystemInformation() { SystemInformation() {
collect_cpu_info();
collect_os_info(); collect_os_info();
collect_kernel_info(); collect_kernel_info();
collect_graphics_info(); collect_graphics_info();
@ -62,6 +66,13 @@ class SystemInformation {
<< std::endl; << std::endl;
} }
s << "cpu:" << std::endl
<< " arch: " << cpu_info_.arch << std::endl
<< " brand: " << cpu_info_.brand << std::endl
<< " features: " << std::endl;
for (const auto& feature : cpu_info_.features)
s << " - " << feature << std::endl;
s << "os:" << std::endl s << "os:" << std::endl
<< " name: " << os_info_.name << std::endl << " name: " << os_info_.name << std::endl
<< " version: " << os_info_.version << std::endl << " version: " << os_info_.version << std::endl
@ -101,6 +112,32 @@ class SystemInformation {
} }
private: private:
void collect_cpu_info() {
#if defined(CPU_FEATURES_ARCH_X86)
cpu_info_.arch = "x86";
const auto info = cpu_features::GetX86Info();
if (info.features.aes)
cpu_info_.features.push_back("aes");
if (info.features.ssse3)
cpu_info_.features.push_back("ssse3");
if (info.features.ssse3)
cpu_info_.features.push_back("sse4_1");
if (info.features.sse4_1)
cpu_info_.features.push_back("sse4_2");
if (info.features.sse4_2)
cpu_info_.features.push_back("avx");
if (info.features.avx)
cpu_info_.features.push_back("ssse3");
if (info.features.avx2)
cpu_info_.features.push_back("avx2");
char brand_string[49];
cpu_features::FillX86BrandString(brand_string);
cpu_info_.brand = brand_string;
#endif
}
void collect_os_info() { void collect_os_info() {
os_info_.snap_based = !anbox::utils::get_env_value("SNAP").empty(); os_info_.snap_based = !anbox::utils::get_env_value("SNAP").empty();
fs::path path = os_release_path; fs::path path = os_release_path;
@ -173,6 +210,12 @@ class SystemInformation {
} }
} }
struct {
std::string arch;
std::string brand;
std::vector<std::string> features;
} cpu_info_;
struct { struct {
bool snap_based = false; bool snap_based = false;
std::string name = "n/a"; std::string name = "n/a";