top can show loose tasks now

This commit is contained in:
albert 2005-06-21 19:20:39 +00:00
parent 864a5356a1
commit 38d36b4960
3 changed files with 84 additions and 19 deletions

1
NEWS
View File

@ -1,5 +1,6 @@
procps-3.2.5 --> procps-3.2.6 procps-3.2.5 --> procps-3.2.6
top can do per-task display -- thanks John Blackwood rh114012
more MIPS crud -- thanks Jim Gifford and Ryan Oliver more MIPS crud -- thanks Jim Gifford and Ryan Oliver
begin prep for setuid begin prep for setuid

71
top.c
View File

@ -1081,6 +1081,7 @@ static proc_t **procs_refresh (proc_t **table, int flags)
proc_t *ptsk = (proc_t *)-1; // first time, Force: (ii) proc_t *ptsk = (proc_t *)-1; // first time, Force: (ii)
unsigned curmax = 0; // every time (jeeze) unsigned curmax = 0; // every time (jeeze)
PROCTAB* PT; PROCTAB* PT;
static int show_threads_was_enabled = 0; // optimization
prochlp(NULL); // prep for a new frame prochlp(NULL); // prep for a new frame
if (Monpidsidx) if (Monpidsidx)
@ -1089,8 +1090,17 @@ static proc_t **procs_refresh (proc_t **table, int flags)
PT = openproc(flags); PT = openproc(flags);
// i) Allocated Chunks: *Existing* table; refresh + reuse // i) Allocated Chunks: *Existing* table; refresh + reuse
if (!(CHKw(Curwin, Show_THREADS))) {
while (curmax < savmax) { while (curmax < savmax) {
if (table[curmax]->cmdline) { if (table[curmax]->cmdline) {
unsigned idx;
// Skip if Show_THREADS was never enabled
if (show_threads_was_enabled) {
for (idx = curmax + 1; idx < savmax; idx++) {
if (table[idx]->cmdline == table[curmax]->cmdline)
table[idx]->cmdline = NULL;
}
}
free(*table[curmax]->cmdline); free(*table[curmax]->cmdline);
table[curmax]->cmdline = NULL; table[curmax]->cmdline = NULL;
} }
@ -1098,8 +1108,34 @@ static proc_t **procs_refresh (proc_t **table, int flags)
prochlp(ptsk); // tally & complete this proc_t prochlp(ptsk); // tally & complete this proc_t
++curmax; ++curmax;
} }
}
else { // show each thread in a process separately
while (curmax < savmax) {
proc_t *ttsk;
if (unlikely(!(ptsk = readproc(PT, NULL)))) break;
show_threads_was_enabled = 1;
while (curmax < savmax) {
unsigned idx;
if (table[curmax]->cmdline) {
// threads share the same cmdline storage. 'table' is
// qsort()ed, so must look through the rest of the table.
for (idx = curmax + 1; idx < savmax; idx++) {
if (table[idx]->cmdline == table[curmax]->cmdline)
table[idx]->cmdline = NULL;
}
free(*table[curmax]->cmdline); // only free once
table[curmax]->cmdline = NULL;
}
if (!(ttsk = readtask(PT, ptsk, table[curmax]))) break;
prochlp(ttsk);
++curmax;
}
free(ptsk); // readproc() proc_t not used
}
}
// ii) Unallocated Chunks: *New* or *Existing* table; extend + fill // ii) Unallocated Chunks: *New* or *Existing* table; extend + fill
if (!(CHKw(Curwin, Show_THREADS))) {
while (ptsk) { while (ptsk) {
// realloc as we go, keeping 'table' ahead of 'currmax++' // realloc as we go, keeping 'table' ahead of 'currmax++'
table = alloc_r(table, (curmax + 1) * PTRsz); table = alloc_r(table, (curmax + 1) * PTRsz);
@ -1109,6 +1145,22 @@ static proc_t **procs_refresh (proc_t **table, int flags)
table[curmax++] = ptsk; table[curmax++] = ptsk;
} }
} }
}
else { // show each thread in a process separately
while (ptsk) {
proc_t *ttsk;
if (likely(ptsk = readproc(PT, NULL))) {
show_threads_was_enabled = 1;
while (1) {
table = alloc_r(table, (curmax + 1) * PTRsz);
if (!(ttsk = readtask(PT, ptsk, NULL))) break;
prochlp(ttsk);
table[curmax++] = ttsk;
}
free(ptsk); // readproc() proc_t not used
}
}
}
closeproc(PT); closeproc(PT);
// iii) Chunkless: make 'eot' entry, after ensuring proc_t exists // iii) Chunkless: make 'eot' entry, after ensuring proc_t exists
@ -1427,8 +1479,8 @@ static int rc_read_old (const char *const buf, RCF_t *rc) {
case 'i': case 'i':
rc->win[0].winflags &= ~Show_IDLEPS; rc->win[0].winflags &= ~Show_IDLEPS;
break; break;
case 'H': // 'H' = show threads (yea, sure) case 'H':
//rc->win[0].winflags |= ; rc->win[0].winflags |= Show_THREADS;
break; break;
case 'm': case 'm':
rc->win[0].winflags &= ~View_MEMORY; rc->win[0].winflags &= ~View_MEMORY;
@ -1742,7 +1794,7 @@ static void parse_args (char **args)
. bunched args are actually handled properly and none are ignored . bunched args are actually handled properly and none are ignored
. we tolerate NO whitespace and NO switches -- maybe too tolerant? */ . we tolerate NO whitespace and NO switches -- maybe too tolerant? */
static const char usage[] = static const char usage[] =
" -hv | -bcisS -d delay -n iterations [-u user | -U user] -p pid [,pid ...]"; " -hv | -bcisSH -d delay -n iterations [-u user | -U user] -p pid [,pid ...]";
float tmp_delay = MAXFLOAT; float tmp_delay = MAXFLOAT;
char *p; char *p;
@ -1768,7 +1820,10 @@ static void parse_args (char **args)
if (sscanf(cp, "%f", &tmp_delay) != 1) if (sscanf(cp, "%f", &tmp_delay) != 1)
std_err(fmtmk("bad delay '%s'", cp)); std_err(fmtmk("bad delay '%s'", cp));
break; break;
case 'h': case 'H': case 'H':
TOGw(Curwin, Show_THREADS);
break;
case 'h':
case 'v': case 'V': case 'v': case 'V':
std_out(fmtmk("%s\nusage:\t%s%s", procps_version, Myname, usage)); std_out(fmtmk("%s\nusage:\t%s%s", procps_version, Myname, usage));
case 'i': case 'i':
@ -2482,6 +2537,14 @@ static void do_key (unsigned c)
win_select(0); win_select(0);
break; break;
case 'H':
if (VIZCHKc) {
TOGw(Curwin, Show_THREADS);
show_msg(fmtmk("Show threads %s"
, CHKw(Curwin, Show_THREADS) ? "On" : "Off"));
}
break;
case 'h': case 'h':
case '?': case '?':
{ char ch; { char ch;

3
top.h
View File

@ -277,6 +277,7 @@ enum pflag {
#define View_NOBOLD 0x0001 // 'B' - disable 'bold' attribute globally #define View_NOBOLD 0x0001 // 'B' - disable 'bold' attribute globally
// 'Show_' & 'Qsrt_' flags are for task display in a visible window // 'Show_' & 'Qsrt_' flags are for task display in a visible window
#define Show_THREADS 0x10000 // 'H' - show threads in each task
#define Show_COLORS 0x0800 // 'z' - show in color (vs. mono) #define Show_COLORS 0x0800 // 'z' - show in color (vs. mono)
#define Show_HIBOLD 0x0400 // 'b' - rows and/or cols bold (vs. reverse) #define Show_HIBOLD 0x0400 // 'b' - rows and/or cols bold (vs. reverse)
#define Show_HICOLS 0x0200 // 'x' - show sort column highlighted #define Show_HICOLS 0x0200 // 'x' - show sort column highlighted
@ -413,7 +414,7 @@ typedef struct WIN_t {
" f,o . Fields/Columns: '\01f\02' add or remove; '\01o\02' change display order\n" \ " f,o . Fields/Columns: '\01f\02' add or remove; '\01o\02' change display order\n" \
" F or O . Select sort field\n" \ " F or O . Select sort field\n" \
" <,> . Move sort field: '\01<\02' next col left; '\01>\02' next col right\n" \ " <,> . Move sort field: '\01<\02' next col left; '\01>\02' next col right\n" \
" R . Toggle normal/reverse sort\n" \ " R,H . Toggle: '\01R\02' normal/reverse sort; '\01H\02' show threads\n" \
" c,i,S . Toggle: '\01c\02' cmd name/line; '\01i\02' idle tasks; '\01S\02' cumulative time\n" \ " c,i,S . Toggle: '\01c\02' cmd name/line; '\01i\02' idle tasks; '\01S\02' cumulative time\n" \
" x\05,\01y\05 . Toggle highlights: '\01x\02' sort field; '\01y\02' running tasks\n" \ " x\05,\01y\05 . Toggle highlights: '\01x\02' sort field; '\01y\02' running tasks\n" \
" z\05,\01b\05 . Toggle: '\01z\02' color/mono; '\01b\02' bold/reverse (only if 'x' or 'y')\n" \ " z\05,\01b\05 . Toggle: '\01z\02' color/mono; '\01b\02' bold/reverse (only if 'x' or 'y')\n" \