Subject: Re: changes to top to print wchan for sleeping procs
To: None <tech-userlevel@netbsd.org>
From: enami tsugutomo <enami@sm.sony.co.jp>
List: tech-userlevel
Date: 01/18/2001 17:43:40
Jason R Thorpe <thorpej@zembu.com> writes:
> I think Hubert wants to get rid of WCPU -- but I totally support keeping
> the WCPU column, and simply doing the CAPS/nocaps thing for STATE versus
> wchan.
Ideally, it is best if top (or systat) display can be configurable
like ps...
Here is CAPS version, btw.
enami.
Index: machine/m_netbsd15.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/machine/m_netbsd15.c,v
retrieving revision 1.12
diff -u -r1.12 m_netbsd15.c
--- machine/m_netbsd15.c 2000/12/30 14:26:50 1.12
+++ machine/m_netbsd15.c 2001/01/18 05:42:37
@@ -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"
/*
@@ -98,7 +98,7 @@
*/
const char *state_abbrev[] = {
- "", "start", "run", "sleep", "stop", "zomb", "dead", "cpu"
+ "", "START", "RUN", "SLEEP", "STOP", "ZOMB", "DEAD", "CPU"
};
static kvm_t *kd;
@@ -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;