aboutsummaryrefslogtreecommitdiff
path: root/sysutils/htop
diff options
context:
space:
mode:
authorPav Lucistnik <pav@FreeBSD.org>2011-08-12 08:30:34 +0000
committerPav Lucistnik <pav@FreeBSD.org>2011-08-12 08:30:34 +0000
commit69623540650261ced8f01f2472f78dcf06b8770b (patch)
treea75c3b366d078d9b2b64e347408db1f570265dcd /sysutils/htop
parent3675765d8309792a6f0e109110a7c3db69246cb2 (diff)
downloadports-69623540650261ced8f01f2472f78dcf06b8770b.tar.gz
ports-69623540650261ced8f01f2472f78dcf06b8770b.zip
- Fix calculation of available memory
PR: ports/157195 Submitted by: Sayetsky Anton <jason@linux.lg.ua> Approved by: Hung-Yi Chen <gaod@hychen.org> (maintainer)
Notes
Notes: svn path=/head/; revision=279528
Diffstat (limited to 'sysutils/htop')
-rw-r--r--sysutils/htop/Makefile1
-rw-r--r--sysutils/htop/files/patch-ProcessList.c87
-rw-r--r--sysutils/htop/files/patch-configure.ac14
3 files changed, 99 insertions, 3 deletions
diff --git a/sysutils/htop/Makefile b/sysutils/htop/Makefile
index ee0c909884ca..9ea7f5895203 100644
--- a/sysutils/htop/Makefile
+++ b/sysutils/htop/Makefile
@@ -7,6 +7,7 @@
PORTNAME= htop
PORTVERSION= 0.9
+PORTREVISION= 1
CATEGORIES= sysutils
MASTER_SITES= SF
diff --git a/sysutils/htop/files/patch-ProcessList.c b/sysutils/htop/files/patch-ProcessList.c
new file mode 100644
index 000000000000..29d7010ce6ae
--- /dev/null
+++ b/sysutils/htop/files/patch-ProcessList.c
@@ -0,0 +1,87 @@
+--- ./ProcessList.c.orig 2010-11-26 18:50:25.000000000 +0200
++++ ./ProcessList.c 2011-08-11 13:07:08.000000000 +0300
+@@ -32,6 +32,19 @@
+ #include "debug.h"
+ #include <assert.h>
+
++#ifndef PAGE_SIZE
++#define PAGE_SIZE sysconf(_SC_PAGESIZE)
++#endif
++
++#ifdef __FreeBSD__
++#define KB 1024
++#define SYSCTLBYNAME(name, var, len) sysctlbyname(name, &(var), &(len), NULL, 0)
++#include <kvm.h>
++#include <paths.h>
++#include <fcntl.h>
++#include <sys/sysctl.h>
++#endif
++
+ /*{
+
+ #ifndef PROCDIR
+@@ -665,15 +678,24 @@
+
+ void ProcessList_scan(ProcessList* this) {
+ unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime, virtalltime;
++ #ifndef __FreeBSD__
+ unsigned long long int swapFree = 0;
++ #endif
++ int cpus = this->cpuCount;
++ FILE* file = NULL;
+
+- FILE* file = fopen(PROCMEMINFOFILE, "r");
++ #ifdef __FreeBSD__
++ kvm_t *kd = NULL;
++ struct kvm_swap kvmswapinfo[1];
++ size_t len = 0;
++ #endif
++
++ #ifndef __FreeBSD__
++ file = fopen(PROCMEMINFOFILE, "r");
+ assert(file != NULL);
+- int cpus = this->cpuCount;
+ {
+ char buffer[128];
+ while (fgets(buffer, 128, file)) {
+-
+ switch (buffer[0]) {
+ case 'M':
+ if (String_startsWith(buffer, "MemTotal:"))
+@@ -700,10 +722,35 @@
+ }
+ }
+ }
++ fclose(file);
++ #endif
+
++ #ifdef __FreeBSD__
++ len = sizeof(this->totalMem);
++ SYSCTLBYNAME("vm.stats.vm.v_page_count", this->totalMem, len);
++ this->totalMem *= PAGE_SIZE / KB;
++ len = sizeof(this->cachedMem);
++ SYSCTLBYNAME("vm.stats.vm.v_cache_count", this->cachedMem, len);
++ this->cachedMem *= PAGE_SIZE / KB;
++ len = sizeof(this->buffersMem);
++ SYSCTLBYNAME("vfs.bufspace", this->buffersMem, len);
++ this->buffersMem /= KB;
++ len = sizeof(this->usedMem);
++ SYSCTLBYNAME("vm.stats.vm.v_active_count", this->usedMem, len);
++ this->usedMem = this->usedMem * PAGE_SIZE / KB + this->cachedMem + this->buffersMem;
++ this->freeMem = this->totalMem - this->usedMem;
++ kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL);
++ assert(kd != NULL);
++ kvm_getswapinfo(kd, kvmswapinfo, 1, 0);
++ this->totalSwap = kvmswapinfo[0].ksw_total * PAGE_SIZE / KB;
++ this->usedSwap = kvmswapinfo[0].ksw_used * PAGE_SIZE / KB;
++ kvm_close(kd);
++ #endif
++
++ #ifndef __FreeBSD__
+ this->usedMem = this->totalMem - this->freeMem;
+ this->usedSwap = this->totalSwap - swapFree;
+- fclose(file);
++ #endif
+
+ file = fopen(PROCSTATFILE, "r");
+ assert(file != NULL);
diff --git a/sysutils/htop/files/patch-configure.ac b/sysutils/htop/files/patch-configure.ac
index a752d5d06feb..bea88b28ce17 100644
--- a/sysutils/htop/files/patch-configure.ac
+++ b/sysutils/htop/files/patch-configure.ac
@@ -1,6 +1,14 @@
---- configure.ac.orig 2010-12-30 03:13:16.000000000 +0800
-+++ configure.ac 2010-12-30 03:13:23.000000000 +0800
-@@ -86,7 +86,7 @@
+--- ./configure.ac.orig 2010-11-23 17:56:32.000000000 +0200
++++ ./configure.ac 2011-08-11 12:50:44.000000000 +0300
+@@ -18,6 +18,7 @@
+
+ # Checks for libraries.
+ AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
++AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
+
+ # Checks for header files.
+ AC_HEADER_DIRENT
+@@ -86,7 +87,7 @@
AC_ARG_ENABLE(unicode, [AC_HELP_STRING([--enable-unicode], [enable Unicode support])], ,enable_unicode="no")
if test "x$enable_unicode" = xyes; then
AC_CHECK_LIB([ncursesw], [refresh], [], [missing_libraries="$missing_libraries libncursesw"])