diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 00196d1025..5a9d07fba0 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -61,6 +61,7 @@ #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" @@ -214,10 +215,10 @@ GMainWindow::GMainWindow() LOG_INFO(Frontend, "Host CPU: {}", cpu_string); #endif LOG_INFO(Frontend, "Host OS: {}", QSysInfo::prettyProductName().toStdString()); - LOG_INFO(Frontend, "Host RAM: {:.2f} GB", - Common::GetMemInfo().TotalPhysicalMemory / 1024.0f / 1024 / 1024); - LOG_INFO(Frontend, "Host Swap: {:.2f} GB", - Common::GetMemInfo().TotalSwapMemory / 1024.0f / 1024 / 1024); + 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 65fd3ad1a6..48914c9609 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 diff --git a/src/common/literals.h b/src/common/literals.h new file mode 100644 index 0000000000..d55fed40be --- /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 index 8cff6ec379..e97ff9af20 100644 --- a/src/common/memory_detect.cpp +++ b/src/common/memory_detect.cpp @@ -3,10 +3,9 @@ // Refer to the license.txt file included. #ifdef _WIN32 -// clang-format off #include +// Depends on coming first #include -// clang-format on #else #include #if defined(__APPLE__) || defined(__FreeBSD__) @@ -23,15 +22,15 @@ namespace Common { // Detects the RAM and Swapfile sizes -static MemoryInfo Detect() { +const MemoryInfo GetMemInfo() { MemoryInfo mem_info{}; #ifdef _WIN32 MEMORYSTATUSEX memorystatus; memorystatus.dwLength = sizeof(memorystatus); GlobalMemoryStatusEx(&memorystatus); - mem_info.TotalPhysicalMemory = memorystatus.ullTotalPhys; - mem_info.TotalSwapMemory = memorystatus.ullTotalPageFile - mem_info.TotalPhysicalMemory; + 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; @@ -42,32 +41,27 @@ static MemoryInfo Detect() { // 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.TotalPhysicalMemory = ramsize; - mem_info.TotalSwapMemory = vmusage.xsu_total; + 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.TotalPhysicalMemory = physmem; - mem_info.TotalSwapMemory = swap_total; + mem_info.total_physical_memory = physmem; + mem_info.total_swap_memory = swap_total; #elif defined(__linux__) struct sysinfo meminfo; sysinfo(&meminfo); - mem_info.TotalPhysicalMemory = meminfo.totalram; - mem_info.TotalSwapMemory = meminfo.totalswap; + mem_info.total_physical_memory = meminfo.totalram; + mem_info.total_swap_memory = meminfo.totalswap; #else - mem_info.TotalPhysicalMemory = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE); - mem_info.TotalSwapMemory = 0; + mem_info.total_physical_memory = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE); + mem_info.total_swap_memory = 0; #endif return mem_info; } -const MemoryInfo& GetMemInfo() { - static MemoryInfo mem_info = Detect(); - return mem_info; -} - -} // namespace Common \ No newline at end of file +} // namespace Common diff --git a/src/common/memory_detect.h b/src/common/memory_detect.h index a73c0f3f4c..eb07d8ab0e 100644 --- a/src/common/memory_detect.h +++ b/src/common/memory_detect.h @@ -9,14 +9,14 @@ namespace Common { struct MemoryInfo { - u64 TotalPhysicalMemory{}; - u64 TotalSwapMemory{}; + 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 */ -const MemoryInfo& GetMemInfo(); +[[nodiscard]] const MemoryInfo GetMemInfo(); -} // namespace Common \ No newline at end of file +} // namespace Common