void-packages/srcpkgs/procps/patches/procps-3.2.7-slabtop-once.p...

114 lines
3.0 KiB
Diff

diff -up procps-3.2.7/slabtop.c.once procps-3.2.7/slabtop.c
--- procps-3.2.7/slabtop.c.once 2008-12-11 13:24:52.000000000 +0100
+++ procps-3.2.7/slabtop.c 2008-12-11 13:33:12.000000000 +0100
@@ -268,9 +268,24 @@ static void parse_input(char c)
}
}
+/*printw or printf depending on the context*/
+static void printwf(int once, const char *s,...)
+{
+va_list va;
+
+va_start(va,s);
+if(once)
+ vprintf(s,va);
+else
+ vwprintw(stdscr, s, va);
+va_end(va);
+}
+
+
int main(int argc, char *argv[])
{
int o;
+ int once = 0;
unsigned short old_rows;
struct slab_info *slab_list = NULL;
@@ -307,6 +322,7 @@ int main(int argc, char *argv[])
break;
case 'o':
delay = 0;
+ once = 1;
break;
case 'V':
display_version();
@@ -322,12 +338,18 @@ 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);
- signal(SIGINT, sigint_handler);
+ if(!once) {
+ initscr();
+ term_size(0);
+ old_rows = rows;
+ resizeterm(rows, cols);
+ signal(SIGWINCH, term_size);
+ signal(SIGINT, sigint_handler);
+ } else {
+ old_rows = rows;
+ rows = 80;
+ cols = 24;
+ }
do {
struct slab_info *curr;
@@ -341,12 +363,12 @@ int main(int argc, char *argv[])
break;
if (old_rows != rows) {
- resizeterm(rows, cols);
+ if(!once) resizeterm(rows, cols);
old_rows = rows;
}
move(0,0);
- printw( " Active / Total Objects (%% used) : %d / %d (%.1f%%)\n"
+ printwf(once, " 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"
@@ -360,15 +382,15 @@ int main(int argc, char *argv[])
slab_list = slabsort(slab_list);
- attron(A_REVERSE);
- printw( "%6s %6s %4s %8s %6s %8s %10s %-23s\n",
+ if(!once) attron(A_REVERSE);
+ printwf(once, "%6s %6s %4s %8s %6s %8s %10s %-23s\n",
"OBJS", "ACTIVE", "USE", "OBJ SIZE", "SLABS",
"OBJ/SLAB", "CACHE SIZE", "NAME");
- attroff(A_REVERSE);
+ if(!once) 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",
+ printwf(once, "%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,7 +398,7 @@ int main(int argc, char *argv[])
curr = curr->next;
}
- refresh();
+ if(!once) refresh();
put_slabinfo(slab_list);
FD_ZERO(&readfds);
@@ -392,6 +414,6 @@ int main(int argc, char *argv[])
tcsetattr(0, TCSAFLUSH, &saved_tty);
free_slabinfo(slab_list);
- endwin();
+ if(!once) endwin();
return 0;
}