]>
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>
48 #define streql(a, b) (strcmp((a), (b)) == 0)
49 #define strneql(a, b, n) (strncmp((a), (b), (n)) == 0)
51 static void printzone();
52 static void colprintzone();
53 static void colprintzoneheader();
56 static boolean_t
substr();
60 static boolean_t ShowWasted
= FALSE
;
61 static boolean_t SortZones
= FALSE
;
62 static boolean_t ColFormat
= TRUE
;
63 static boolean_t PrintHeader
= TRUE
;
65 static unsigned int totalsize
= 0;
66 static unsigned int totalused
= 0;
71 fprintf(stderr
, "usage: %s [-w] [-s] [-c] [-h] [name]\n", program
);
80 zone_name_t name_buf
[1024];
81 zone_name_t
*name
= name_buf
;
82 unsigned int nameCnt
= sizeof name_buf
/sizeof name_buf
[0];
83 zone_info_t info_buf
[1024];
84 zone_info_t
*info
= info_buf
;
85 unsigned int infoCnt
= sizeof info_buf
/sizeof info_buf
[0];
93 program
= strrchr(argv
[0], '/');
99 for (i
= 1; i
< argc
; i
++) {
100 if (streql(argv
[i
], "-w"))
102 else if (streql(argv
[i
], "-W"))
104 else if (streql(argv
[i
], "-s"))
106 else if (streql(argv
[i
], "-S"))
108 else if (streql(argv
[i
], "-c"))
110 else if (streql(argv
[i
], "-C"))
112 else if (streql(argv
[i
], "-H"))
114 else if (streql(argv
[i
], "--")) {
117 } else if (argv
[i
][0] == '-')
131 znamelen
= strlen(zname
);
138 kr
= host_zone_info(mach_host_self(),
139 &name
, &nameCnt
, &info
, &infoCnt
);
140 if (kr
!= KERN_SUCCESS
) {
141 fprintf(stderr
, "%s: host_zone_info: %s\n",
142 program
, mach_error_string(kr
));
145 else if (nameCnt
!= infoCnt
) {
146 fprintf(stderr
, "%s: host_zone_info: counts not equal?\n",
152 for (i
= 0; i
< nameCnt
-1; i
++)
153 for (j
= i
+1; j
< nameCnt
; j
++) {
156 wastei
= (info
[i
].zi_cur_size
-
157 (info
[i
].zi_elem_size
*
159 wastej
= (info
[j
].zi_cur_size
-
160 (info
[j
].zi_elem_size
*
163 if (wastej
> wastei
) {
179 colprintzoneheader();
181 for (i
= 0; i
< nameCnt
; i
++)
182 if (substr(zname
, znamelen
, name
[i
].zn_name
,
183 strnlen(name
[i
].zn_name
, sizeof name
[i
].zn_name
)))
185 colprintzone(&name
[i
], &info
[i
]);
187 printzone(&name
[i
], &info
[i
]);
189 if ((name
!= name_buf
) && (nameCnt
!= 0)) {
190 kr
= vm_deallocate(mach_task_self(), (vm_address_t
) name
,
191 (vm_size_t
) (nameCnt
* sizeof *name
));
192 if (kr
!= KERN_SUCCESS
) {
193 fprintf(stderr
, "%s: vm_deallocate: %s\n",
194 program
, mach_error_string(kr
));
199 if ((info
!= info_buf
) && (infoCnt
!= 0)) {
200 kr
= vm_deallocate(mach_task_self(), (vm_address_t
) info
,
201 (vm_size_t
) (infoCnt
* sizeof *info
));
202 if (kr
!= KERN_SUCCESS
) {
203 fprintf(stderr
, "%s: vm_deallocate: %s\n",
204 program
, mach_error_string(kr
));
209 if (ShowWasted
&& PrintHeader
) {
210 printf("TOTAL SIZE = %u\n", totalsize
);
211 printf("TOTAL USED = %u\n", totalused
);
212 printf("TOTAL WASTED = %d\n", totalsize
- totalused
);
225 while ((len
< n
) && (*s
++ != '\0'))
232 substr(a
, alen
, b
, blen
)
240 for (i
= 0; i
<= blen
- alen
; i
++)
241 if (strneql(a
, b
+i
, alen
))
248 printzone(name
, info
)
252 unsigned int used
, size
;
254 printf("%.*s zone:\n", (int)sizeof name
->zn_name
, name
->zn_name
);
255 printf("\tcur_size: %dK bytes (%d elements)\n",
256 info
->zi_cur_size
/1024,
257 info
->zi_cur_size
/info
->zi_elem_size
);
258 printf("\tmax_size: %dK bytes (%d elements)\n",
259 info
->zi_max_size
/1024,
260 info
->zi_max_size
/info
->zi_elem_size
);
261 printf("\telem_size: %d bytes\n",
263 printf("\t# of elems: %d\n",
265 printf("\talloc_size: %dK bytes (%d elements)\n",
266 info
->zi_alloc_size
/1024,
267 info
->zi_alloc_size
/info
->zi_elem_size
);
268 if (info
->zi_pageable
)
269 printf("\tPAGEABLE\n");
270 if (info
->zi_collectable
)
271 printf("\tCOLLECTABLE\n");
274 totalused
+= used
= info
->zi_elem_size
* info
->zi_count
;
275 totalsize
+= size
= info
->zi_cur_size
;
276 printf("\t\t\t\t\tWASTED: %d\n", size
- used
);
285 printf(fmt
, i
/ 1024);
290 colprintzone(zone_name
, info
)
291 zone_name_t
*zone_name
;
294 char *name
= zone_name
->zn_name
;
296 unsigned int used
, size
;
302 for (j
= 0; j
< namewidth
- 1 && name
[j
]; j
++) {
303 if (name
[j
] == ' ') {
309 if (j
== namewidth
- 1) {
316 for (; j
< namewidth
; j
++) {
320 printf("%5d", info
->zi_elem_size
);
321 printk("%6d", info
->zi_cur_size
);
322 if (info
->zi_max_size
>= 99999 * 1024) {
325 printk("%6d", info
->zi_max_size
);
327 printf("%7d", info
->zi_cur_size
/ info
->zi_elem_size
);
328 if (info
->zi_max_size
>= 99999 * 1024) {
331 printf("%7d", info
->zi_max_size
/ info
->zi_elem_size
);
333 printf("%6d", info
->zi_count
);
334 printk("%5d", info
->zi_alloc_size
);
335 printf("%6d", info
->zi_alloc_size
/ info
->zi_elem_size
);
337 totalused
+= used
= info
->zi_elem_size
* info
->zi_count
;
338 totalsize
+= size
= info
->zi_cur_size
;
340 printf("%7d", size
- used
);
344 (info
->zi_pageable
? 'P' : ' '),
345 (info
->zi_collectable
? 'C' : ' '));
355 printf(" elem cur max cur max%s",
356 " cur alloc alloc\n");
357 printf("zone name size size size #elts #elts%s",
358 " inuse size count wasted\n");
360 printf(" elem cur max cur%s",
361 " max cur alloc alloc\n");
362 printf("zone name size size size #elts%s",
363 " #elts inuse size count\n");
365 printf("-----------------------------------------------%s",
366 "--------------------------------\n");