diff --git a/src/freebsd.c b/src/freebsd.c index 736b3948..8d13962d 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -724,9 +724,9 @@ int comparecpu(const void *a, const void *b) int comparemem(const void *a, const void *b) { - if (((const struct process *)a)->totalmem > ((const struct process *)b)->totalmem) { + if (((const struct process *)a)->rss > ((const struct process *)b)->rss) { return -1; - } else if (((const struct process *)a)->totalmem < ((const struct process *)b)->totalmem) { + } else if (((const struct process *)a)->rss < ((const struct process *)b)->rss) { return 1; } else { return 0; @@ -756,8 +756,6 @@ proc_find_top(struct process **cpu, struct process **mem) processes[j].pid = p[i].ki_pid; processes[j].name = strndup(p[i].ki_comm, text_buffer_size); processes[j].amount = 100.0 * p[i].ki_pctcpu / FSCALE; - processes[j].totalmem = (float) (p[i].ki_rssize / - (float) total_pages) * 100.0; processes[j].vsize = p[i].ki_size; processes[j].rss = (p[i].ki_rssize * getpagesize()); j++; @@ -771,7 +769,6 @@ proc_find_top(struct process **cpu, struct process **mem) tmp = malloc(sizeof(struct process)); tmp->pid = processes[i].pid; tmp->amount = processes[i].amount; - tmp->totalmem = processes[i].totalmem; tmp->name = strndup(processes[i].name, text_buffer_size); tmp->rss = processes[i].rss; tmp->vsize = processes[i].vsize; @@ -791,7 +788,6 @@ proc_find_top(struct process **cpu, struct process **mem) tmp = malloc(sizeof(struct process)); tmp->pid = processes[i].pid; tmp->amount = processes[i].amount; - tmp->totalmem = processes[i].totalmem; tmp->name = strndup(processes[i].name, text_buffer_size); tmp->rss = processes[i].rss; tmp->vsize = processes[i].vsize; @@ -807,8 +803,8 @@ proc_find_top(struct process **cpu, struct process **mem) #if defined(FREEBSD_DEBUG) printf("=====\nmem\n"); for (i = 0; i < 10; i++) { - printf("%d: %s(%d) %.2f %ld %ld\n", i, mem[i]->name, - mem[i]->pid, mem[i]->totalmem, mem[i]->vsize, mem[i]->rss); + printf("%d: %s(%d) %ld %ld\n", i, mem[i]->name, + mem[i]->pid, mem[i]->vsize, mem[i]->rss); } #endif diff --git a/src/openbsd.c b/src/openbsd.c index b6fba3d0..e2f6cc20 100644 --- a/src/openbsd.c +++ b/src/openbsd.c @@ -738,11 +738,11 @@ int comparecpu(const void *a, const void *b) int comparemem(const void *a, const void *b) { - if (((struct process *) a)->totalmem > ((struct process *) b)->totalmem) { + if (((struct process *) a)->rss > ((struct process *) b)->rss) { return -1; } - if (((struct process *) a)->totalmem < ((struct process *) b)->totalmem) { + if (((struct process *) a)->rss < ((struct process *) b)->rss) { return 1; } @@ -783,8 +783,6 @@ inline void proc_find_top(struct process **cpu, struct process **mem) processes[j].pid = p[i].p_pid; processes[j].name = strndup(p[i].p_comm, text_buffer_size); processes[j].amount = 100.0 * p[i].p_pctcpu / FSCALE; - processes[j].totalmem = (float) (p[i].p_vm_rssize / - (float) total_pages) * 100.0; j++; } } @@ -796,7 +794,6 @@ inline void proc_find_top(struct process **cpu, struct process **mem) tmp = malloc(sizeof(struct process)); tmp->pid = processes[i].pid; tmp->amount = processes[i].amount; - tmp->totalmem = processes[i].totalmem; tmp->name = strndup(processes[i].name, text_buffer_size); ttmp = mem[i]; @@ -814,7 +811,6 @@ inline void proc_find_top(struct process **cpu, struct process **mem) tmp = malloc(sizeof(struct process)); tmp->pid = processes[i].pid; tmp->amount = processes[i].amount; - tmp->totalmem = processes[i].totalmem; tmp->name = strndup(processes[i].name, text_buffer_size); ttmp = cpu[i]; diff --git a/src/top.c b/src/top.c index 76236ead..ff5fa000 100644 --- a/src/top.c +++ b/src/top.c @@ -199,7 +199,6 @@ static struct process *new_process(int p) * Anyone hoping to port wmtop should look here first. */ static int process_parse_stat(struct process *process) { - struct information *cur = &info; char line[BUFFER_LEN] = { 0 }, filename[BUFFER_LEN], procname[BUFFER_LEN]; int ps; unsigned long user_time = 0; @@ -280,12 +279,7 @@ static int process_parse_stat(struct process *process) process->name = strndup(procname, text_buffer_size); process->rss *= getpagesize(); - if (!cur->memmax) { - update_total_processes(); - } - process->total_cpu_time = process->user_time + process->kernel_time; - process->totalmem = (float) (((float) process->rss / cur->memmax) / 10); if (process->previous_user_time == ULONG_MAX) { process->previous_user_time = process->user_time; } @@ -625,9 +619,9 @@ static int compare_cpu(struct process *a, struct process *b) /* mem comparison function for insert_sp_element */ static int compare_mem(struct process *a, struct process *b) { - if (a->totalmem < b->totalmem) { + if (a->rss < b->rss) { return 1; - } else if (a->totalmem > b->totalmem) { + } else if (a->rss > b->rss) { return -1; } else { return 0; @@ -978,8 +972,10 @@ void print_top(struct text_object *obj, char *p, int top_name_width) needed[td->num]->pid); break; case TOP_MEM: + /* Calculate a percentage of residential mem from total mem available. + * Since rss is bytes and memmax kilobytes, dividing by 10 suffices here. */ snprintf(p, 7, "%6.2f", - needed[td->num]->totalmem); + (float) ((float)needed[td->num]->rss / cur->memmax) / 10); break; case TOP_TIME: timeval = format_time( diff --git a/src/top.h b/src/top.h index e5773d1f..ae05f0a2 100644 --- a/src/top.h +++ b/src/top.h @@ -123,7 +123,6 @@ struct process { unsigned int time_stamp; unsigned int counted; unsigned int changed; - float totalmem; }; struct sorted_process {