]> granicus.if.org Git - procps-ng/commitdiff
slabtop prints plain ASCII in once mode
authorCraig Small <csmall@enc.com.au>
Fri, 2 Dec 2011 11:36:38 +0000 (22:36 +1100)
committerCraig Small <csmall@enc.com.au>
Fri, 2 Dec 2011 11:36:38 +0000 (22:36 +1100)
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>

NEWS
slabtop.c

diff --git a/NEWS b/NEWS
index 30a0f278b279370de61c5e1213e519377d147b32..94a28c81d3586ce5e6f6b83971b2c47d2cc62f92 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ procps-3.3.0 --> procps-ng-3.3.1
   * vmstat -p <part> finds partitions. Was Debian patch vmstat_part_format
     fixes closed bugs RH#485243 and Debian#588677
   * 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
 ------------------------------------------------------
index 36025e2ff0065e900e4ed7929b44d83767f5754c..5c9d31e1e0d9e027dd97e8ee1ff11b5d77bdd647 100644 (file)
--- a/slabtop.c
+++ b/slabtop.c
@@ -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 o;
        unsigned short old_rows;
        struct slab_info *slab_list = NULL;
+  int run_once=0;
 
        struct option longopts[] = {
                { "delay",      1, NULL, 'd' },
@@ -306,6 +308,7 @@ int main(int argc, char *argv[])
                        sort_func = set_sort_func(optarg[0]);
                        break;
                case 'o':
+      run_once=1;
                        delay = 0;
                        break;
                case 'V':
@@ -322,11 +325,13 @@ int main(int argc, char *argv[])
        if (tcgetattr(0, &saved_tty) == -1)
                perror("tcgetattr");
 
-       initscr();
-       term_size(0);
        old_rows = rows;
-       resizeterm(rows, cols);
-       signal(SIGWINCH, term_size);
+       term_size(0);
+  if (!run_once) {
+    initscr();
+         resizeterm(rows, cols);
+         signal(SIGWINCH, term_size);
+  }
        signal(SIGINT, sigint_handler);
 
        do {
@@ -340,13 +345,13 @@ int main(int argc, char *argv[])
                if (get_slabinfo(&slab_list, &stats))
                        break;
 
-               if (old_rows != rows) {
+               if (!run_once && old_rows != rows) {
                        resizeterm(rows, cols);
                        old_rows = rows;
                }
 
                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 Caches (%% used)     : %d / %d (%.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);
 
                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",
                        "OBJ/SLAB", "CACHE SIZE", "NAME");
                attroff(A_REVERSE);
 
                curr = slab_list;
                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->obj_size / 1024.0, curr->nr_slabs,
                                curr->objs_per_slab, (unsigned)(curr->cache_size / 1024),
@@ -376,22 +381,24 @@ int main(int argc, char *argv[])
                        curr = curr->next;
                }
 
-               refresh();
                put_slabinfo(slab_list);
 
-               FD_ZERO(&readfds);
-               FD_SET(0, &readfds);
-               tv.tv_sec = delay;
-               tv.tv_usec = 0;
-               if (select(1, &readfds, NULL, NULL, &tv) > 0) {
-                       if (read(0, &c, 1) != 1)
-                               break;
-                       parse_input(c);
-               }
+               if (!run_once) {
+      refresh();
+                 FD_ZERO(&readfds);
+                 FD_SET(0, &readfds);
+                 tv.tv_sec = delay;
+                 tv.tv_usec = 0;
+                 if (select(1, &readfds, NULL, NULL, &tv) > 0) {
+                         if (read(0, &c, 1) != 1)
+                                 break;
+                         parse_input(c);
+                 }
+    }
        } while (delay);
 
        tcsetattr(0, TCSAFLUSH, &saved_tty);
        free_slabinfo(slab_list);
-       endwin();
+       if (!run_once) endwin();
        return 0;
 }