Changeset View
Changeset View
Standalone View
Standalone View
head/sysutils/libsysstat/files/patch-memstat.cpp
--- memstat.cpp.orig 2018-07-28 14:33:22 UTC | --- memstat.cpp.orig 2019-01-24 21:43:32 UTC | ||||
+++ memstat.cpp | +++ memstat.cpp | ||||
@@ -26,10 +26,61 @@ | @@ -26,10 +26,58 @@ | ||||
#include "memstat.h" | #include "memstat.h" | ||||
#include "memstat_p.h" | #include "memstat_p.h" | ||||
+#ifdef HAVE_CONFIG_H | |||||
+#include "config.h" | |||||
+#endif | |||||
+#if defined(HAVE_KVM_H) && defined(HAVE_SYSCTL_H) | +#if defined(HAVE_KVM_H) && defined(HAVE_SYSCTL_H) | ||||
+extern "C" | +extern "C" | ||||
+{ | +{ | ||||
+ #include <paths.h> | + #include <paths.h> | ||||
+ #include <unistd.h> | + #include <unistd.h> | ||||
+ #include <fcntl.h> | + #include <fcntl.h> | ||||
+ #include <kvm.h> | + #include <kvm.h> | ||||
Show All 39 Lines | |||||
+ res = res * getpagesize(); | + res = res * getpagesize(); | ||||
+ | + | ||||
+ return res; | + return res; | ||||
+} | +} | ||||
+#endif | +#endif | ||||
MemStatPrivate::MemStatPrivate(MemStat *parent) | MemStatPrivate::MemStatPrivate(MemStat *parent) | ||||
: BaseStatPrivate(parent) | : BaseStatPrivate(parent) | ||||
{ | { | ||||
@@ -52,7 +103,38 @@ void MemStatPrivate::timeout() | @@ -52,7 +100,37 @@ void MemStatPrivate::timeout() | ||||
qulonglong memCached = 0; | qulonglong memCached = 0; | ||||
qulonglong swapTotal = 0; | qulonglong swapTotal = 0; | ||||
qulonglong swapFree = 0; | qulonglong swapFree = 0; | ||||
+#ifdef HAVE_SYSCTL_H | +#ifdef HAVE_SYSCTL_H | ||||
+ memTotal = MemGetByBytes("hw.physmem"); | + memTotal = MemGetByBytes(QLatin1String("hw.physmem")); | ||||
+ memFree = MemGetByPages("vm.stats.vm.v_free_count"); | + memFree = MemGetByPages(QLatin1String("vm.stats.vm.v_free_count")); | ||||
+ memBuffers = MemGetByBytes("vfs.bufspace"); | + memBuffers = MemGetByBytes(QLatin1String("vfs.bufspace")); | ||||
+ memCached = MemGetByPages("vm.stats.vm.v_inactive_count"); | + memCached = MemGetByPages(QLatin1String("vm.stats.vm.v_inactive_count")); | ||||
+#endif | +#endif | ||||
+#ifdef HAVE_KVM_H | +#ifdef HAVE_KVM_H | ||||
+ qulonglong swapUsed = 0; | + qulonglong swapUsed = 0; | ||||
+ kvm_t *kd; | + kvm_t *kd; | ||||
+ struct kvm_swap kswap[16]; /* size taken from pstat/pstat.c */ | + struct kvm_swap kswap[16]; /* size taken from pstat/pstat.c */ | ||||
+ | |||||
+ kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open"); | + kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open"); | ||||
+ if (kd == NULL) | + if (kd == NULL) | ||||
+ kvm_close(kd); | + kvm_close(kd); | ||||
+ | + | ||||
+ if (kvm_getswapinfo(kd, kswap, (sizeof(kswap) / sizeof(kswap[0])), SWIF_DEV_PREFIX) > 0) | + if (kvm_getswapinfo(kd, kswap, (sizeof(kswap) / sizeof(kswap[0])), SWIF_DEV_PREFIX) > 0) | ||||
+ { | + { | ||||
+ int swapd = SwapDevices(); | + int swapd = SwapDevices(); | ||||
+ /* TODO: loop over swap devives */ | + /* TODO: loop over swap devives */ | ||||
+ if (swapd >= 1) | + if (swapd >= 1) | ||||
+ { | + { | ||||
+ swapTotal = static_cast<qulonglong>(kswap[0].ksw_total * getpagesize()); | + swapTotal = static_cast<qulonglong>(kswap[0].ksw_total * getpagesize()); | ||||
+ swapUsed = static_cast<qulonglong>(kswap[0].ksw_used * getpagesize()); | + swapUsed = static_cast<qulonglong>(kswap[0].ksw_used * getpagesize()); | ||||
+ } | + } | ||||
+ | + | ||||
+ kvm_close(kd); | + kvm_close(kd); | ||||
+ } | + } | ||||
+ else | + else | ||||
+ kvm_close(kd); | + kvm_close(kd); | ||||
+#endif | +#endif | ||||
+#ifndef HAVE_SYSCTL_H | +#ifndef HAVE_SYSCTL_H | ||||
const QStringList rows = readAllFile("/proc/meminfo").split(QChar('\n'), QString::SkipEmptyParts); | const QStringList rows = readAllFile("/proc/meminfo").split(QLatin1Char('\n'), QString::SkipEmptyParts); | ||||
for (const QString &row : rows) | for (const QString &row : rows) | ||||
{ | { | ||||
@@ -73,7 +155,7 @@ void MemStatPrivate::timeout() | @@ -73,7 +151,7 @@ void MemStatPrivate::timeout() | ||||
else if(tokens[0] == "SwapFree:") | else if(tokens[0] == QLatin1String("SwapFree:")) | ||||
swapFree = tokens[1].toULong(); | swapFree = tokens[1].toULong(); | ||||
} | } | ||||
- | - | ||||
+#endif | +#endif | ||||
if (mSource == "memory") | if (mSource == QLatin1String("memory")) | ||||
{ | { | ||||
if (memTotal) | if (memTotal) | ||||
@@ -90,8 +172,11 @@ void MemStatPrivate::timeout() | @@ -90,8 +168,11 @@ void MemStatPrivate::timeout() | ||||
{ | { | ||||
if (swapTotal) | if (swapTotal) | ||||
{ | { | ||||
+#ifndef HAVE_KVM_H | +#ifndef HAVE_KVM_H | ||||
float swapUsed_d = static_cast<float>(swapTotal - swapFree) / static_cast<float>(swapTotal); | float swapUsed_d = static_cast<float>(swapTotal - swapFree) / static_cast<float>(swapTotal); | ||||
- | - | ||||
+#else | +#else | ||||
+ float swapUsed_d = static_cast<float>(swapUsed) / static_cast<float>(swapTotal); | + float swapUsed_d = static_cast<float>(swapUsed) / static_cast<float>(swapTotal); | ||||
+#endif | +#endif | ||||
emit swapUpdate(swapUsed_d); | emit swapUpdate(swapUsed_d); | ||||
} | } | ||||
} | } |