xref: /aosp_15_r20/system/extras/showslab/showslab.c (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1*288bf522SAndroid Build Coastguard Worker #include <stdlib.h>
2*288bf522SAndroid Build Coastguard Worker #include <stdio.h>
3*288bf522SAndroid Build Coastguard Worker #include <string.h>
4*288bf522SAndroid Build Coastguard Worker #include <unistd.h>
5*288bf522SAndroid Build Coastguard Worker #include <errno.h>
6*288bf522SAndroid Build Coastguard Worker #include <ctype.h>
7*288bf522SAndroid Build Coastguard Worker #include <limits.h>
8*288bf522SAndroid Build Coastguard Worker 
9*288bf522SAndroid Build Coastguard Worker #define STRINGIFY_ARG(a)        #a
10*288bf522SAndroid Build Coastguard Worker #define STRINGIFY(a)            STRINGIFY_ARG(a)
11*288bf522SAndroid Build Coastguard Worker 
12*288bf522SAndroid Build Coastguard Worker #define DEF_SORT_FUNC		sort_nr_objs
13*288bf522SAndroid Build Coastguard Worker #define SLABINFO_LINE_LEN	512	/* size of longest line */
14*288bf522SAndroid Build Coastguard Worker #define SLABINFO_NAME_LEN	32	/* cache name size (will truncate) */
15*288bf522SAndroid Build Coastguard Worker #define SLABINFO_FILE		"/proc/slabinfo"
16*288bf522SAndroid Build Coastguard Worker #define DEF_NR_ROWS		15	/* default nr of caches to show */
17*288bf522SAndroid Build Coastguard Worker 
18*288bf522SAndroid Build Coastguard Worker /* object representing a slab cache (each line of slabinfo) */
19*288bf522SAndroid Build Coastguard Worker struct slab_info {
20*288bf522SAndroid Build Coastguard Worker 	char name[SLABINFO_NAME_LEN];	/* name of this cache */
21*288bf522SAndroid Build Coastguard Worker 	struct slab_info *next;
22*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_pages;		/* size of cache in pages */
23*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_objs;		/* number of objects in this cache */
24*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_active_objs;	/* number of active objects */
25*288bf522SAndroid Build Coastguard Worker 	unsigned long obj_size;		/* size of each object */
26*288bf522SAndroid Build Coastguard Worker 	unsigned long objs_per_slab;	/* number of objects per slab */
27*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_slabs;		/* number of slabs in this cache */
28*288bf522SAndroid Build Coastguard Worker 	unsigned long use;		/* percent full: total / active */
29*288bf522SAndroid Build Coastguard Worker };
30*288bf522SAndroid Build Coastguard Worker 
31*288bf522SAndroid Build Coastguard Worker /* object representing system-wide statistics */
32*288bf522SAndroid Build Coastguard Worker struct slab_stat {
33*288bf522SAndroid Build Coastguard Worker 	unsigned long total_size;	/* size of all objects */
34*288bf522SAndroid Build Coastguard Worker 	unsigned long active_size;	/* size of all active objects */
35*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_objs;		/* total number of objects */
36*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_active_objs;	/* total number of active objects */
37*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_slabs;		/* total number of slabs */
38*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_active_slabs;	/* total number of active slabs*/
39*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_caches;	/* number of caches */
40*288bf522SAndroid Build Coastguard Worker 	unsigned long nr_active_caches;	/* number of active caches */
41*288bf522SAndroid Build Coastguard Worker 	unsigned long avg_obj_size;	/* average object size */
42*288bf522SAndroid Build Coastguard Worker 	unsigned long min_obj_size;	/* size of smallest object */
43*288bf522SAndroid Build Coastguard Worker 	unsigned long max_obj_size;	/* size of largest object */
44*288bf522SAndroid Build Coastguard Worker };
45*288bf522SAndroid Build Coastguard Worker 
46*288bf522SAndroid Build Coastguard Worker typedef int (*sort_t)(const struct slab_info *, const struct slab_info *);
47*288bf522SAndroid Build Coastguard Worker static sort_t sort_func;
48*288bf522SAndroid Build Coastguard Worker 
49*288bf522SAndroid Build Coastguard Worker /*
50*288bf522SAndroid Build Coastguard Worker  * get_slabinfo - open, read, and parse a slabinfo 2.x file, which has the
51*288bf522SAndroid Build Coastguard Worker  * following format:
52*288bf522SAndroid Build Coastguard Worker  *
53*288bf522SAndroid Build Coastguard Worker  * slabinfo - version: 2.1
54*288bf522SAndroid Build Coastguard Worker  * <name>  <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>
55*288bf522SAndroid Build Coastguard Worker  * : tunables <limit> <batchcount> <sharedfactor>
56*288bf522SAndroid Build Coastguard Worker  * : slabdata <active_slabs> <num_slabs> <sharedavail>
57*288bf522SAndroid Build Coastguard Worker  *
58*288bf522SAndroid Build Coastguard Worker  * Returns the head of the new list of slab_info structures, or NULL on error.
59*288bf522SAndroid Build Coastguard Worker  */
get_slabinfo(struct slab_stat * stats)60*288bf522SAndroid Build Coastguard Worker static struct slab_info * get_slabinfo(struct slab_stat *stats)
61*288bf522SAndroid Build Coastguard Worker {
62*288bf522SAndroid Build Coastguard Worker 	struct slab_info *head = NULL, *p = NULL, *prev = NULL;
63*288bf522SAndroid Build Coastguard Worker 	FILE *slabfile;
64*288bf522SAndroid Build Coastguard Worker 	char line[SLABINFO_LINE_LEN];
65*288bf522SAndroid Build Coastguard Worker 	unsigned int major, minor;
66*288bf522SAndroid Build Coastguard Worker 
67*288bf522SAndroid Build Coastguard Worker 	slabfile = fopen(SLABINFO_FILE, "r");
68*288bf522SAndroid Build Coastguard Worker 	if (!slabfile) {
69*288bf522SAndroid Build Coastguard Worker 		perror("fopen");
70*288bf522SAndroid Build Coastguard Worker 		return NULL;
71*288bf522SAndroid Build Coastguard Worker 	}
72*288bf522SAndroid Build Coastguard Worker 
73*288bf522SAndroid Build Coastguard Worker 	if (!fgets(line, SLABINFO_LINE_LEN, slabfile)) {
74*288bf522SAndroid Build Coastguard Worker 		fprintf(stderr, "cannot read from " SLABINFO_FILE "\n");
75*288bf522SAndroid Build Coastguard Worker 		return NULL;
76*288bf522SAndroid Build Coastguard Worker 	}
77*288bf522SAndroid Build Coastguard Worker 
78*288bf522SAndroid Build Coastguard Worker 	if (sscanf(line, "slabinfo - version: %u.%u", &major, &minor) != 2) {
79*288bf522SAndroid Build Coastguard Worker 		fprintf(stderr, "unable to parse slabinfo version!\n");
80*288bf522SAndroid Build Coastguard Worker 		return NULL;
81*288bf522SAndroid Build Coastguard Worker 	}
82*288bf522SAndroid Build Coastguard Worker 
83*288bf522SAndroid Build Coastguard Worker 	if (major != 2 || minor > 1) {
84*288bf522SAndroid Build Coastguard Worker 		fprintf(stderr, "we only support slabinfo 2.0 and 2.1!\n");
85*288bf522SAndroid Build Coastguard Worker 		return NULL;
86*288bf522SAndroid Build Coastguard Worker 	}
87*288bf522SAndroid Build Coastguard Worker 
88*288bf522SAndroid Build Coastguard Worker 	stats->min_obj_size = INT_MAX;
89*288bf522SAndroid Build Coastguard Worker 
90*288bf522SAndroid Build Coastguard Worker 	while (fgets(line, SLABINFO_LINE_LEN, slabfile)) {
91*288bf522SAndroid Build Coastguard Worker 		unsigned long nr_active_slabs, pages_per_slab;
92*288bf522SAndroid Build Coastguard Worker 		int ret;
93*288bf522SAndroid Build Coastguard Worker 
94*288bf522SAndroid Build Coastguard Worker 		if (line[0] == '#')
95*288bf522SAndroid Build Coastguard Worker 			continue;
96*288bf522SAndroid Build Coastguard Worker 
97*288bf522SAndroid Build Coastguard Worker 		p = malloc(sizeof (struct slab_info));
98*288bf522SAndroid Build Coastguard Worker 		if (!p) {
99*288bf522SAndroid Build Coastguard Worker 			perror("malloc");
100*288bf522SAndroid Build Coastguard Worker 			head = NULL;
101*288bf522SAndroid Build Coastguard Worker 			break;
102*288bf522SAndroid Build Coastguard Worker 		}
103*288bf522SAndroid Build Coastguard Worker 		if (stats->nr_caches++ == 0)
104*288bf522SAndroid Build Coastguard Worker 			head = prev = p;
105*288bf522SAndroid Build Coastguard Worker 
106*288bf522SAndroid Build Coastguard Worker 		ret = sscanf(line, "%" STRINGIFY(SLABINFO_NAME_LEN) "s"
107*288bf522SAndroid Build Coastguard Worker 			     " %lu %lu %lu %lu %lu : tunables %*d %*d %*d : \
108*288bf522SAndroid Build Coastguard Worker 			     slabdata %lu %lu %*d", p->name,
109*288bf522SAndroid Build Coastguard Worker 			     &p->nr_active_objs, &p->nr_objs,
110*288bf522SAndroid Build Coastguard Worker 			     &p->obj_size, &p->objs_per_slab,
111*288bf522SAndroid Build Coastguard Worker 			     &pages_per_slab,
112*288bf522SAndroid Build Coastguard Worker 			     &nr_active_slabs,
113*288bf522SAndroid Build Coastguard Worker 			     &p->nr_slabs);
114*288bf522SAndroid Build Coastguard Worker 
115*288bf522SAndroid Build Coastguard Worker 		if (ret != 8) {
116*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "unrecognizable data in slabinfo!\n");
117*288bf522SAndroid Build Coastguard Worker 			head = NULL;
118*288bf522SAndroid Build Coastguard Worker 			break;
119*288bf522SAndroid Build Coastguard Worker 		}
120*288bf522SAndroid Build Coastguard Worker 
121*288bf522SAndroid Build Coastguard Worker 		if (p->obj_size < stats->min_obj_size)
122*288bf522SAndroid Build Coastguard Worker 			stats->min_obj_size = p->obj_size;
123*288bf522SAndroid Build Coastguard Worker 		if (p->obj_size > stats->max_obj_size)
124*288bf522SAndroid Build Coastguard Worker 			stats->max_obj_size = p->obj_size;
125*288bf522SAndroid Build Coastguard Worker 
126*288bf522SAndroid Build Coastguard Worker 		p->nr_pages = p->nr_slabs * pages_per_slab;
127*288bf522SAndroid Build Coastguard Worker 
128*288bf522SAndroid Build Coastguard Worker 		if (p->nr_objs) {
129*288bf522SAndroid Build Coastguard Worker 			p->use = 100 * p->nr_active_objs / p->nr_objs;
130*288bf522SAndroid Build Coastguard Worker 			stats->nr_active_caches++;
131*288bf522SAndroid Build Coastguard Worker 		} else
132*288bf522SAndroid Build Coastguard Worker 			p->use = 0;
133*288bf522SAndroid Build Coastguard Worker 
134*288bf522SAndroid Build Coastguard Worker 		stats->nr_objs += p->nr_objs;
135*288bf522SAndroid Build Coastguard Worker 		stats->nr_active_objs += p->nr_active_objs;
136*288bf522SAndroid Build Coastguard Worker 		stats->total_size += p->nr_objs * p->obj_size;
137*288bf522SAndroid Build Coastguard Worker 		stats->active_size += p->nr_active_objs * p->obj_size;
138*288bf522SAndroid Build Coastguard Worker 		stats->nr_slabs += p->nr_slabs;
139*288bf522SAndroid Build Coastguard Worker 		stats->nr_active_slabs += nr_active_slabs;
140*288bf522SAndroid Build Coastguard Worker 
141*288bf522SAndroid Build Coastguard Worker 		prev->next = p;
142*288bf522SAndroid Build Coastguard Worker 		prev = p;
143*288bf522SAndroid Build Coastguard Worker 	}
144*288bf522SAndroid Build Coastguard Worker 
145*288bf522SAndroid Build Coastguard Worker 	if (fclose(slabfile))
146*288bf522SAndroid Build Coastguard Worker 		perror("fclose");
147*288bf522SAndroid Build Coastguard Worker 
148*288bf522SAndroid Build Coastguard Worker 	if (p)
149*288bf522SAndroid Build Coastguard Worker 		p->next = NULL;
150*288bf522SAndroid Build Coastguard Worker 	if (stats->nr_objs)
151*288bf522SAndroid Build Coastguard Worker 		stats->avg_obj_size = stats->total_size / stats->nr_objs;
152*288bf522SAndroid Build Coastguard Worker 
153*288bf522SAndroid Build Coastguard Worker 	return head;
154*288bf522SAndroid Build Coastguard Worker }
155*288bf522SAndroid Build Coastguard Worker 
156*288bf522SAndroid Build Coastguard Worker /*
157*288bf522SAndroid Build Coastguard Worker  * free_slablist - deallocate the memory associated with each node in the
158*288bf522SAndroid Build Coastguard Worker  * provided slab_info linked list
159*288bf522SAndroid Build Coastguard Worker  */
free_slablist(struct slab_info * list)160*288bf522SAndroid Build Coastguard Worker static void free_slablist(struct slab_info *list)
161*288bf522SAndroid Build Coastguard Worker {
162*288bf522SAndroid Build Coastguard Worker 	while (list) {
163*288bf522SAndroid Build Coastguard Worker 		struct slab_info *temp = list->next;
164*288bf522SAndroid Build Coastguard Worker 		free(list);
165*288bf522SAndroid Build Coastguard Worker 		list = temp;
166*288bf522SAndroid Build Coastguard Worker 	}
167*288bf522SAndroid Build Coastguard Worker }
168*288bf522SAndroid Build Coastguard Worker 
merge_objs(struct slab_info * a,struct slab_info * b)169*288bf522SAndroid Build Coastguard Worker static struct slab_info *merge_objs(struct slab_info *a, struct slab_info *b)
170*288bf522SAndroid Build Coastguard Worker {
171*288bf522SAndroid Build Coastguard Worker 	struct slab_info list;
172*288bf522SAndroid Build Coastguard Worker 	struct slab_info *p = &list;
173*288bf522SAndroid Build Coastguard Worker 
174*288bf522SAndroid Build Coastguard Worker 	while (a && b) {
175*288bf522SAndroid Build Coastguard Worker 		if (sort_func(a, b)) {
176*288bf522SAndroid Build Coastguard Worker 			p->next = a;
177*288bf522SAndroid Build Coastguard Worker 			p = a;
178*288bf522SAndroid Build Coastguard Worker 			a = a->next;
179*288bf522SAndroid Build Coastguard Worker 		} else {
180*288bf522SAndroid Build Coastguard Worker 			p->next = b;
181*288bf522SAndroid Build Coastguard Worker 			p = b;
182*288bf522SAndroid Build Coastguard Worker 			b = b->next;
183*288bf522SAndroid Build Coastguard Worker 		}
184*288bf522SAndroid Build Coastguard Worker 	}
185*288bf522SAndroid Build Coastguard Worker 
186*288bf522SAndroid Build Coastguard Worker 	p->next = (a == NULL) ? b : a;
187*288bf522SAndroid Build Coastguard Worker 	return list.next;
188*288bf522SAndroid Build Coastguard Worker }
189*288bf522SAndroid Build Coastguard Worker 
190*288bf522SAndroid Build Coastguard Worker /*
191*288bf522SAndroid Build Coastguard Worker  * slabsort - merge sort the slab_info linked list based on sort_func
192*288bf522SAndroid Build Coastguard Worker  */
slabsort(struct slab_info * list)193*288bf522SAndroid Build Coastguard Worker static struct slab_info *slabsort(struct slab_info *list)
194*288bf522SAndroid Build Coastguard Worker {
195*288bf522SAndroid Build Coastguard Worker 	struct slab_info *a, *b;
196*288bf522SAndroid Build Coastguard Worker 
197*288bf522SAndroid Build Coastguard Worker 	if (!list || !list->next)
198*288bf522SAndroid Build Coastguard Worker 		return list;
199*288bf522SAndroid Build Coastguard Worker 
200*288bf522SAndroid Build Coastguard Worker 	a = list;
201*288bf522SAndroid Build Coastguard Worker 	b = list->next;
202*288bf522SAndroid Build Coastguard Worker 
203*288bf522SAndroid Build Coastguard Worker 	while (b && b->next) {
204*288bf522SAndroid Build Coastguard Worker 		list = list->next;
205*288bf522SAndroid Build Coastguard Worker 		b = b->next->next;
206*288bf522SAndroid Build Coastguard Worker 	}
207*288bf522SAndroid Build Coastguard Worker 
208*288bf522SAndroid Build Coastguard Worker 	b = list->next;
209*288bf522SAndroid Build Coastguard Worker 	list->next = NULL;
210*288bf522SAndroid Build Coastguard Worker 
211*288bf522SAndroid Build Coastguard Worker 	return merge_objs(slabsort(a), slabsort(b));
212*288bf522SAndroid Build Coastguard Worker }
213*288bf522SAndroid Build Coastguard Worker 
214*288bf522SAndroid Build Coastguard Worker /*
215*288bf522SAndroid Build Coastguard Worker  * Sort Routines.  Each of these should be associated with a command-line
216*288bf522SAndroid Build Coastguard Worker  * search option.  The functions should fit the prototype:
217*288bf522SAndroid Build Coastguard Worker  *
218*288bf522SAndroid Build Coastguard Worker  *	int sort_foo(const struct slab_info *a, const struct slab_info *b)
219*288bf522SAndroid Build Coastguard Worker  *
220*288bf522SAndroid Build Coastguard Worker  * They return zero if the first parameter is smaller than the second.
221*288bf522SAndroid Build Coastguard Worker  * Otherwise, they return nonzero.
222*288bf522SAndroid Build Coastguard Worker  */
223*288bf522SAndroid Build Coastguard Worker 
sort_name(const struct slab_info * a,const struct slab_info * b)224*288bf522SAndroid Build Coastguard Worker static int sort_name(const struct slab_info *a, const struct slab_info *b)
225*288bf522SAndroid Build Coastguard Worker {
226*288bf522SAndroid Build Coastguard Worker 	return (strcmp(a->name, b->name) < 0 ) ? 1: 0;
227*288bf522SAndroid Build Coastguard Worker }
228*288bf522SAndroid Build Coastguard Worker 
229*288bf522SAndroid Build Coastguard Worker #define BUILD_SORT_FUNC(VAL) \
230*288bf522SAndroid Build Coastguard Worker 	static int sort_ ## VAL \
231*288bf522SAndroid Build Coastguard Worker 		(const struct slab_info *a, const struct slab_info *b) { \
232*288bf522SAndroid Build Coastguard Worker 			return (a-> VAL > b-> VAL); }
233*288bf522SAndroid Build Coastguard Worker 
234*288bf522SAndroid Build Coastguard Worker BUILD_SORT_FUNC(nr_objs)
BUILD_SORT_FUNC(nr_active_objs)235*288bf522SAndroid Build Coastguard Worker BUILD_SORT_FUNC(nr_active_objs)
236*288bf522SAndroid Build Coastguard Worker BUILD_SORT_FUNC(obj_size)
237*288bf522SAndroid Build Coastguard Worker BUILD_SORT_FUNC(objs_per_slab)
238*288bf522SAndroid Build Coastguard Worker BUILD_SORT_FUNC(nr_slabs)
239*288bf522SAndroid Build Coastguard Worker BUILD_SORT_FUNC(use)
240*288bf522SAndroid Build Coastguard Worker BUILD_SORT_FUNC(nr_pages)
241*288bf522SAndroid Build Coastguard Worker 
242*288bf522SAndroid Build Coastguard Worker /*
243*288bf522SAndroid Build Coastguard Worker  * set_sort_func - return the slab_sort_func that matches the given key.
244*288bf522SAndroid Build Coastguard Worker  * On unrecognizable key, the call returns NULL.
245*288bf522SAndroid Build Coastguard Worker  */
246*288bf522SAndroid Build Coastguard Worker static sort_t set_sort_func(char key)
247*288bf522SAndroid Build Coastguard Worker {
248*288bf522SAndroid Build Coastguard Worker 	switch (tolower(key)) {
249*288bf522SAndroid Build Coastguard Worker 	case 'a':
250*288bf522SAndroid Build Coastguard Worker 		return sort_nr_active_objs;
251*288bf522SAndroid Build Coastguard Worker 	case 'c':
252*288bf522SAndroid Build Coastguard Worker 		return sort_nr_pages;
253*288bf522SAndroid Build Coastguard Worker 	case 'l':
254*288bf522SAndroid Build Coastguard Worker 		return sort_nr_slabs;
255*288bf522SAndroid Build Coastguard Worker 	case 'n':
256*288bf522SAndroid Build Coastguard Worker 		return sort_name;
257*288bf522SAndroid Build Coastguard Worker 	case 'o':
258*288bf522SAndroid Build Coastguard Worker 		return sort_nr_objs;
259*288bf522SAndroid Build Coastguard Worker 	case 'p':
260*288bf522SAndroid Build Coastguard Worker 		return sort_objs_per_slab;
261*288bf522SAndroid Build Coastguard Worker 	case 's':
262*288bf522SAndroid Build Coastguard Worker 		return sort_obj_size;
263*288bf522SAndroid Build Coastguard Worker 	case 'u':
264*288bf522SAndroid Build Coastguard Worker 		return sort_use;
265*288bf522SAndroid Build Coastguard Worker 	default:
266*288bf522SAndroid Build Coastguard Worker 		return NULL;
267*288bf522SAndroid Build Coastguard Worker 	}
268*288bf522SAndroid Build Coastguard Worker }
269*288bf522SAndroid Build Coastguard Worker 
main(int argc,char * argv[])270*288bf522SAndroid Build Coastguard Worker int main(int argc, char *argv[])
271*288bf522SAndroid Build Coastguard Worker {
272*288bf522SAndroid Build Coastguard Worker 	struct slab_info *list, *p;
273*288bf522SAndroid Build Coastguard Worker 	struct slab_stat stats = { .nr_objs = 0 };
274*288bf522SAndroid Build Coastguard Worker 	unsigned int page_size = getpagesize() / 1024, nr_rows = DEF_NR_ROWS, i;
275*288bf522SAndroid Build Coastguard Worker 
276*288bf522SAndroid Build Coastguard Worker 	sort_func = DEF_SORT_FUNC;
277*288bf522SAndroid Build Coastguard Worker 
278*288bf522SAndroid Build Coastguard Worker 	if (argc > 1) {
279*288bf522SAndroid Build Coastguard Worker 		/* FIXME: Ugh. */
280*288bf522SAndroid Build Coastguard Worker 		if (argc == 3 && !strcmp(argv[1], "-n")) {
281*288bf522SAndroid Build Coastguard Worker 			errno = 0;
282*288bf522SAndroid Build Coastguard Worker 			nr_rows = (unsigned int) strtoul(argv[2], NULL, 0);
283*288bf522SAndroid Build Coastguard Worker 			if (errno) {
284*288bf522SAndroid Build Coastguard Worker 				perror("strtoul");
285*288bf522SAndroid Build Coastguard Worker 				exit(EXIT_FAILURE);
286*288bf522SAndroid Build Coastguard Worker 			}
287*288bf522SAndroid Build Coastguard Worker 		}
288*288bf522SAndroid Build Coastguard Worker 		else if (argc == 3 && !strcmp(argv[1], "-s"))
289*288bf522SAndroid Build Coastguard Worker 			sort_func = set_sort_func(argv[2][0]) ? : DEF_SORT_FUNC;
290*288bf522SAndroid Build Coastguard Worker 		else {
291*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "usage: %s [options]\n\n", argv[0]);
292*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "options:\n");
293*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  -s S   specify sort criteria S\n");
294*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  -h     display this help\n\n");
295*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "Valid sort criteria:\n");
296*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  a: number of Active objects\n");
297*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  c: Cache size\n");
298*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  l: number of sLabs\n");
299*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  n: Name\n");
300*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  o: number of Objects\n");
301*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  p: objects Per slab\n");
302*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  s: object Size\n");
303*288bf522SAndroid Build Coastguard Worker 			fprintf(stderr, "  u: cache Utilization\n");
304*288bf522SAndroid Build Coastguard Worker 			exit(EXIT_FAILURE);
305*288bf522SAndroid Build Coastguard Worker 		}
306*288bf522SAndroid Build Coastguard Worker 	}
307*288bf522SAndroid Build Coastguard Worker 
308*288bf522SAndroid Build Coastguard Worker 	list = get_slabinfo (&stats);
309*288bf522SAndroid Build Coastguard Worker 	if (!list)
310*288bf522SAndroid Build Coastguard Worker 		exit(EXIT_FAILURE);
311*288bf522SAndroid Build Coastguard Worker 
312*288bf522SAndroid Build Coastguard Worker 	printf(" Active / Total Objects (%% used) : %lu / %lu (%.1f%%)\n"
313*288bf522SAndroid Build Coastguard Worker 	       " Active / Total Slabs (%% used)   : %lu / %lu (%.1f%%)\n"
314*288bf522SAndroid Build Coastguard Worker 	       " Active / Total Caches (%% used)  : %lu / %lu (%.1f%%)\n"
315*288bf522SAndroid Build Coastguard Worker 	       " Active / Total Size (%% used)    : %.2fK / %.2fK (%.1f%%)\n"
316*288bf522SAndroid Build Coastguard Worker 	       " Min / Avg / Max Object Size     : %.2fK / %.2fK / %.2fK\n\n",
317*288bf522SAndroid Build Coastguard Worker 	       stats.nr_active_objs,
318*288bf522SAndroid Build Coastguard Worker 	       stats.nr_objs,
319*288bf522SAndroid Build Coastguard Worker 	       100.0 * stats.nr_active_objs / stats.nr_objs,
320*288bf522SAndroid Build Coastguard Worker 	       stats.nr_active_slabs,
321*288bf522SAndroid Build Coastguard Worker 	       stats.nr_slabs,
322*288bf522SAndroid Build Coastguard Worker 	       100.0 * stats.nr_active_slabs / stats.nr_slabs,
323*288bf522SAndroid Build Coastguard Worker 	       stats.nr_active_caches,
324*288bf522SAndroid Build Coastguard Worker 	       stats.nr_caches,
325*288bf522SAndroid Build Coastguard Worker 	       100.0 * stats.nr_active_caches / stats.nr_caches,
326*288bf522SAndroid Build Coastguard Worker 	       stats.active_size / 1024.0,
327*288bf522SAndroid Build Coastguard Worker 	       stats.total_size / 1024.0,
328*288bf522SAndroid Build Coastguard Worker 	       100.0 * stats.active_size / stats.total_size,
329*288bf522SAndroid Build Coastguard Worker 	       stats.min_obj_size / 1024.0,
330*288bf522SAndroid Build Coastguard Worker 	       stats.avg_obj_size / 1024.0,
331*288bf522SAndroid Build Coastguard Worker 	       stats.max_obj_size / 1024.0);
332*288bf522SAndroid Build Coastguard Worker 
333*288bf522SAndroid Build Coastguard Worker 	printf("%6s %6s %4s %8s %6s %8s %10s %-23s\n",
334*288bf522SAndroid Build Coastguard Worker 	       "OBJS", "ACTIVE", "USE", "OBJ SIZE", "SLABS",
335*288bf522SAndroid Build Coastguard Worker 	       "OBJ/SLAB", "CACHE SIZE", "NAME");
336*288bf522SAndroid Build Coastguard Worker 
337*288bf522SAndroid Build Coastguard Worker 	p = list = slabsort(list);
338*288bf522SAndroid Build Coastguard Worker 	for (i = 0; i < nr_rows && p; i++) {
339*288bf522SAndroid Build Coastguard Worker 		printf("%6lu %6lu %3lu%% %7.2fK %6lu %8lu %9luK %-23s\n",
340*288bf522SAndroid Build Coastguard Worker 		       p->nr_objs, p->nr_active_objs, p->use,
341*288bf522SAndroid Build Coastguard Worker 		       p->obj_size / 1024.0, p->nr_slabs,
342*288bf522SAndroid Build Coastguard Worker 		       p->objs_per_slab,
343*288bf522SAndroid Build Coastguard Worker 		       p->nr_pages * page_size,
344*288bf522SAndroid Build Coastguard Worker 		       p->name);
345*288bf522SAndroid Build Coastguard Worker 		p = p->next;
346*288bf522SAndroid Build Coastguard Worker 	}
347*288bf522SAndroid Build Coastguard Worker 
348*288bf522SAndroid Build Coastguard Worker 	free_slablist(list);
349*288bf522SAndroid Build Coastguard Worker 
350*288bf522SAndroid Build Coastguard Worker 	return 0;
351*288bf522SAndroid Build Coastguard Worker }
352