mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-26 17:12:37 -06:00
Merge pull request #5380 from FearlessTobi/port-3954
Port yuzu-emu/yuzu#3954: "main: Log host system memory parameters"
This commit is contained in:
commit
2967068b87
5 changed files with 129 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
31
src/common/literals.h
Normal file
31
src/common/literals.h
Normal file
|
@ -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
|
67
src/common/memory_detect.cpp
Normal file
67
src/common/memory_detect.cpp
Normal file
|
@ -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 <windows.h>
|
||||
// Depends on <windows.h> coming first
|
||||
#include <sysinfoapi.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <sys/sysctl.h>
|
||||
#elif defined(__linux__)
|
||||
#include <sys/sysinfo.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#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
|
22
src/common/memory_detect.h
Normal file
22
src/common/memory_detect.h
Normal file
|
@ -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
|
Loading…
Reference in a new issue