Subject: changes to top to print wchan for sleeping procs
To: None <tech-userlevel@netbsd.org>
From: enami tsugutomo <enami@but-b.or.jp>
List: tech-userlevel
Date: 01/17/2001 23:17:38
Hi all.
Here is my local mod to top(1) to print wchan for sleeping process.
Some of us also likes this change. So, I'd like to commit this. Is
there any objection or thoughts? Especially, is it better to have a
flag to enable this? Also, hubert noted that openbsd drops wcpu and
have separate field for wchan (but personally, I prefer current
format).
enami.
Diffs to top:
Index: machine/m_netbsd15.c
===================================================================
RCS file: /i/netbsd/cvsroot/basesrc/usr.bin/top/machine/m_netbsd15.c,v
retrieving revision 1.12
diff -u -r1.12 m_netbsd15.c
--- m_netbsd15.c 2000/12/30 14:26:50 1.12
+++ m_netbsd15.c 2001/01/17 13:20:38
@@ -1,4 +1,4 @@
-/* $NetBSD: m_netbsd15.c,v 1.11 2000/11/29 11:18:33 simonb Exp $ */
+/* $NetBSD: m_netbsd15.c,v 1.12 2000/12/30 14:26:50 sommerfeld Exp $ */
/*
* top - a top users display for Unix
@@ -85,12 +85,12 @@
*/
static char header[] =
- " PID X PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND";
+ " PID X PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND";
/* 0123456 -- field to fill in starts at header+6 */
#define UNAME_START 6
#define Proc_format \
- "%5d %-8.8s %3d %4d%7s %5s %-7s%7s %5.2f%% %5.2f%% %.12s"
+ "%5d %-8.8s %3d %4d%7s %5s %-8.8s%7s %5.2f%% %5.2f%% %.12s"
/*
@@ -451,6 +451,7 @@
#ifdef KI_NOCPU
char state[10];
#endif
+ char wmesg[KI_WMESGLEN + 1];
static char fmt[128]; /* static area where result is built */
/* find and remember the next proc structure */
@@ -484,7 +485,11 @@
/* calculate the base for cpu percentages */
pct = pctdouble(pp->p_pctcpu);
- statep = state_abbrev[(unsigned)pp->p_stat];
+ if (pp->p_stat == SSLEEP) {
+ strlcpy(wmesg, pp->p_wmesg, sizeof(wmesg));
+ statep = wmesg;
+ } else
+ statep = state_abbrev[(unsigned)pp->p_stat];
#ifdef KI_NOCPU
/* Post-1.5 change: add cpu number if appropriate */
@@ -493,7 +498,7 @@
case SONPROC:
case SRUN:
case SSLEEP:
- snprintf(state, sizeof(state), "%s/%lld",
+ snprintf(state, sizeof(state), "%.6s/%lld",
statep, (long long)pp->p_cpuid);
statep = state;
break;
------------------------------------------------------------
Sample output on uni-processr machine:
load averages: 0.19, 0.14, 0.09 22:45:32
106 processes: 100 sleeping, 4 stopped, 1 zombie, 1 on processor
Memory: 62M Act, 31M Inact, 3860K Wired, 816K Free, 127M Swap, 79M Swap free
PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND
21958 enami 10 0 748K 1232K wait 0:00 0.67% 0.24% bash
4 root 18 0 0K 24M syncer 16:19 0.15% 0.15% ioflush
21957 root 2 0 268K 1380K select 0:00 0.22% 0.10% sshd
284 enami 2 0 8200K 9520K select 56:17 0.00% 0.00% XFree86
11117 enami 36 4 20M 4K stop 22:14 0.00% 0.00% <emacs>
23502 enami 2 0 712K 4K select 7:28 0.00% 0.00% <slogin>
2863 enami 28 0 1820K 4K stop 3:44 0.00% 0.00% <w3m>
287 enami 2 0 396K 4K select 1:23 0.00% 0.00% <kterm>
166 root 2 0 48K 348K nfsd 1:02 0.00% 0.00% nfsd
------------------------------------------------------------
Sample output on smp machine:
load averages: 1.70, 0.73, 0.37 22:44:17
42 processes: 41 sleeping, 1 on processor
Memory: 132M Act, 3768K Wired, 791M Free
PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND
258 root -5 0 316K 320K biowai/0 0:04 4.97% 4.93% cat
8 root -18 0 0K 39M aiodon/0 0:00 0.20% 0.20% aiodoned
7 root 18 0 0K 39M syncer/0 0:01 0.00% 0.00% ioflush
208 root 2 0 444K 944K select/0 0:01 0.00% 0.00% sshd1
259 root 28 0 140K 772K cpu/1 0:00 0.00% 0.00% top
181 root 18 -12 644K 3480K pause/0 0:00 0.00% 0.00% ntpd
243 root 18 0 440K 396K pause/1 0:00 0.00% 0.00% csh
3 root 10 0 0K 39M usbevt/0 0:00 0.00% 0.00% usb1
4 root 10 0 0K 39M viaenv/0 0:00 0.00% 0.00% viaenv0
2 root 10 0 0K 39M usbevt/0 0:00 0.00% 0.00% usb0
210 enami 10 0 544K 1136K wait/0 0:00 0.00% 0.00% bash