FreeBSD Bugzilla – Attachment 115431 Details for
Bug 157195
[PATCH] sysutils/htop miscalculates available memory
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
patch-ProcessList.c
patch-ProcessList.c (text/x-csrc; charset=US-ASCII), 2.98 KB, created by
Sayetsky Anton
on 2011-07-24 09:43:21 UTC
(
hide
)
Description:
patch-ProcessList.c
Filename:
MIME Type:
Creator:
Sayetsky Anton
Created:
2011-07-24 09:43:21 UTC
Size:
2.98 KB
patch
obsolete
>--- ./ProcessList.c.orig 2009-03-11 15:03:42.000000000 +0200 >+++ ./ProcessList.c 2011-07-24 11:29:03.000000000 +0300 >@@ -31,6 +31,20 @@ > #include "debug.h" > #include <assert.h> > >+// This works only with glibc 2.1+. On earlier versions >+// the behavior is similar to have a hardcoded page size. >+#ifndef PAGE_SIZE >+#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) ) >+#endif >+ >+#ifdef __FreeBSD__ >+#include <sys/sysctl.h> >+#include <kvm.h> >+#include <paths.h> >+#include <fcntl.h> >+#define SYSCTLBYNAME(name, var, len) sysctlbyname(name, &(var), &(len), NULL, 0) >+#endif >+ > /*{ > #ifndef PROCDIR > #define PROCDIR "/proc" >@@ -313,7 +327,7 @@ > unsigned int pid = p->pid; > int index = Vector_indexOf(this->processes, p, Process_pidCompare); > assert(index != -1); >- Vector_remove(this->processes, index); >+ if (index >= 0) Vector_remove(this->processes, index); > assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid; > assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); > } >@@ -730,13 +744,20 @@ > > void ProcessList_scan(ProcessList* this) { > unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime; >- unsigned long long int swapFree; >+ >+ int processors = this->processorCount; > > FILE* status; >- char buffer[128]; >+ char buffer[256]; >+ >+ #ifdef __FreeBSD__ >+ size_t vlen = 0; >+ #endif >+ >+ #ifndef __FreeBSD__ > status = ProcessList_fopen(this, PROCMEMINFOFILE, "r"); > assert(status != NULL); >- int processors = this->processorCount; >+ > while (!feof(status)) { > fgets(buffer, 128, status); > >@@ -765,16 +786,39 @@ > break; > } > } >+ fclose(status); >+ #endif >+ >+ #ifdef __FreeBSD__ >+ vlen = sizeof(this->totalMem); >+ if(!SYSCTLBYNAME("vm.stats.vm.v_page_count", this->totalMem, vlen)) >+ this->totalMem *= PAGE_SIZE / 1024; >+ vlen = sizeof(this->freeMem); >+ if(!SYSCTLBYNAME("vm.stats.vm.v_free_count", this->freeMem, vlen)) >+ this->freeMem *= PAGE_SIZE / 1024; >+ vlen = sizeof(this->buffersMem); >+ if(!SYSCTLBYNAME("vfs.bufspace", this->buffersMem, vlen)) >+ this->buffersMem /= 1024; >+ vlen = sizeof(this->cachedMem); >+ if(!SYSCTLBYNAME("vm.stats.vm.v_cache_count", this->cachedMem, vlen)) >+ this->cachedMem *= PAGE_SIZE / 1024; >+ kvm_t *kd; >+ struct kvm_swap swapinfo[1]; >+ kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL); >+ if(kd) { >+ kvm_getswapinfo(kd, swapinfo, 1, 0); >+ this->totalSwap = swapinfo[0].ksw_total * PAGE_SIZE / 1024; >+ this->usedSwap = swapinfo[0].ksw_used * PAGE_SIZE / 1024; >+ kvm_close(kd); >+ } >+ #endif > > this->usedMem = this->totalMem - this->freeMem; >- this->usedSwap = this->totalSwap - swapFree; >- fclose(status); > > status = ProcessList_fopen(this, PROCSTATFILE, "r"); > > assert(status != NULL); > for (int i = 0; i <= processors; i++) { >- char buffer[256]; > int cpuid; > unsigned long long int ioWait, irq, softIrq, steal; > ioWait = irq = softIrq = steal = 0;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 157195
:
115430
| 115431 |
115432
|
115433
|
115434
|
115435