]>
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.
43 #include <mach/mach.h>
44 #include <mach_debug/mach_debug.h>
45 #include <mach/mach_error.h>
47 #define streql(a, b) (strcmp((a), (b)) == 0)
48 #define strneql(a, b, n) (strncmp((a), (b), (n)) == 0)
50 static void printzone();
51 static void colprintzone();
52 static void colprintzoneheader();
55 static boolean_t
substr();
59 static boolean_t ShowWasted
= FALSE
;
60 static boolean_t SortZones
= FALSE
;
61 static boolean_t ColFormat
= TRUE
;
62 static boolean_t PrintHeader
= TRUE
;
64 static unsigned int totalsize
= 0;
65 static unsigned int totalused
= 0;
70 fprintf(stderr
, "usage: %s [-w] [-s] [-c] [-h] [name]\n", program
);
78 zone_name_t name_buf
[1024];
79 zone_name_t
*name
= name_buf
;
80 unsigned int nameCnt
= sizeof name_buf
/sizeof name_buf
[0];
81 zone_info_t info_buf
[1024];
82 zone_info_t
*info
= info_buf
;
83 unsigned int infoCnt
= sizeof info_buf
/sizeof info_buf
[0];
91 program
= strrchr(argv
[0], '/');
97 for (i
= 1; i
< argc
; i
++) {
98 if (streql(argv
[i
], "-w"))
100 else if (streql(argv
[i
], "-W"))
102 else if (streql(argv
[i
], "-s"))
104 else if (streql(argv
[i
], "-S"))
106 else if (streql(argv
[i
], "-c"))
108 else if (streql(argv
[i
], "-C"))
110 else if (streql(argv
[i
], "-H"))
112 else if (streql(argv
[i
], "--")) {
115 } else if (argv
[i
][0] == '-')
129 znamelen
= strlen(zname
);
136 kr
= host_zone_info(mach_host_self(),
137 &name
, &nameCnt
, &info
, &infoCnt
);
138 if (kr
!= KERN_SUCCESS
) {
139 fprintf(stderr
, "%s: host_zone_info: %s\n",
140 program
, mach_error_string(kr
));
143 else if (nameCnt
!= infoCnt
) {
144 fprintf(stderr
, "%s: host_zone_info: counts not equal?\n",
150 for (i
= 0; i
< nameCnt
-1; i
++)
151 for (j
= i
+1; j
< nameCnt
; j
++) {
154 wastei
= (info
[i
].zi_cur_size
-
155 (info
[i
].zi_elem_size
*
157 wastej
= (info
[j
].zi_cur_size
-
158 (info
[j
].zi_elem_size
*
161 if (wastej
> wastei
) {
177 colprintzoneheader();
179 for (i
= 0; i
< nameCnt
; i
++)
180 if (substr(zname
, znamelen
, name
[i
].zn_name
,
181 strnlen(name
[i
].zn_name
, sizeof name
[i
].zn_name
)))
183 colprintzone(&name
[i
], &info
[i
]);
185 printzone(&name
[i
], &info
[i
]);
187 if ((name
!= name_buf
) && (nameCnt
!= 0)) {
188 kr
= vm_deallocate(mach_task_self(), (vm_address_t
) name
,
189 (vm_size_t
) (nameCnt
* sizeof *name
));
190 if (kr
!= KERN_SUCCESS
) {
191 fprintf(stderr
, "%s: vm_deallocate: %s\n",
192 program
, mach_error_string(kr
));
197 if ((info
!= info_buf
) && (infoCnt
!= 0)) {
198 kr
= vm_deallocate(mach_task_self(), (vm_address_t
) info
,
199 (vm_size_t
) (infoCnt
* sizeof *info
));
200 if (kr
!= KERN_SUCCESS
) {
201 fprintf(stderr
, "%s: vm_deallocate: %s\n",
202 program
, mach_error_string(kr
));
207 if (ShowWasted
&& PrintHeader
) {
208 printf("TOTAL SIZE = %u\n", totalsize
);
209 printf("TOTAL USED = %u\n", totalused
);
210 printf("TOTAL WASTED = %d\n", totalsize
- totalused
);
223 while ((len
< n
) && (*s
++ != '\0'))
230 substr(a
, alen
, b
, blen
)
238 for (i
= 0; i
<= blen
- alen
; i
++)
239 if (strneql(a
, b
+i
, alen
))
246 printzone(name
, info
)
250 unsigned int used
, size
;
252 printf("%.*s zone:\n", sizeof name
->zn_name
, name
->zn_name
);
253 printf("\tcur_size: %dK bytes (%d elements)\n",
254 info
->zi_cur_size
/1024,
255 info
->zi_cur_size
/info
->zi_elem_size
);
256 printf("\tmax_size: %dK bytes (%d elements)\n",
257 info
->zi_max_size
/1024,
258 info
->zi_max_size
/info
->zi_elem_size
);
259 printf("\telem_size: %d bytes\n",
261 printf("\t# of elems: %d\n",
263 printf("\talloc_size: %dK bytes (%d elements)\n",
264 info
->zi_alloc_size
/1024,
265 info
->zi_alloc_size
/info
->zi_elem_size
);
266 if (info
->zi_pageable
)
267 printf("\tPAGEABLE\n");
268 if (info
->zi_collectable
)
269 printf("\tCOLLECTABLE\n");
272 totalused
+= used
= info
->zi_elem_size
* info
->zi_count
;
273 totalsize
+= size
= info
->zi_cur_size
;
274 printf("\t\t\t\t\tWASTED: %d\n", size
- used
);
283 printf(fmt
, i
/ 1024);
288 colprintzone(zone_name
, info
)
289 zone_name_t
*zone_name
;
292 char *name
= zone_name
->zn_name
;
293 int j
, namewidth
, retval
;
294 unsigned int used
, size
;
300 for (j
= 0; j
< namewidth
- 1 && name
[j
]; j
++) {
301 if (name
[j
] == ' ') {
307 if (j
== namewidth
- 1) {
314 for (; j
< namewidth
; j
++) {
318 printf("%5d", info
->zi_elem_size
);
319 printk("%6d", info
->zi_cur_size
);
320 if (info
->zi_max_size
>= 99999 * 1024) {
323 printk("%6d", info
->zi_max_size
);
325 printf("%7d", info
->zi_cur_size
/ info
->zi_elem_size
);
326 if (info
->zi_max_size
>= 99999 * 1024) {
329 printf("%7d", info
->zi_max_size
/ info
->zi_elem_size
);
331 printf("%6d", info
->zi_count
);
332 printk("%5d", info
->zi_alloc_size
);
333 printf("%6d", info
->zi_alloc_size
/ info
->zi_elem_size
);
335 totalused
+= used
= info
->zi_elem_size
* info
->zi_count
;
336 totalsize
+= size
= info
->zi_cur_size
;
338 printf("%7d", size
- used
);
342 (info
->zi_pageable
? 'P' : ' '),
343 (info
->zi_collectable
? 'C' : ' '));
353 printf(" elem cur max cur max%s",
354 " cur alloc alloc\n");
355 printf("zone name size size size #elts #elts%s",
356 " inuse size count wasted\n");
358 printf(" elem cur max cur%s",
359 " max cur alloc alloc\n");
360 printf("zone name size size size #elts%s",
361 " #elts inuse size count\n");
363 printf("-----------------------------------------------%s",
364 "--------------------------------\n");