diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index b11692f59..5a9d07fba 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -61,10 +61,12 @@ #include "common/common_paths.h" #include "common/detached_tasks.h" #include "common/file_util.h" +#include "common/literals.h" #include "common/logging/backend.h" #include "common/logging/filter.h" #include "common/logging/log.h" #include "common/logging/text_formatter.h" +#include "common/memory_detect.h" #include "common/microprofile.h" #include "common/scm_rev.h" #include "common/scope_exit.h" @@ -213,6 +215,10 @@ GMainWindow::GMainWindow() LOG_INFO(Frontend, "Host CPU: {}", cpu_string); #endif LOG_INFO(Frontend, "Host OS: {}", QSysInfo::prettyProductName().toStdString()); + const auto& mem_info = Common::GetMemInfo(); + using namespace Common::Literals; + LOG_INFO(Frontend, "Host RAM: {:.2f} GiB", mem_info.total_physical_memory / f64{1_GiB}); + LOG_INFO(Frontend, "Host Swap: {:.2f} GiB", mem_info.total_swap_memory / f64{1_GiB}); UpdateWindowTitle(); show(); diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index a68983b05..48914c960 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -74,6 +74,7 @@ add_library(common STATIC file_util.h hash.h linear_disk_cache.h + literals.h logging/backend.cpp logging/backend.h logging/filter.cpp @@ -83,6 +84,8 @@ add_library(common STATIC logging/text_formatter.cpp logging/text_formatter.h math_util.h + memory_detect.cpp + memory_detect.h memory_ref.h memory_ref.cpp microprofile.cpp diff --git a/src/common/literals.h b/src/common/literals.h new file mode 100644 index 000000000..d55fed40b --- /dev/null +++ b/src/common/literals.h @@ -0,0 +1,31 @@ +// Copyright 2021 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace Common::Literals { + +constexpr u64 operator""_KiB(unsigned long long int x) { + return 1024ULL * x; +} + +constexpr u64 operator""_MiB(unsigned long long int x) { + return 1024_KiB * x; +} + +constexpr u64 operator""_GiB(unsigned long long int x) { + return 1024_MiB * x; +} + +constexpr u64 operator""_TiB(unsigned long long int x) { + return 1024_GiB * x; +} + +constexpr u64 operator""_PiB(unsigned long long int x) { + return 1024_TiB * x; +} + +} // namespace Common::Literals diff --git a/src/common/memory_detect.cpp b/src/common/memory_detect.cpp new file mode 100644 index 000000000..e97ff9af2 --- /dev/null +++ b/src/common/memory_detect.cpp @@ -0,0 +1,67 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#ifdef _WIN32 +#include +// Depends on coming first +#include +#else +#include +#if defined(__APPLE__) || defined(__FreeBSD__) +#include +#elif defined(__linux__) +#include +#else +#include +#endif +#endif + +#include "common/memory_detect.h" + +namespace Common { + +// Detects the RAM and Swapfile sizes +const MemoryInfo GetMemInfo() { + MemoryInfo mem_info{}; + +#ifdef _WIN32 + MEMORYSTATUSEX memorystatus; + memorystatus.dwLength = sizeof(memorystatus); + GlobalMemoryStatusEx(&memorystatus); + mem_info.total_physical_memory = memorystatus.ullTotalPhys; + mem_info.total_swap_memory = memorystatus.ullTotalPageFile - mem_info.total_physical_memory; +#elif defined(__APPLE__) + u64 ramsize; + struct xsw_usage vmusage; + std::size_t sizeof_ramsize = sizeof(ramsize); + std::size_t sizeof_vmusage = sizeof(vmusage); + // hw and vm are defined in sysctl.h + // https://github.com/apple/darwin-xnu/blob/master/bsd/sys/sysctl.h#L471 + // sysctlbyname(const char *, void *, size_t *, void *, size_t); + sysctlbyname("hw.memsize", &ramsize, &sizeof_ramsize, nullptr, 0); + sysctlbyname("vm.swapusage", &vmusage, &sizeof_vmusage, nullptr, 0); + mem_info.total_physical_memory = ramsize; + mem_info.total_swap_memory = vmusage.xsu_total; +#elif defined(__FreeBSD__) + u_long physmem, swap_total; + std::size_t sizeof_u_long = sizeof(u_long); + // sysctlbyname(const char *, void *, size_t *, const void *, size_t); + sysctlbyname("hw.physmem", &physmem, &sizeof_u_long, nullptr, 0); + sysctlbyname("vm.swap_total", &swap_total, &sizeof_u_long, nullptr, 0); + mem_info.total_physical_memory = physmem; + mem_info.total_swap_memory = swap_total; +#elif defined(__linux__) + struct sysinfo meminfo; + sysinfo(&meminfo); + mem_info.total_physical_memory = meminfo.totalram; + mem_info.total_swap_memory = meminfo.totalswap; +#else + mem_info.total_physical_memory = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE); + mem_info.total_swap_memory = 0; +#endif + + return mem_info; +} + +} // namespace Common diff --git a/src/common/memory_detect.h b/src/common/memory_detect.h new file mode 100644 index 000000000..eb07d8ab0 --- /dev/null +++ b/src/common/memory_detect.h @@ -0,0 +1,22 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace Common { + +struct MemoryInfo { + u64 total_physical_memory{}; + u64 total_swap_memory{}; +}; + +/** + * Gets the memory info of the host system + * @return Reference to a MemoryInfo struct with the physical and swap memory sizes in bytes + */ +[[nodiscard]] const MemoryInfo GetMemInfo(); + +} // namespace Common