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 -0000 1.43 +++ display.c 13 Jan 2013 10:52:06 -0000 @@ -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 -0000 1.11 +++ display.h 13 Jan 2013 10:52:06 -0000 @@ -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 -0000 1.79 +++ top.c 13 Jan 2013 10:52:06 -0000 @@ -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);