summaryrefslogtreecommitdiff
path: root/core/procps/procps-3.2.7-slabtop-once.patch
blob: d3319cfe7bf9d49d70d89517a2d603589cada993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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;
 }