diff options
author | wosch <wosch@FreeBSD.org> | 1998-08-12 09:58:15 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1998-08-12 09:58:15 +0000 |
commit | 5a643960aa4012b193090151b24495f169347192 (patch) | |
tree | 02da4dc42adf7463ea85038e995ac02909ace114 /usr.bin | |
parent | c07d751872ed072f5302455068e9f472b9ff335f (diff) | |
download | FreeBSD-src-5a643960aa4012b193090151b24495f169347192.zip FreeBSD-src-5a643960aa4012b193090151b24495f169347192.tar.gz |
Merge from stable: support for the o, order, command
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/top/Makefile | 2 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 206 |
2 files changed, 178 insertions, 30 deletions
diff --git a/usr.bin/top/Makefile b/usr.bin/top/Makefile index 01d4926..19a60f1 100644 --- a/usr.bin/top/Makefile +++ b/usr.bin/top/Makefile @@ -3,7 +3,7 @@ PROG= top TOPDIR= ${.CURDIR}/../../contrib/top .PATH: ${TOPDIR} -CFLAGS+= -DHAVE_GETOPT -I${.CURDIR} -I${TOPDIR} +CFLAGS+= -DHAVE_GETOPT -I${.CURDIR} -I${TOPDIR} -DORDER # # The table size should be a prime number approximately twice as diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 8667149..e5edd40 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -6,6 +6,8 @@ * DESCRIPTION: * Originally written for BSD4.4 system by Christos Zoulas. * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider + * Order support hacked in from top-3.5beta6/machine/m_aix41.c + * by Monte Mitzelfelt (for latest top see http://www.groupsys.com/topinfo/) * * This is the machine-dependent module for FreeBSD 2.2 * Works for: @@ -17,7 +19,7 @@ * Steven Wallace <swallace@freebsd.org> * Wolfram Schneider <wosch@FreeBSD.org> * - * $Id: machine.c,v 1.12 1998/07/27 12:21:58 wosch Exp $ + * $Id: machine.c,v 1.13 1998/08/04 14:10:30 des Exp $ */ @@ -226,6 +228,13 @@ static int pageshift; /* log base 2 of the pagesize */ /* useful externals */ long percentages(); +#ifdef ORDER +/* sorting orders. first is default */ +char *ordernames[] = { + "cpu", "size", "res", "time", "pri", NULL +}; +#endif + int machine_init(statics) @@ -311,6 +320,9 @@ struct statics *statics; statics->cpustate_names = cpustatenames; statics->memory_names = memorynames; statics->swap_names = swapnames; +#ifdef ORDER + statics->order_names = ordernames; +#endif /* all done! */ return(0); @@ -696,7 +708,7 @@ char *refstr; return(1); } -/* comparison routine for qsort */ +/* comparison routines for qsort */ /* * proc_compare - comparison function for "qsort" @@ -720,8 +732,35 @@ static unsigned char sorted_state[] = 4 /* stop */ }; + +#define ORDERKEY_PCTCPU \ + if (lresult = PP(p2, p_pctcpu) - PP(p1, p_pctcpu), \ + (result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0) + +#define ORDERKEY_CPTICKS \ + if ((result = PP(p2, p_runtime) - PP(p1, p_runtime)) == 0) + +#define ORDERKEY_STATE \ + if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - \ + sorted_state[(unsigned char) PP(p1, p_stat)]) == 0) + +#define ORDERKEY_PRIO \ + if ((result = PP(p2, p_priority) - PP(p1, p_priority)) == 0) + +#define ORDERKEY_RSSIZE \ + if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0) + +#define ORDERKEY_MEM \ + if ( (result = PROCSIZE(p2) - PROCSIZE(p1)) == 0 ) + +/* compare_cpu - the comparison function for sorting by cpu percentage */ + int +#ifdef ORDER +compare_cpu(pp1, pp2) +#else proc_compare(pp1, pp2) +#endif struct proc **pp1; struct proc **pp2; @@ -736,37 +775,146 @@ struct proc **pp2; p1 = *(struct kinfo_proc **) pp1; p2 = *(struct kinfo_proc **) pp2; - /* compare percent cpu (pctcpu) */ - if ((lresult = PP(p2, p_pctcpu) - PP(p1, p_pctcpu)) == 0) - { - /* use lifetime CPU usage to break the tie */ - if ((result = PP(p2, p_runtime) - PP(p1, p_runtime)) == 0) - { - /* use process state to break the tie */ - if ((result = sorted_state[(unsigned char) PP(p2, p_stat)] - - sorted_state[(unsigned char) PP(p1, p_stat)]) == 0) - { - /* use priority to break the tie */ - if ((result = PP(p2, p_priority) - PP(p1, p_priority)) == 0) - { - /* use resident set size (rssize) to break the tie */ - if ((result = VP(p2, vm_rssize) - VP(p1, vm_rssize)) == 0) - { - /* use total memory to break the tie */ - result = PROCSIZE(p2) - PROCSIZE(p1); - } - } - } - } - } - else - { - result = lresult < 0 ? -1 : 1; - } + ORDERKEY_PCTCPU + ORDERKEY_CPTICKS + ORDERKEY_STATE + ORDERKEY_PRIO + ORDERKEY_RSSIZE + ORDERKEY_MEM + ; + + return(result); +} + +#ifdef ORDER +/* compare routines */ +int compare_size(), compare_res(), compare_time(), compare_prio(); + +int (*proc_compares[])() = { + compare_cpu, + compare_size, + compare_res, + compare_time, + compare_prio, + NULL +}; + +/* compare_size - the comparison function for sorting by total memory usage */ + +int +compare_size(pp1, pp2) + +struct proc **pp1; +struct proc **pp2; + +{ + register struct kinfo_proc *p1; + register struct kinfo_proc *p2; + register int result; + register pctcpu lresult; + + /* remove one level of indirection */ + p1 = *(struct kinfo_proc **) pp1; + p2 = *(struct kinfo_proc **) pp2; + + ORDERKEY_MEM + ORDERKEY_RSSIZE + ORDERKEY_PCTCPU + ORDERKEY_CPTICKS + ORDERKEY_STATE + ORDERKEY_PRIO + ; return(result); } +/* compare_res - the comparison function for sorting by resident set size */ + +int +compare_res(pp1, pp2) + +struct proc **pp1; +struct proc **pp2; + +{ + register struct kinfo_proc *p1; + register struct kinfo_proc *p2; + register int result; + register pctcpu lresult; + + /* remove one level of indirection */ + p1 = *(struct kinfo_proc **) pp1; + p2 = *(struct kinfo_proc **) pp2; + + ORDERKEY_RSSIZE + ORDERKEY_MEM + ORDERKEY_PCTCPU + ORDERKEY_CPTICKS + ORDERKEY_STATE + ORDERKEY_PRIO + ; + + return(result); +} + +/* compare_time - the comparison function for sorting by total cpu time */ + +int +compare_time(pp1, pp2) + +struct proc **pp1; +struct proc **pp2; + +{ + register struct kinfo_proc *p1; + register struct kinfo_proc *p2; + register int result; + register pctcpu lresult; + + /* remove one level of indirection */ + p1 = *(struct kinfo_proc **) pp1; + p2 = *(struct kinfo_proc **) pp2; + + ORDERKEY_CPTICKS + ORDERKEY_PCTCPU + ORDERKEY_STATE + ORDERKEY_PRIO + ORDERKEY_RSSIZE + ORDERKEY_MEM + ; + + return(result); + } + +/* compare_prio - the comparison function for sorting by cpu percentage */ + +int +compare_prio(pp1, pp2) + +struct proc **pp1; +struct proc **pp2; + +{ + register struct kinfo_proc *p1; + register struct kinfo_proc *p2; + register int result; + register pctcpu lresult; + + /* remove one level of indirection */ + p1 = *(struct kinfo_proc **) pp1; + p2 = *(struct kinfo_proc **) pp2; + + ORDERKEY_PRIO + ORDERKEY_CPTICKS + ORDERKEY_PCTCPU + ORDERKEY_STATE + ORDERKEY_RSSIZE + ORDERKEY_MEM + ; + + return(result); +} +#endif /* * proc_owner(pid) - returns the uid that owns process "pid", or -1 if |