mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-12 13:00:01 -08:00
[Oracle] Apply clang-format to the memory querier
This commit is contained in:
parent
88ee27b7f0
commit
1d1a6f579b
2 changed files with 8 additions and 58 deletions
|
|
@ -11,10 +11,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
#include <mach/mach.h>
|
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qulonglong SystemMemoryQuerier::totalMemoryBytes()
|
qulonglong SystemMemoryQuerier::totalMemoryBytes()
|
||||||
|
|
@ -23,15 +21,17 @@ qulonglong SystemMemoryQuerier::totalMemoryBytes()
|
||||||
|
|
||||||
MEMORYSTATUSEX statex;
|
MEMORYSTATUSEX statex;
|
||||||
statex.dwLength = sizeof(statex);
|
statex.dwLength = sizeof(statex);
|
||||||
if (GlobalMemoryStatusEx(&statex))
|
if (GlobalMemoryStatusEx(&statex)) {
|
||||||
return statex.ullTotalPhys;
|
return statex.ullTotalPhys;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#elif defined(Q_OS_LINUX)
|
#elif defined(Q_OS_LINUX)
|
||||||
|
|
||||||
QFile file("/proc/meminfo");
|
QFile file("/proc/meminfo");
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
while (!in.atEnd()) {
|
while (!in.atEnd()) {
|
||||||
|
|
@ -42,8 +42,9 @@ qulonglong SystemMemoryQuerier::totalMemoryBytes()
|
||||||
#else
|
#else
|
||||||
QStringList parts = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
QStringList parts = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||||
#endif
|
#endif
|
||||||
if (parts.size() >= 2)
|
if (parts.size() >= 2) {
|
||||||
return parts[1].toULongLong() * 1024; // kB → bytes
|
return parts[1].toULongLong() * 1024; // kB → bytes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -54,62 +55,12 @@ qulonglong SystemMemoryQuerier::totalMemoryBytes()
|
||||||
qulonglong memsize = 0;
|
qulonglong memsize = 0;
|
||||||
size_t len = sizeof(memsize);
|
size_t len = sizeof(memsize);
|
||||||
|
|
||||||
if (sysctl(mib, 2, &memsize, &len, nullptr, 0) == 0)
|
if (sysctl(mib, 2, &memsize, &len, nullptr, 0) == 0) {
|
||||||
return memsize;
|
return memsize;
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
qulonglong SystemMemoryQuerier::availableMemoryBytes()
|
|
||||||
{
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
|
|
||||||
MEMORYSTATUSEX statex;
|
|
||||||
statex.dwLength = sizeof(statex);
|
|
||||||
if (GlobalMemoryStatusEx(&statex))
|
|
||||||
return statex.ullAvailPhys;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#elif defined(Q_OS_LINUX)
|
|
||||||
|
|
||||||
QFile file("/proc/meminfo");
|
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
QTextStream in(&file);
|
|
||||||
while (!in.atEnd()) {
|
|
||||||
QString line = in.readLine();
|
|
||||||
if (line.startsWith("MemAvailable:")) {
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
QStringList parts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
|
||||||
#else
|
|
||||||
QStringList parts = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
|
||||||
#endif
|
|
||||||
if (parts.size() >= 2)
|
|
||||||
return parts[1].toULongLong() * 1024;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#elif defined(Q_OS_MACOS)
|
|
||||||
|
|
||||||
vm_size_t pageSize;
|
|
||||||
host_page_size(mach_host_self(), &pageSize);
|
|
||||||
|
|
||||||
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
|
|
||||||
vm_statistics64_data_t vmstat;
|
|
||||||
|
|
||||||
if (host_statistics64(mach_host_self(), HOST_VM_INFO, (host_info64_t)&vmstat, &count) != KERN_SUCCESS)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
qulonglong freeBytes = (qulonglong)vmstat.free_count * (qulonglong)pageSize;
|
|
||||||
|
|
||||||
return freeBytes;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ class SystemMemoryQuerier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static qulonglong totalMemoryBytes();
|
static qulonglong totalMemoryBytes();
|
||||||
static qulonglong availableMemoryBytes();
|
|
||||||
|
|
||||||
static bool hasAtLeastGiB(int gib)
|
static bool hasAtLeastGiB(int gib)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue