From 17e41d30814331d00530eaf8a88dd8911bdd68a9 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Tue, 11 Sep 2012 02:17:25 +0200 Subject: [PATCH] top: add memory order, order cycling key --- usr.bin/top/top.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index f9be0a12b..e5c409368 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -41,6 +41,11 @@ #define TIMECYCLEKEY 't' +#define ORDER_CPU 0 +#define ORDER_MEMORY 1 +#define ORDER_HIGHEST ORDER_MEMORY +int order = ORDER_CPU; + u32_t system_hz; /* name of cpu cycle types, in the order they appear in /psinfo. */ @@ -281,12 +286,18 @@ struct tp { u64_t ticks; }; -int cmp_ticks(const void *v1, const void *v2) +int cmp_procs(const void *v1, const void *v2) { int c; struct tp *p1 = (struct tp *) v1, *p2 = (struct tp *) v2; int p1blocked, p2blocked; + if(order == ORDER_MEMORY) { + if(p1->p->p_memory < p2->p->p_memory) return 1; + if(p1->p->p_memory > p2->p->p_memory) return -1; + return 0; + } + p1blocked = !!(p1->p->p_flags & BLOCKED); p2blocked = !!(p2->p->p_flags & BLOCKED); @@ -464,7 +475,7 @@ void print_procs(int maxlines, if (!cmp64u(total_ticks, 0)) return; - qsort(tick_procs, nprocs, sizeof(tick_procs[0]), cmp_ticks); + qsort(tick_procs, nprocs, sizeof(tick_procs[0]), cmp_procs); tcyc = div64u(total_ticks, SCALE); @@ -692,6 +703,11 @@ int main(int argc, char *argv[]) putchar('\r'); return 0; break; + case 'o': + order++; + if(order > ORDER_HIGHEST) + order = 0; + break; case TIMECYCLEKEY: cputimemode++; if(cputimemode >= (1L << CPUTIMENAMES)) -- 2.44.0