slabtop prints plain ASCII in once mode

Using ncurses initscr/endwin clears the screen for xterm/etc it
now prints raw text using printf
Bug-Debian: http://bugs.debian.org/503089
Author: Craig Small <csmall@debian.org>
This commit is contained in:
Craig Small 2011-12-02 22:36:38 +11:00
parent bf1cd8b6e7
commit 0bee2f1060
2 changed files with 27 additions and 19 deletions

1
NEWS
View File

@ -7,6 +7,7 @@ procps-3.3.0 --> procps-ng-3.3.1
* vmstat -p <part> finds partitions. Was Debian patch vmstat_part_format * vmstat -p <part> finds partitions. Was Debian patch vmstat_part_format
fixes closed bugs RH#485243 and Debian#588677 fixes closed bugs RH#485243 and Debian#588677
* watch 8-bit clean, Was Debian patch watch_8bitchar * watch 8-bit clean, Was Debian patch watch_8bitchar
* slabtop prints plain ASCII in once mode
procps-3.2.8 --> procps-ng-3.3.0 procps-3.2.8 --> procps-ng-3.3.0
------------------------------------------------------ ------------------------------------------------------

View File

@ -268,11 +268,13 @@ static void parse_input(char c)
} }
} }
#define print_line(fmt, args...) if (run_once) printf(fmt, ## args); else printw(fmt, ## args)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int o; int o;
unsigned short old_rows; unsigned short old_rows;
struct slab_info *slab_list = NULL; struct slab_info *slab_list = NULL;
int run_once=0;
struct option longopts[] = { struct option longopts[] = {
{ "delay", 1, NULL, 'd' }, { "delay", 1, NULL, 'd' },
@ -306,6 +308,7 @@ int main(int argc, char *argv[])
sort_func = set_sort_func(optarg[0]); sort_func = set_sort_func(optarg[0]);
break; break;
case 'o': case 'o':
run_once=1;
delay = 0; delay = 0;
break; break;
case 'V': case 'V':
@ -322,11 +325,13 @@ int main(int argc, char *argv[])
if (tcgetattr(0, &saved_tty) == -1) if (tcgetattr(0, &saved_tty) == -1)
perror("tcgetattr"); perror("tcgetattr");
initscr();
term_size(0);
old_rows = rows; old_rows = rows;
resizeterm(rows, cols); term_size(0);
signal(SIGWINCH, term_size); if (!run_once) {
initscr();
resizeterm(rows, cols);
signal(SIGWINCH, term_size);
}
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
do { do {
@ -340,13 +345,13 @@ int main(int argc, char *argv[])
if (get_slabinfo(&slab_list, &stats)) if (get_slabinfo(&slab_list, &stats))
break; break;
if (old_rows != rows) { if (!run_once && old_rows != rows) {
resizeterm(rows, cols); resizeterm(rows, cols);
old_rows = rows; old_rows = rows;
} }
move(0,0); move(0,0);
printw( " Active / Total Objects (%% used) : %d / %d (%.1f%%)\n" print_line( " Active / Total Objects (%% used) : %d / %d (%.1f%%)\n"
" Active / Total Slabs (%% used) : %d / %d (%.1f%%)\n" " Active / Total Slabs (%% used) : %d / %d (%.1f%%)\n"
" Active / Total Caches (%% used) : %d / %d (%.1f%%)\n" " Active / Total Caches (%% used) : %d / %d (%.1f%%)\n"
" Active / Total Size (%% used) : %.2fK / %.2fK (%.1f%%)\n" " Active / Total Size (%% used) : %.2fK / %.2fK (%.1f%%)\n"
@ -361,14 +366,14 @@ int main(int argc, char *argv[])
slab_list = slabsort(slab_list); slab_list = slabsort(slab_list);
attron(A_REVERSE); attron(A_REVERSE);
printw( "%6s %6s %4s %8s %6s %8s %10s %-23s\n", print_line( "%6s %6s %4s %8s %6s %8s %10s %-23s\n",
"OBJS", "ACTIVE", "USE", "OBJ SIZE", "SLABS", "OBJS", "ACTIVE", "USE", "OBJ SIZE", "SLABS",
"OBJ/SLAB", "CACHE SIZE", "NAME"); "OBJ/SLAB", "CACHE SIZE", "NAME");
attroff(A_REVERSE); attroff(A_REVERSE);
curr = slab_list; curr = slab_list;
for (i = 0; i < rows - 8 && curr->next; i++) { for (i = 0; i < rows - 8 && curr->next; i++) {
printw("%6u %6u %3u%% %7.2fK %6u %8u %9uK %-23s\n", print_line("%6u %6u %3u%% %7.2fK %6u %8u %9uK %-23s\n",
curr->nr_objs, curr->nr_active_objs, curr->use, curr->nr_objs, curr->nr_active_objs, curr->use,
curr->obj_size / 1024.0, curr->nr_slabs, curr->obj_size / 1024.0, curr->nr_slabs,
curr->objs_per_slab, (unsigned)(curr->cache_size / 1024), curr->objs_per_slab, (unsigned)(curr->cache_size / 1024),
@ -376,22 +381,24 @@ int main(int argc, char *argv[])
curr = curr->next; curr = curr->next;
} }
refresh();
put_slabinfo(slab_list); put_slabinfo(slab_list);
FD_ZERO(&readfds); if (!run_once) {
FD_SET(0, &readfds); refresh();
tv.tv_sec = delay; FD_ZERO(&readfds);
tv.tv_usec = 0; FD_SET(0, &readfds);
if (select(1, &readfds, NULL, NULL, &tv) > 0) { tv.tv_sec = delay;
if (read(0, &c, 1) != 1) tv.tv_usec = 0;
break; if (select(1, &readfds, NULL, NULL, &tv) > 0) {
parse_input(c); if (read(0, &c, 1) != 1)
} break;
parse_input(c);
}
}
} while (delay); } while (delay);
tcsetattr(0, TCSAFLUSH, &saved_tty); tcsetattr(0, TCSAFLUSH, &saved_tty);
free_slabinfo(slab_list); free_slabinfo(slab_list);
endwin(); if (!run_once) endwin();
return 0; return 0;
} }