]>
git.saurik.com Git - apple/system_cmds.git/blob - zprint.tproj/zprint.c
5 * Mach Operating System
6 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
32 * utility for printing out zone structures
34 * With no arguments, prints information on all zone structures.
35 * With an argument, prints information only on those zones for
36 * which the given name is a substring of the zone's name.
37 * With a "-w" flag, calculates how much much space is allocated
38 * to zones but not currently in use.
44 #include <mach/mach.h>
45 #include <mach_debug/mach_debug.h>
46 #include <mach/mach_error.h>
50 #define streql(a, b) (strcmp((a), (b)) == 0)
51 #define strneql(a, b, n) (strncmp((a), (b), (n)) == 0)
53 static void printzone();
54 static void colprintzone();
55 static void colprintzoneheader();
58 static boolean_t
substr();
62 static boolean_t ShowWasted
= FALSE
;
63 static boolean_t SortZones
= FALSE
;
64 static boolean_t ColFormat
= TRUE
;
65 static boolean_t PrintHeader
= TRUE
;
67 static unsigned int totalsize
= 0;
68 static unsigned int totalused
= 0;
73 fprintf(stderr
, "usage: %s [-w] [-s] [-c] [-h] [name]\n", program
);
82 zone_name_t name_buf
[1024];
83 zone_name_t
*name
= name_buf
;
84 unsigned int nameCnt
= sizeof name_buf
/sizeof name_buf
[0];
85 zone_info_t info_buf
[1024];
86 zone_info_t
*info
= info_buf
;
87 unsigned int infoCnt
= sizeof info_buf
/sizeof info_buf
[0];
95 if (0 != reexec_to_match_kernel()) {
96 fprintf(stderr
, "Could not re-execute: %d\n", errno
);
100 program
= strrchr(argv
[0], '/');
106 for (i
= 1; i
< argc
; i
++) {
107 if (streql(argv
[i
], "-w"))
109 else if (streql(argv
[i
], "-W"))
111 else if (streql(argv
[i
], "-s"))
113 else if (streql(argv
[i
], "-S"))
115 else if (streql(argv
[i
], "-c"))
117 else if (streql(argv
[i
], "-C"))
119 else if (streql(argv
[i
], "-H"))
121 else if (streql(argv
[i
], "--")) {
124 } else if (argv
[i
][0] == '-')
138 znamelen
= strlen(zname
);
145 kr
= host_zone_info(mach_host_self(),
146 &name
, &nameCnt
, &info
, &infoCnt
);
147 if (kr
!= KERN_SUCCESS
) {
148 fprintf(stderr
, "%s: host_zone_info: %s\n",
149 program
, mach_error_string(kr
));
152 else if (nameCnt
!= infoCnt
) {
153 fprintf(stderr
, "%s: host_zone_info: counts not equal?\n",
159 for (i
= 0; i
< nameCnt
-1; i
++)
160 for (j
= i
+1; j
< nameCnt
; j
++) {
163 wastei
= (info
[i
].zi_cur_size
-
164 (info
[i
].zi_elem_size
*
166 wastej
= (info
[j
].zi_cur_size
-
167 (info
[j
].zi_elem_size
*
170 if (wastej
> wastei
) {
186 colprintzoneheader();
188 for (i
= 0; i
< nameCnt
; i
++)
189 if (substr(zname
, znamelen
, name
[i
].zn_name
,
190 strnlen(name
[i
].zn_name
, sizeof name
[i
].zn_name
)))
192 colprintzone(&name
[i
], &info
[i
]);
194 printzone(&name
[i
], &info
[i
]);
196 if ((name
!= name_buf
) && (nameCnt
!= 0)) {
197 kr
= vm_deallocate(mach_task_self(), (vm_address_t
) name
,
198 (vm_size_t
) (nameCnt
* sizeof *name
));
199 if (kr
!= KERN_SUCCESS
) {
200 fprintf(stderr
, "%s: vm_deallocate: %s\n",
201 program
, mach_error_string(kr
));
206 if ((info
!= info_buf
) && (infoCnt
!= 0)) {
207 kr
= vm_deallocate(mach_task_self(), (vm_address_t
) info
,
208 (vm_size_t
) (infoCnt
* sizeof *info
));
209 if (kr
!= KERN_SUCCESS
) {
210 fprintf(stderr
, "%s: vm_deallocate: %s\n",
211 program
, mach_error_string(kr
));
216 if (ShowWasted
&& PrintHeader
) {
217 printf("TOTAL SIZE = %u\n", totalsize
);
218 printf("TOTAL USED = %u\n", totalused
);
219 printf("TOTAL WASTED = %d\n", totalsize
- totalused
);
232 while ((len
< n
) && (*s
++ != '\0'))
239 substr(a
, alen
, b
, blen
)
247 for (i
= 0; i
<= blen
- alen
; i
++)
248 if (strneql(a
, b
+i
, alen
))
255 printzone(name
, info
)
259 unsigned int used
, size
;
261 printf("%.*s zone:\n", (int)sizeof name
->zn_name
, name
->zn_name
);
262 printf("\tcur_size: %dK bytes (%d elements)\n",
263 info
->zi_cur_size
/1024,
264 info
->zi_cur_size
/info
->zi_elem_size
);
265 printf("\tmax_size: %dK bytes (%d elements)\n",
266 info
->zi_max_size
/1024,
267 info
->zi_max_size
/info
->zi_elem_size
);
268 printf("\telem_size: %d bytes\n",
270 printf("\t# of elems: %d\n",
272 printf("\talloc_size: %dK bytes (%d elements)\n",
273 info
->zi_alloc_size
/1024,
274 info
->zi_alloc_size
/info
->zi_elem_size
);
275 if (info
->zi_pageable
)
276 printf("\tPAGEABLE\n");
277 if (info
->zi_collectable
)
278 printf("\tCOLLECTABLE\n");
281 totalused
+= used
= info
->zi_elem_size
* info
->zi_count
;
282 totalsize
+= size
= info
->zi_cur_size
;
283 printf("\t\t\t\t\tWASTED: %d\n", size
- used
);
292 printf(fmt
, i
/ 1024);
297 colprintzone(zone_name
, info
)
298 zone_name_t
*zone_name
;
301 char *name
= zone_name
->zn_name
;
303 unsigned int used
, size
;
309 for (j
= 0; j
< namewidth
- 1 && name
[j
]; j
++) {
310 if (name
[j
] == ' ') {
316 if (j
== namewidth
- 1) {
323 for (; j
< namewidth
; j
++) {
327 printf("%5d", info
->zi_elem_size
);
328 printk("%6d", info
->zi_cur_size
);
329 if (info
->zi_max_size
>= 99999 * 1024) {
332 printk("%6d", info
->zi_max_size
);
334 printf("%7d", info
->zi_cur_size
/ info
->zi_elem_size
);
335 if (info
->zi_max_size
>= 99999 * 1024) {
338 printf("%7d", info
->zi_max_size
/ info
->zi_elem_size
);
340 printf("%6d", info
->zi_count
);
341 printk("%5d", info
->zi_alloc_size
);
342 printf("%6d", info
->zi_alloc_size
/ info
->zi_elem_size
);
344 totalused
+= used
= info
->zi_elem_size
* info
->zi_count
;
345 totalsize
+= size
= info
->zi_cur_size
;
347 printf("%7d", size
- used
);
351 (info
->zi_pageable
? 'P' : ' '),
352 (info
->zi_collectable
? 'C' : ' '));
362 printf(" elem cur max cur max%s",
363 " cur alloc alloc\n");
364 printf("zone name size size size #elts #elts%s",
365 " inuse size count wasted\n");
367 printf(" elem cur max cur%s",
368 " max cur alloc alloc\n");
369 printf("zone name size size size #elts%s",
370 " #elts inuse size count\n");
372 printf("-----------------------------------------------%s",
373 "--------------------------------\n");