Commit d753996b authored by Bernard Spil's avatar Bernard Spil
Browse files

Fix memory percentage display on FreeBSD

parent b1027831
...@@ -84,6 +84,8 @@ static int MIB_kern_cp_time[2]; ...@@ -84,6 +84,8 @@ static int MIB_kern_cp_time[2];
static int MIB_kern_cp_times[2]; static int MIB_kern_cp_times[2];
static int kernelFScale; static int kernelFScale;
// XXX hack
static unsigned long long int Global_totalMem;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
FreeBSDProcessList* fpl = xCalloc(1, sizeof(FreeBSDProcessList)); FreeBSDProcessList* fpl = xCalloc(1, sizeof(FreeBSDProcessList));
...@@ -301,6 +303,8 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { ...@@ -301,6 +303,8 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) {
//pl->totalMem *= pageSizeKb; //pl->totalMem *= pageSizeKb;
sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0);
pl->totalMem /= 1024; pl->totalMem /= 1024;
// XXX hack
Global_totalMem = pl->totalMem;
sysctl(MIB_vm_stats_vm_v_active_count, 4, &(fpl->memActive), &len, NULL, 0); sysctl(MIB_vm_stats_vm_v_active_count, 4, &(fpl->memActive), &len, NULL, 0);
fpl->memActive *= pageSizeKb; fpl->memActive *= pageSizeKb;
...@@ -479,6 +483,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { ...@@ -479,6 +483,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
// from FreeBSD source /src/usr.bin/top/machine.c // from FreeBSD source /src/usr.bin/top/machine.c
proc->m_size = kproc->ki_size / 1024 / pageSizeKb; proc->m_size = kproc->ki_size / 1024 / pageSizeKb;
proc->m_resident = kproc->ki_rssize; proc->m_resident = kproc->ki_rssize;
proc->percent_mem = (proc->m_resident * PAGE_SIZE_KB) / (double)(Global_totalMem) * 100.0;
proc->nlwp = kproc->ki_numthreads; proc->nlwp = kproc->ki_numthreads;
proc->time = (kproc->ki_runtime + 5000) / 10000; proc->time = (kproc->ki_runtime + 5000) / 10000;
...@@ -487,9 +492,6 @@ void ProcessList_goThroughEntries(ProcessList* this) { ...@@ -487,9 +492,6 @@ void ProcessList_goThroughEntries(ProcessList* this) {
// system idle process should own all CPU time left regardless of CPU count // system idle process should own all CPU time left regardless of CPU count
if ( strcmp("idle", kproc->ki_comm) == 0 ) { if ( strcmp("idle", kproc->ki_comm) == 0 ) {
isIdleProcess = true; isIdleProcess = true;
} else {
if (cpus > 1)
proc->percent_cpu = proc->percent_cpu / (double) cpus;
} }
} }
if (isIdleProcess == false && proc->percent_cpu >= 99.8) { if (isIdleProcess == false && proc->percent_cpu >= 99.8) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment