Re: PATCH: Print "threads" in top(1) output
13.01.2013 14:55 полÑзоваÑÐµÐ»Ñ "Philip Guenther" напиÑал: > > On Mon, 7 Jan 2013, Vadim Zhukov wrote: > > Small nit that allows (immediately) differentiate "processes" and > > "threads" output of top(1). Adds another dependency on "machine.h", > > though. :( Tested on both smart and dumb terminals. Any comments/okays? > > Adding an extern declaration to a .c file? Blech. Adding an argument > (...and fixing the incorrect function header comment...) is the Right > Thing, IMO. You're right. I like your diff more. > ok? > > Philip Guenther > > Index: display.c > === > RCS file: /cvs/src/usr.bin/top/display.c,v > retrieving revision 1.43 > diff -u -p -r1.43 display.c > --- display.c 5 Jun 2012 18:52:53 - 1.43 > +++ display.c 13 Jan 2013 10:52:06 - > @@ -262,12 +262,12 @@ i_timeofday(time_t * tod) > } > > /* > - * *_procstates(total, brkdn, names) - print the process summary line > + * *_procstates(total, brkdn, threads) - print the process/thread summary line > * > * Assumptions: cursor is at the beginning of the line on entry > */ > void > -i_procstates(int total, int *brkdn) > +i_procstates(int total, int *brkdn, int threads) > { > if (screen_length > 2 || !smart_terminal) { > int i; > @@ -275,23 +275,26 @@ i_procstates(int total, int *brkdn) > > move(1, 0); > clrtoeol(); > - /* write current number of processes and remember the value */ > - printwp("%d processes:", total); > + /* write current number of procs and remember the value */ > + if (threads == Yes) > + printwp("%d threads:", total); > + else > + printwp("%d processes:", total); > > if (smart_terminal) > move(1, 15); > else { > /* put out enough spaces to get to column 15 */ > i = digits(total); > - while (i++ < 4) { > + while (i++ < (threads == Yes ? 6 : 4)) { > if (putchar(' ') == EOF) > exit(1); > } > } > > /* format and print the process state summary */ > - summary_format(procstates_buffer, sizeof(procstates_buffer), brkdn, > - procstate_names); > + summary_format(procstates_buffer, sizeof(procstates_buffer), > + brkdn, procstate_names); > > addstrp(procstates_buffer); > putn(); > @@ -299,7 +302,7 @@ i_procstates(int total, int *brkdn) > } > > /* > - * *_cpustates(states, names) - print the cpu state percentages > + * *_cpustates(states) - print the cpu state percentages > * > * Assumptions: cursor is on the PREVIOUS line > */ > Index: display.h > === > RCS file: /cvs/src/usr.bin/top/display.h,v > retrieving revision 1.11 > diff -u -p -r1.11 display.h > --- display.h 22 Nov 2007 11:01:04 - 1.11 > +++ display.h 13 Jan 2013 10:52:06 - > @@ -38,7 +38,7 @@ int display_resize(void); > void i_loadave(int, double *); > void u_loadave(int, double *); > void i_timeofday(time_t *); > -void i_procstates(int, int *); > +void i_procstates(int, int *, int); > void u_procstates(int, int *); > void i_cpustates(int64_t *); > void u_cpustates(int64_t *); > Index: top.c > === > RCS file: /cvs/src/usr.bin/top/top.c,v > retrieving revision 1.79 > diff -u -p -r1.79 top.c > --- top.c 8 Jun 2012 13:41:16 - 1.79 > +++ top.c 13 Jan 2013 10:52:06 - > @@ -452,8 +452,9 @@ restart: > time(&curr_time); > i_timeofday(&curr_time); > > - /* display process state breakdown */ > - i_procstates(system_info.p_total, system_info.procstates); > + /* display process/threads state breakdown */ > + i_procstates(system_info.p_total, system_info.procstates, > + ps.threads); > > /* display the cpu state percentage breakdown */ > i_cpustates(system_info.cpustates);
Re: PATCH: Print "threads" in top(1) output
On Mon, 7 Jan 2013, Vadim Zhukov wrote: > Small nit that allows (immediately) differentiate "processes" and > "threads" output of top(1). Adds another dependency on "machine.h", > though. :( Tested on both smart and dumb terminals. Any comments/okays? Adding an extern declaration to a .c file? Blech. Adding an argument (...and fixing the incorrect function header comment...) is the Right Thing, IMO. ok? Philip Guenther Index: display.c === RCS file: /cvs/src/usr.bin/top/display.c,v retrieving revision 1.43 diff -u -p -r1.43 display.c --- display.c 5 Jun 2012 18:52:53 - 1.43 +++ display.c 13 Jan 2013 10:52:06 - @@ -262,12 +262,12 @@ i_timeofday(time_t * tod) } /* - * *_procstates(total, brkdn, names) - print the process summary line + * *_procstates(total, brkdn, threads) - print the process/thread summary line * * Assumptions: cursor is at the beginning of the line on entry */ void -i_procstates(int total, int *brkdn) +i_procstates(int total, int *brkdn, int threads) { if (screen_length > 2 || !smart_terminal) { int i; @@ -275,23 +275,26 @@ i_procstates(int total, int *brkdn) move(1, 0); clrtoeol(); - /* write current number of processes and remember the value */ - printwp("%d processes:", total); + /* write current number of procs and remember the value */ + if (threads == Yes) + printwp("%d threads:", total); + else + printwp("%d processes:", total); if (smart_terminal) move(1, 15); else { /* put out enough spaces to get to column 15 */ i = digits(total); - while (i++ < 4) { + while (i++ < (threads == Yes ? 6 : 4)) { if (putchar(' ') == EOF) exit(1); } } /* format and print the process state summary */ - summary_format(procstates_buffer, sizeof(procstates_buffer), brkdn, - procstate_names); + summary_format(procstates_buffer, sizeof(procstates_buffer), + brkdn, procstate_names); addstrp(procstates_buffer); putn(); @@ -299,7 +302,7 @@ i_procstates(int total, int *brkdn) } /* - * *_cpustates(states, names) - print the cpu state percentages + * *_cpustates(states) - print the cpu state percentages * * Assumptions: cursor is on the PREVIOUS line */ Index: display.h === RCS file: /cvs/src/usr.bin/top/display.h,v retrieving revision 1.11 diff -u -p -r1.11 display.h --- display.h 22 Nov 2007 11:01:04 - 1.11 +++ display.h 13 Jan 2013 10:52:06 - @@ -38,7 +38,7 @@ int display_resize(void); void i_loadave(int, double *); void u_loadave(int, double *); void i_timeofday(time_t *); -void i_procstates(int, int *); +void i_procstates(int, int *, int); void u_procstates(int, int *); void i_cpustates(int64_t *); void u_cpustates(int64_t *); Index: top.c === RCS file: /cvs/src/usr.bin/top/top.c,v retrieving revision 1.79 diff -u -p -r1.79 top.c --- top.c 8 Jun 2012 13:41:16 - 1.79 +++ top.c 13 Jan 2013 10:52:06 - @@ -452,8 +452,9 @@ restart: time(&curr_time); i_timeofday(&curr_time); - /* display process state breakdown */ - i_procstates(system_info.p_total, system_info.procstates); + /* display process/threads state breakdown */ + i_procstates(system_info.p_total, system_info.procstates, + ps.threads); /* display the cpu state percentage breakdown */ i_cpustates(system_info.cpustates);
Re: PATCH: Print "threads" in top(1) output
On Mon, Jan 07, 2013 at 05:58:43PM +0400, Vadim Zhukov wrote: > Small nit that allows (immediately) differentiate "processes" and > "threads" output of top(1). Adds another dependency on "machine.h", > though. :( Tested on both smart and dumb terminals. Any comments/okays? > > -- > WBR, > Vadim Zhukov > > > Index: display.c > === > RCS file: /cvs/src/usr.bin/top/display.c,v > retrieving revision 1.43 > diff -u -p -r1.43 display.c > --- display.c 5 Jun 2012 18:52:53 - 1.43 > +++ display.c 7 Jan 2013 13:50:38 - > @@ -100,6 +100,7 @@ int y_idlecursor; > int y_procs; > extern int ncpu; > extern int combine_cpus; > +extern struct process_select ps; > > int header_status = Yes; > > @@ -275,15 +276,18 @@ i_procstates(int total, int *brkdn) > > move(1, 0); > clrtoeol(); > - /* write current number of processes and remember the value */ > - printwp("%d processes:", total); > + /* write current number of procs and remember the value */ > + if (ps.threads == Yes) > + printwp("%d threads:", total); > + else > + printwp("%d processes:", total); > > if (smart_terminal) > move(1, 15); > else { > /* put out enough spaces to get to column 15 */ > i = digits(total); > - while (i++ < 4) { > + while (i++ < (ps.threads == Yes ? 6 : 4)) { > if (putchar(' ') == EOF) > exit(1); > } I like that. guenther, any objection ?
PATCH: Print "threads" in top(1) output
Small nit that allows (immediately) differentiate "processes" and "threads" output of top(1). Adds another dependency on "machine.h", though. :( Tested on both smart and dumb terminals. Any comments/okays? -- WBR, Vadim Zhukov Index: display.c === RCS file: /cvs/src/usr.bin/top/display.c,v retrieving revision 1.43 diff -u -p -r1.43 display.c --- display.c 5 Jun 2012 18:52:53 - 1.43 +++ display.c 7 Jan 2013 13:50:38 - @@ -100,6 +100,7 @@ int y_idlecursor; int y_procs; extern int ncpu; extern int combine_cpus; +extern struct process_select ps; int header_status = Yes; @@ -275,15 +276,18 @@ i_procstates(int total, int *brkdn) move(1, 0); clrtoeol(); - /* write current number of processes and remember the value */ - printwp("%d processes:", total); + /* write current number of procs and remember the value */ + if (ps.threads == Yes) + printwp("%d threads:", total); + else + printwp("%d processes:", total); if (smart_terminal) move(1, 15); else { /* put out enough spaces to get to column 15 */ i = digits(total); - while (i++ < 4) { + while (i++ < (ps.threads == Yes ? 6 : 4)) { if (putchar(' ') == EOF) exit(1); }