Date: Sun, 07 Jun 1998 05:08:03 +0900 From: SANETO Takanori <sanewo@ba2.so-net.ne.jp> To: Nathan Dorfman <nathan@rtfm.net> Cc: current@FreeBSD.ORG Subject: Re: top -osize Message-ID: <199806062008.FAA28080@sanewo.ba2.so-net.ne.jp> In-Reply-To: nathan@rtfm.net's message of Sun, 31 May 1998 11:46:27 -0400. <19980531114627.A580@rtfm.net>
next in thread | previous in thread | raw e-mail | index | archive | help
In article <19980531114627.A580@rtfm.net>
Nathan Dorfman <nathan@rtfm.net> said:
>This won't patch into top (in -current). Hunk #8 fails at 762, and
>the code fails to compile:
>
>cc -O -pipe -DHAVE_GETOPT -I/usr/src/usr.bin/top -I/usr/src/usr.bin/top/../../contrib/top -c /usr/src/usr.bin/top/machine.c
Strange. It seems that the patch for Makefile (which adds -DORDER to
CFLAGS) failed as well (bad?) as hunk #8.
>/usr/src/usr.bin/top/machine.c: In function `machine_init':
>/usr/src/usr.bin/top/machine.c:331: structure has no member named `order_names'
Struct member ``order_names'' will be defined (in
contrib/top/machine.h) when -DORDER is specified.
Anyway, try following patch, which I created against the -current as
of 16:00 GMT, June 6.
Index: usr.bin/top/Makefile
===================================================================
RCS file: /sd0/FreeBSD/cvs/src/usr.bin/top/Makefile,v
retrieving revision 1.4
diff -c -r1.4 Makefile
*** Makefile 1997/07/21 16:06:00 1.4
--- Makefile 1998/06/06 19:54:01
***************
*** 3,9 ****
TOPDIR= ${.CURDIR}/../../contrib/top
.PATH: ${TOPDIR}
! CFLAGS+= -DHAVE_GETOPT -I${.CURDIR} -I${TOPDIR}
#
# The table size should be a prime number approximately twice as
--- 3,9 ----
TOPDIR= ${.CURDIR}/../../contrib/top
.PATH: ${TOPDIR}
! CFLAGS+= -DHAVE_GETOPT -DORDER -I${.CURDIR} -I${TOPDIR}
#
# The table size should be a prime number approximately twice as
Index: usr.bin/top/machine.c
===================================================================
RCS file: /sd0/FreeBSD/cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.10
diff -c -r1.10 machine.c
*** machine.c 1998/05/28 09:29:48 1.10
--- machine.c 1998/05/28 17:27:52
***************
*** 13,18 ****
--- 13,20 ----
*
* LIBS: -lkvm
*
+ * CFLAGS: -DHAVE_GETOPT -DORDER
+ *
* AUTHOR: Christos Zoulas <christos@ee.cornell.edu>
* Steven Wallace <swallace@freebsd.org>
* Wolfram Schneider <wosch@FreeBSD.org>
***************
*** 167,173 ****
static long lastpid;
static unsigned long cnt_offset;
static unsigned long bufspace_offset;
- static long cnt;
/* these are for calculating cpu state percentages */
--- 169,174 ----
***************
*** 206,211 ****
--- 207,228 ----
NULL
};
+ /* these are names given to allowed sorting orders -- first is default */
+ char *ordernames[] =
+ {"cpu", "size", "res", "time", NULL};
+
+ /* forward definitions for comparison functions */
+ int compare_cpu();
+ int compare_size();
+ int compare_res();
+ int compare_time();
+
+ int (*proc_compares[])() = {
+ compare_cpu,
+ compare_size,
+ compare_res,
+ compare_time,
+ NULL };
/* these are for keeping track of the proc array */
***************
*** 311,316 ****
--- 328,334 ----
statics->cpustate_names = cpustatenames;
statics->memory_names = memorynames;
statics->swap_names = swapnames;
+ statics->order_names = ordernames;
/* all done! */
return(0);
***************
*** 321,333 ****
register char *uname_field;
{
- register char *ptr;
static char Header[128];
snprintf(Header, sizeof(Header), smpmode ? smp_header : up_header,
namelength, namelength, uname_field);
! cmdlength = 80 - strlen(Header) + 6;
return Header;
}
--- 339,350 ----
register char *uname_field;
{
static char Header[128];
snprintf(Header, sizeof(Header), smpmode ? smp_header : up_header,
namelength, namelength, uname_field);
! cmdlength = 128 - strlen(Header) + 6; /* 128 should be the line of screen */
return Header;
}
***************
*** 691,710 ****
}
return(1);
}
!
! /* comparison routine for qsort */
/*
! * proc_compare - comparison function for "qsort"
! * Compares the resource consumption of two processes using five
! * distinct keys. The keys (in descending order of importance) are:
! * percent cpu, cpu ticks, state, resident set size, total virtual
! * memory usage. The process states are ordered as follows (from least
! * to most important): WAIT, zombie, sleep, stop, start, run. The
! * array declaration below maps a process state index into a number
! * that reflects this ordering.
*/
static unsigned char sorted_state[] =
{
0, /* not used */
--- 708,744 ----
}
return(1);
}
!
! /* comparison routines for qsort */
/*
! * There are currently four possible comparison routines. main selects
! * one of these by indexing in to the array proc_compares.
! *
! * Possible keys are defined as macros below. Currently these keys are
! * defined: percent cpu, cpu ticks, process state, resident set size,
! * total virtual memory usage. The process states are ordered as follows
! * (from least to most important): WAIT, zombie, sleep, stop, start, run.
! * The array declaration below maps a process state index into a number
! * that reflects this ordering.
*/
+ /* First, the possible comparison keys. These are defined in such a way
+ that they can be merely listed in the source code to define the actual
+ desired ordering.
+ */
+
+ #define ORDERKEY_PCTCPU if (dresult = pctdouble(PP(p2, p_pctcpu)) - pctdouble(PP(p1, p_pctcpu)),\
+ (result = dresult > 0.0 ? 1 : dresult < 0.0 ? -1 : 0) == 0)
+ #define ORDERKEY_CPTICKS if ((result = PP(p2, p_runtime) - PP(p1, p_runtime)) == 0)
+ #define ORDERKEY_STATE if ((result = (long) (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)
+
+ /* Now the array that maps process state to a weight */
+
static unsigned char sorted_state[] =
{
0, /* not used */
***************
*** 716,723 ****
4 /* stop */
};
int
! proc_compare(pp1, pp2)
struct proc **pp1;
struct proc **pp2;
--- 750,759 ----
4 /* stop */
};
+ /* compare_cpu - the comparison function for sorting by cpu percentage */
+
int
! compare_cpu(pp1, pp2)
struct proc **pp1;
struct proc **pp2;
***************
*** 726,764 ****
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;
! /* 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;
! }
return(result);
}
--- 762,867 ----
register struct kinfo_proc *p1;
register struct kinfo_proc *p2;
register int result;
! double dresult;
/* remove one level of indirection */
p1 = *(struct kinfo_proc **) pp1;
p2 = *(struct kinfo_proc **) pp2;
! ORDERKEY_PCTCPU
! ORDERKEY_CPTICKS
! ORDERKEY_STATE
! ORDERKEY_PRIO
! ORDERKEY_RSSIZE
! ORDERKEY_MEM
! ;
!
! return(result);
! }
!
! /* 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;
! double dresult;
!
! /* 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;
! double dresult;
!
! /* 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;
! double dresult;
!
! /* remove one level of indirection */
! p1 = *(struct kinfo_proc **) pp1;
! p2 = *(struct kinfo_proc **) pp2;
!
! ORDERKEY_CPTICKS
! ORDERKEY_PCTCPU
! ORDERKEY_STATE
! ORDERKEY_PRIO
! ORDERKEY_MEM
! ORDERKEY_RSSIZE
! ;
return(result);
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806062008.FAA28080>
