378 lines
12 KiB
C++
378 lines
12 KiB
C++
#include "dl_infoware.h"
|
||
|
||
#include <iostream>
|
||
|
||
#include "io/dl_log.h"
|
||
#include "base/dl_string.h"
|
||
|
||
#if DL_PLATFORM != DL_PLATFORM_ANDROID && DL_PLATFORM != DL_PLATFORM_APPLE
|
||
|
||
namespace dl::Infoware
|
||
{
|
||
|
||
static const char* cache_type_name(iware::cpu::cache_type_t cache_type) noexcept {
|
||
switch (cache_type) {
|
||
case iware::cpu::cache_type_t::unified:
|
||
return "Unified";
|
||
case iware::cpu::cache_type_t::instruction:
|
||
return "Instruction";
|
||
case iware::cpu::cache_type_t::data:
|
||
return "Data";
|
||
case iware::cpu::cache_type_t::trace:
|
||
return "Trace";
|
||
default:
|
||
return "Unknown";
|
||
}
|
||
}
|
||
|
||
static const char* architecture_name(iware::cpu::architecture_t architecture) noexcept {
|
||
switch (architecture) {
|
||
case iware::cpu::architecture_t::x64:
|
||
return "x64";
|
||
case iware::cpu::architecture_t::arm:
|
||
return "ARM";
|
||
case iware::cpu::architecture_t::itanium:
|
||
return "Itanium";
|
||
case iware::cpu::architecture_t::x86:
|
||
return "x86";
|
||
default:
|
||
return "Unknown";
|
||
}
|
||
}
|
||
|
||
static const char* endianness_name(iware::cpu::endianness_t endianness) noexcept {
|
||
switch (endianness) {
|
||
case iware::cpu::endianness_t::little:
|
||
return "Little-Endian";
|
||
case iware::cpu::endianness_t::big:
|
||
return "Big-Endian";
|
||
default:
|
||
return "Unknown";
|
||
}
|
||
}
|
||
|
||
void DumpCpu()
|
||
{
|
||
std::cout << "Infoware version " << iware::version << '\n';
|
||
|
||
{
|
||
const auto quantities = iware::cpu::quantities();
|
||
std::cout << "\n"
|
||
" Quantities:\n"
|
||
<< " Logical CPUs : " << quantities.logical << '\n'
|
||
<< " Physical CPUs: " << quantities.physical << '\n'
|
||
<< " CPU packages : " << quantities.packages << '\n';
|
||
}
|
||
|
||
{
|
||
std::cout << "\n"
|
||
" Caches:\n";
|
||
for (auto i = 1u; i <= 3; ++i) {
|
||
const auto cache = iware::cpu::cache(i);
|
||
std::cout << " L" << i << ":\n"
|
||
<< " Size : " << cache.size << "B\n"
|
||
<< " Line size : " << cache.line_size << "B\n"
|
||
<< " Associativity: " << static_cast<unsigned int>(cache.associativity) << '\n'
|
||
<< " Type : " << cache_type_name(cache.type) << '\n';
|
||
}
|
||
}
|
||
|
||
{
|
||
std::cout << "\n"
|
||
<< " Architecture: " << architecture_name(iware::cpu::architecture()) << '\n'
|
||
<< " Frequency: " << iware::cpu::frequency() << " Hz\n"
|
||
<< " Endianness: " << endianness_name(iware::cpu::endianness()) << '\n'
|
||
<< " Model name: " << iware::cpu::model_name() << '\n'
|
||
<< " Vendor ID: " << iware::cpu::vendor_id() << '\n';
|
||
}
|
||
|
||
{
|
||
std::cout << std::boolalpha
|
||
<< "\n"
|
||
" Instruction set support:\n";
|
||
for (auto&& set : { std::make_pair("3D-now!", iware::cpu::instruction_set_t::s3d_now), //
|
||
std::make_pair("MMX ", iware::cpu::instruction_set_t::mmx), //
|
||
std::make_pair("SSE ", iware::cpu::instruction_set_t::sse), //
|
||
std::make_pair("SSE2 ", iware::cpu::instruction_set_t::sse2), //
|
||
std::make_pair("SSE3 ", iware::cpu::instruction_set_t::sse3), //
|
||
std::make_pair("AVX ", iware::cpu::instruction_set_t::avx) })
|
||
std::cout << " " << set.first << ": " << iware::cpu::instruction_set_supported(set.second) << '\n';
|
||
}
|
||
|
||
std::cout << '\n';
|
||
}
|
||
|
||
|
||
static const char* vendor_name(iware::gpu::vendor_t vendor) noexcept {
|
||
switch (vendor) {
|
||
case iware::gpu::vendor_t::intel:
|
||
return "Intel";
|
||
case iware::gpu::vendor_t::amd:
|
||
return "AMD";
|
||
case iware::gpu::vendor_t::nvidia:
|
||
return "NVidia";
|
||
case iware::gpu::vendor_t::microsoft:
|
||
return "Microsoft";
|
||
case iware::gpu::vendor_t::qualcomm:
|
||
return "Qualcomm";
|
||
case iware::gpu::vendor_t::apple:
|
||
return "Apple";
|
||
default:
|
||
return "Unknown";
|
||
}
|
||
}
|
||
|
||
void DumpGpu()
|
||
{
|
||
std::cout << "Infoware version " << iware::version << '\n';
|
||
|
||
{
|
||
const auto device_properties = iware::gpu::device_properties();
|
||
std::cout << "\n"
|
||
" Properties:\n";
|
||
if (device_properties.empty())
|
||
std::cout << " No detection methods enabled\n";
|
||
else
|
||
for (auto i = 0u; i < device_properties.size(); ++i) {
|
||
const auto& properties_of_device = device_properties[i];
|
||
std::cout << " Device #" << (i + 1) << ":\n"
|
||
<< " Vendor : " << vendor_name(properties_of_device.vendor) << '\n'
|
||
<< " Name : " << properties_of_device.name << '\n'
|
||
<< " RAM size : " << properties_of_device.memory_size << "B\n"
|
||
<< " Cache size : " << properties_of_device.cache_size << "B\n"
|
||
<< " Max frequency: " << properties_of_device.max_frequency << "Hz\n";
|
||
}
|
||
}
|
||
|
||
std::cout << '\n';
|
||
}
|
||
|
||
//static void print_named_id(const char* subsystem, std::uint64_t pci_id) {
|
||
// std::cout << "Unrecognised " << subsystem << " with ID " << format_pci_id{ pci_id } << '\n';
|
||
//}
|
||
|
||
//static bool print_vendor(std::uint64_t vendor_id, const char* vendor_name) {
|
||
// if (vendor_name)
|
||
// std::cout << "Vendor " << format_pci_id{ vendor_id } << ' ' << vendor_name << '\n';
|
||
// else
|
||
// print_named_id("vendor", vendor_id);
|
||
|
||
// return vendor_name;
|
||
//}
|
||
|
||
void DumpPci()
|
||
{
|
||
/*std::cout << "Infoware version " << iware::version << '\n';
|
||
|
||
if (argv[1] == nullptr)
|
||
std::cout << "Usage: " << argv[0] << " <vendor_id> [device_id]" << '\n';
|
||
else {
|
||
const auto vendor_id = std::strtoull(argv[1], nullptr, 0);
|
||
|
||
if (argv[2] == nullptr) {
|
||
if (!print_vendor(vendor_id, iware::pci::identify_vendor(vendor_id)))
|
||
return 1;
|
||
}
|
||
else {
|
||
const auto device_id = std::strtoull(argv[2], nullptr, 0);
|
||
|
||
const auto device = iware::pci::identify_device(vendor_id, device_id);
|
||
const auto vendor_ok = print_vendor(vendor_id, device.vendor_name);
|
||
|
||
if (device.device_name) {
|
||
std::cout << "Device " << format_pci_id{ device_id } << ' ' << device.device_name << '\n';
|
||
}
|
||
else
|
||
print_named_id("device", device_id);
|
||
|
||
if (!vendor_ok || !device.device_name)
|
||
return (vendor_ok ? 0 : 1) | (device.device_name ? 0 : 2);
|
||
}
|
||
}*/
|
||
}
|
||
|
||
static const char* kernel_variant_name(iware::system::kernel_t variant) noexcept {
|
||
switch (variant) {
|
||
case iware::system::kernel_t::windows_nt:
|
||
return "Windows NT";
|
||
case iware::system::kernel_t::linux:
|
||
return "Linux";
|
||
case iware::system::kernel_t::darwin:
|
||
return "Darwin";
|
||
default:
|
||
return "Unknown";
|
||
}
|
||
}
|
||
|
||
void DumpSytem()
|
||
{
|
||
std::cout << "Infoware version " << iware::version << '\n';
|
||
|
||
{
|
||
std::cout << "\n"
|
||
" Connected HIDs:\n"
|
||
<< " Mice : " << iware::system::mouse_amount() << '\n'
|
||
<< " Keyboards: " << iware::system::keyboard_amount() << '\n'
|
||
<< " Other : " << iware::system::other_HID_amount() << '\n';
|
||
}
|
||
|
||
{
|
||
const auto memory = iware::system::memory();
|
||
std::cout << "\n"
|
||
" Memory:\n"
|
||
" Physical:\n"
|
||
<< " Available: " << memory.physical_available << "B\n"
|
||
<< " Total : " << memory.physical_total << "B\n"
|
||
<< " Virtual:\n"
|
||
<< " Available: " << memory.virtual_available << "B\n"
|
||
<< " Total : " << memory.virtual_total << "B\n";
|
||
}
|
||
|
||
{
|
||
const auto kernel_info = iware::system::kernel_info();
|
||
std::cout << "\n"
|
||
" Kernel:\n"
|
||
<< " Variant: " << kernel_variant_name(kernel_info.variant) << '\n'
|
||
<< " Version: " << kernel_info.major << '.' << kernel_info.minor << '.' << kernel_info.patch << " build " << kernel_info.build_number << '\n';
|
||
}
|
||
|
||
{
|
||
const auto OS_info = iware::system::OS_info();
|
||
std::cout << "\n"
|
||
" OS:\n"
|
||
<< " Name : " << OS_info.name << '\n'
|
||
<< " Full name: " << OS_info.full_name << '\n'
|
||
<< " Version : " << OS_info.major << '.' << OS_info.minor << '.' << OS_info.patch << " build " << OS_info.build_number << '\n';
|
||
}
|
||
|
||
{
|
||
const auto displays = iware::system::displays();
|
||
std::cout << "\n"
|
||
" Displays:\n";
|
||
if (displays.empty())
|
||
std::cout << " None connected or no detection method enabled\n";
|
||
else
|
||
for (auto i = 0u; i < displays.size(); ++i) {
|
||
const auto& display = displays[i];
|
||
std::cout << " #" << (i + 1) << ":\n"
|
||
<< " Resolution : " << display.width << 'x' << display.height << '\n'
|
||
<< " DPI : " << display.dpi << '\n'
|
||
<< " Colour depth: " << display.bpp << "b\n"
|
||
<< " Refresh rate: " << display.refresh_rate << "Hz\n";
|
||
}
|
||
}
|
||
|
||
{
|
||
const auto configs = iware::system::available_display_configurations();
|
||
std::cout << "\n"
|
||
" Display configurations:\n";
|
||
if (configs.empty())
|
||
std::cout << " No displays connected, no detection method enabled, or not supported\n";
|
||
else
|
||
for (auto i = 0u; i < configs.size(); ++i) {
|
||
const auto& display_configs = configs[i];
|
||
std::cout << " Display #" << (i + 1) << ":\n";
|
||
|
||
for (auto j = 0u; j < display_configs.size(); ++j) {
|
||
const auto& config = display_configs[j];
|
||
std::cout << " #" << (j + 1) << ":\n"
|
||
<< " Resolution : " << config.width << 'x' << config.height << '\n'
|
||
<< " Refresh rates: ";
|
||
|
||
bool first = true;
|
||
for (auto rate : config.refresh_rates) {
|
||
if (first)
|
||
first = false;
|
||
else
|
||
std::cout << ", ";
|
||
|
||
std::cout << rate << "Hz";
|
||
}
|
||
|
||
std::cout << '\n';
|
||
}
|
||
}
|
||
}
|
||
|
||
std::cout << '\n';
|
||
}
|
||
|
||
void DumpSimple()
|
||
{
|
||
std::string ret;
|
||
//ret += fmt::format("Infoware版本:{}\n", iware::version);
|
||
|
||
{
|
||
const auto quantities = iware::cpu::quantities();
|
||
ret += fmt::format("{:-^64}\n", iware::cpu::model_name());
|
||
ret += fmt::format("内核 :{}\n", quantities.physical);
|
||
ret += fmt::format("逻辑处理器 :{}\n", quantities.logical);
|
||
ret += fmt::format("架构 :{}\n", architecture_name(iware::cpu::architecture()));
|
||
float freq = iware::cpu::frequency() / 1000.0f;
|
||
freq /= 1000.0f;
|
||
freq /= 1000.0f;
|
||
ret += fmt::format("频率 :{:.2f}GHz\n", freq);
|
||
ret += fmt::format("字节序 :{}\n", endianness_name(iware::cpu::endianness()));
|
||
|
||
ret += fmt::format("{:-^64}\n", "指令集");
|
||
for (auto&& set : { std::make_pair("3D-now!", iware::cpu::instruction_set_t::s3d_now), //
|
||
std::make_pair("MMX ", iware::cpu::instruction_set_t::mmx), //
|
||
std::make_pair("SSE ", iware::cpu::instruction_set_t::sse), //
|
||
std::make_pair("SSE2 ", iware::cpu::instruction_set_t::sse2), //
|
||
std::make_pair("SSE3 ", iware::cpu::instruction_set_t::sse3), //
|
||
std::make_pair("AVX ", iware::cpu::instruction_set_t::avx) })
|
||
|
||
ret += fmt::format("{} :{}\n", set.first, iware::cpu::instruction_set_supported(set.second));
|
||
}
|
||
{
|
||
|
||
ret += fmt::format("{:-^64}\n", "IO设备");
|
||
ret += fmt::format("鼠标 :{}\n", iware::system::mouse_amount());
|
||
ret += fmt::format("键盘 :{}\n", iware::system::keyboard_amount());
|
||
ret += fmt::format("其他 :{}\n", iware::system::other_HID_amount());
|
||
|
||
{
|
||
ret += fmt::format("{:-^64}\n", "内存");
|
||
double k = 1024 * 1024 * 1024;
|
||
const auto memory = iware::system::memory();
|
||
ret += fmt::format("总计 :{:.2f}GB\n", memory.physical_total / k);
|
||
ret += fmt::format("空闲 :{:.2f}GB\n", memory.physical_available / k);
|
||
}
|
||
|
||
{
|
||
const auto OS_info = iware::system::OS_info();
|
||
ret += fmt::format("{:-^64}\n", OS_info.full_name);
|
||
ret += fmt::format("系统 :{}\n", OS_info.name);
|
||
ret += fmt::format("版本 :{}.{}.{} build {}\n", OS_info.major, OS_info.minor, OS_info.patch, OS_info.build_number);
|
||
}
|
||
|
||
}
|
||
log_msg0(String::FillEndl(ret, '|'));
|
||
}
|
||
|
||
|
||
std::string GetCpuId()
|
||
{
|
||
const auto quantities = iware::cpu::quantities();
|
||
return iware::cpu::model_name() +
|
||
std::to_string(quantities.physical) +
|
||
std::to_string(quantities.logical) +
|
||
architecture_name(iware::cpu::architecture());
|
||
}
|
||
}
|
||
#else
|
||
namespace dl::Infoware
|
||
{
|
||
void DumpCpu() { log_warn0("本平台暂未支持!");}
|
||
void DumpGpu() { log_warn0("本平台暂未支持!");}
|
||
void DumpPci() { log_warn0("本平台暂未支持!");}
|
||
void DumpSystem() { log_warn0("本平台暂未支持!");}
|
||
void DumpSimple() { log_warn0("本平台暂未支持!");}
|
||
|
||
|
||
std::string GetCpuId()
|
||
{
|
||
return "cpu id";
|
||
}
|
||
}
|
||
#endif |