Updated with Tizen:Base source codes
[external/procps.git] / packaging / procps-3.2.7-slabtop-once.patch
1 diff -up procps-3.2.7/slabtop.c.once procps-3.2.7/slabtop.c
2 --- procps-3.2.7/slabtop.c.once 2008-12-11 13:24:52.000000000 +0100
3 +++ procps-3.2.7/slabtop.c      2008-12-11 13:33:12.000000000 +0100
4 @@ -268,9 +268,24 @@ static void parse_input(char c)
5         }
6  }
7  
8 +/*printw or printf depending on the context*/
9 +static void printwf(int once, const char *s,...)
10 +{
11 +va_list va;
12 +
13 +va_start(va,s);
14 +if(once) 
15 +    vprintf(s,va);
16 +else     
17 +    vwprintw(stdscr, s, va);
18 +va_end(va);
19 +}
20 +
21 +
22  int main(int argc, char *argv[])
23  {
24         int o;
25 +        int once = 0;
26         unsigned short old_rows;
27         struct slab_info *slab_list = NULL;
28  
29 @@ -307,6 +322,7 @@ int main(int argc, char *argv[])
30                         break;
31                 case 'o':
32                         delay = 0;
33 +                        once = 1;
34                         break;
35                 case 'V':
36                         display_version();
37 @@ -322,12 +338,18 @@ int main(int argc, char *argv[])
38         if (tcgetattr(0, &saved_tty) == -1)
39                 perror("tcgetattr");
40  
41 -       initscr();
42 -       term_size(0);
43 -       old_rows = rows;
44 -       resizeterm(rows, cols);
45 -       signal(SIGWINCH, term_size);
46 -       signal(SIGINT, sigint_handler);
47 +        if(!once) {
48 +            initscr();
49 +           term_size(0);
50 +           old_rows = rows;
51 +           resizeterm(rows, cols);
52 +           signal(SIGWINCH, term_size);
53 +           signal(SIGINT, sigint_handler); 
54 +        } else {
55 +            old_rows = rows;
56 +            rows = 80;
57 +            cols = 24;
58 +        }
59  
60         do {
61                 struct slab_info *curr;
62 @@ -341,12 +363,12 @@ int main(int argc, char *argv[])
63                         break;
64  
65                 if (old_rows != rows) {
66 -                       resizeterm(rows, cols);
67 +                       if(!once) resizeterm(rows, cols);
68                         old_rows = rows;
69                 }
70  
71                 move(0,0);
72 -               printw( " Active / Total Objects (%% used)    : %d / %d (%.1f%%)\n"
73 +               printwf(once,   " Active / Total Objects (%% used)    : %d / %d (%.1f%%)\n"
74                         " Active / Total Slabs (%% used)      : %d / %d (%.1f%%)\n"
75                         " Active / Total Caches (%% used)     : %d / %d (%.1f%%)\n"
76                         " Active / Total Size (%% used)       : %.2fK / %.2fK (%.1f%%)\n"
77 @@ -360,15 +382,15 @@ int main(int argc, char *argv[])
78  
79                 slab_list = slabsort(slab_list);
80  
81 -               attron(A_REVERSE);
82 -               printw( "%6s %6s %4s %8s %6s %8s %10s %-23s\n",
83 +               if(!once) attron(A_REVERSE);
84 +               printwf(once,   "%6s %6s %4s %8s %6s %8s %10s %-23s\n",
85                         "OBJS", "ACTIVE", "USE", "OBJ SIZE", "SLABS",
86                         "OBJ/SLAB", "CACHE SIZE", "NAME");
87 -               attroff(A_REVERSE);
88 +               if(!once) attroff(A_REVERSE);
89  
90                 curr = slab_list;
91                 for (i = 0; i < rows - 8 && curr->next; i++) {
92 -                       printw("%6u %6u %3u%% %7.2fK %6u %8u %9uK %-23s\n",
93 +                       printwf(once, "%6u %6u %3u%% %7.2fK %6u %8u %9uK %-23s\n",
94                                 curr->nr_objs, curr->nr_active_objs, curr->use,
95                                 curr->obj_size / 1024.0, curr->nr_slabs,
96                                 curr->objs_per_slab, (unsigned)(curr->cache_size / 1024),
97 @@ -376,7 +398,7 @@ int main(int argc, char *argv[])
98                         curr = curr->next;
99                 }
100  
101 -               refresh();
102 +               if(!once) refresh();
103                 put_slabinfo(slab_list);
104  
105                 FD_ZERO(&readfds);
106 @@ -392,6 +414,6 @@ int main(int argc, char *argv[])
107  
108         tcsetattr(0, TCSAFLUSH, &saved_tty);
109         free_slabinfo(slab_list);
110 -       endwin();
111 +       if(!once) endwin();
112         return 0;
113  }