summaryrefslogtreecommitdiff
path: root/src/common/memory_detect.cpp
diff options
context:
space:
mode:
authorGravatar Morph2020-05-17 14:45:12 -0400
committerGravatar Morph2020-05-17 14:45:12 -0400
commit9a36d8600c0b263b4b3861b64051a4f62b4251d2 (patch)
tree65714fc37ebf294332c533db8b2dcefb67ef2562 /src/common/memory_detect.cpp
parentMerge pull request #3665 from bunnei/device-save (diff)
downloadyuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar.gz
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.tar.xz
yuzu-9a36d8600c0b263b4b3861b64051a4f62b4251d2.zip
main: Log host system memory parameters
Logs both physical memory and swapfile sizes, this is useful for support.
Diffstat (limited to '')
-rw-r--r--src/common/memory_detect.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/common/memory_detect.cpp b/src/common/memory_detect.cpp
new file mode 100644
index 000000000..b59a45d55
--- /dev/null
+++ b/src/common/memory_detect.cpp
@@ -0,0 +1,57 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#ifdef _WIN32
6// clang-format off
7#include <windows.h>
8#include <sysinfoapi.h>
9// clang-format on
10#else
11#include <sys/types.h>
12#ifdef __APPLE__
13#include <sys/sysctl.h>
14#else
15#include <sys/sysinfo.h>
16#endif
17#endif
18
19#include "common/memory_detect.h"
20
21namespace Common {
22
23// Detects the RAM and Swapfile sizes
24static MemoryInfo Detect() {
25 MemoryInfo mem_info{};
26
27#ifdef _WIN32
28 MEMORYSTATUSEX memorystatus;
29 memorystatus.dwLength = sizeof(memorystatus);
30 GlobalMemoryStatusEx(&memorystatus);
31 mem_info.TotalPhysicalMemory = memorystatus.ullTotalPhys;
32 mem_info.TotalSwapMemory = memorystatus.ullTotalPageFile - mem_info.TotalPhysicalMemory;
33#elif defined(__APPLE__)
34 u64 ramsize;
35 struct xsw_usage vmusage;
36 // hw and vm are defined in sysctl.h
37 // https://github.com/apple/darwin-xnu/blob/master/bsd/sys/sysctl.h#L471
38 sysctlbyname(hw.memsize, &ramsize, sizeof(ramsize), NULL, 0);
39 sysctlbyname(vm.swapusage, &vmusage, sizeof(vmusage), NULL, 0);
40 mem_info.TotalPhysicalMemory = ramsize;
41 mem_info.TotalSwapMemory = vmusage.xsu_total;
42#else
43 struct sysinfo meminfo;
44 sysinfo(&meminfo);
45 mem_info.TotalPhysicalMemory = meminfo.totalram;
46 mem_info.TotalSwapMemory = meminfo.totalswap;
47#endif
48
49 return mem_info;
50}
51
52const MemoryInfo& GetMemInfo() {
53 static MemoryInfo mem_info = Detect();
54 return mem_info;
55}
56
57} // namespace Common \ No newline at end of file