2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Author: Avadis Tevanian, Jr.
29 * Copyright (C) 1986, Avadis Tevanian, Jr.
32 * Display Mach VM statistics.
34 ************************************************************************
36 * 6-Jun-86 Avadis Tevanian, Jr. (avie) at Carnegie-Mellon University
37 * Use official Mach interface.
39 * 25-mar-99 A.Ramesh at Apple
41 ************************************************************************
49 #include <mach/mach.h>
51 vm_statistics_data_t vm_stat
, last
;
56 int pageSize
= 4096; /* set to 4k default */
61 void pstat(char *str
, natural_t n
);
62 void print_stats(void);
63 void get_stats(struct vm_statistics
*stat
);
66 main(int argc
, char *argv
[])
76 if (sscanf(argv
[1], "%d", &delay
) != 1)
82 myHost
= mach_host_self();
84 if(host_page_size(mach_host_self(), &pageSize
) != KERN_SUCCESS
) {
85 fprintf(stderr
, "%s: failed to get pagesize; defaulting to 4K.\n", pgmname
);
104 fprintf(stderr
, "usage: %s [ repeat-interval ]\n", pgmname
);
112 printf("Mach Virtual Memory Statistics: ");
113 printf("(page size of %d bytes, cache hits %u%%)\n",
115 printf("%6s %6s %4s %4s %8s %8s %8s %8s %8s %8s\n",
126 bzero(&last
, sizeof(last
));
134 printf("Mach Virtual Memory Statistics: (page size of %d bytes)\n",
137 pstat("Pages free:", vm_stat
.free_count
);
138 pstat("Pages active:", vm_stat
.active_count
);
139 pstat("Pages inactive:", vm_stat
.inactive_count
);
140 pstat("Pages wired down:", vm_stat
.wire_count
);
141 pstat("\"Translation faults\":", vm_stat
.faults
);
142 pstat("Pages copy-on-write:", vm_stat
.cow_faults
);
143 pstat("Pages zero filled:", vm_stat
.zero_fill_count
);
144 pstat("Pages reactivated:", vm_stat
.reactivations
);
145 pstat("Pageins:", vm_stat
.pageins
);
146 pstat("Pageouts:", vm_stat
.pageouts
);
147 printf("Object cache: %u hits of %u lookups (%u%% hit rate)\n",
148 vm_stat
.hits
, vm_stat
.lookups
, percent
);
152 pstat(char *str
, natural_t n
)
154 printf("%-25s %10u.\n", str
, n
);
160 static int count
= 0;
169 printf("%6u %6u %4u %4u %8u %8u %8u %8u %8u %8u\n",
171 vm_stat
.active_count
,
172 vm_stat
.inactive_count
,
174 vm_stat
.faults
- last
.faults
,
175 vm_stat
.cow_faults
- last
.cow_faults
,
176 vm_stat
.zero_fill_count
- last
.zero_fill_count
,
177 vm_stat
.reactivations
- last
.reactivations
,
178 vm_stat
.pageins
- last
.pageins
,
179 vm_stat
.pageouts
- last
.pageouts
);
184 get_stats(struct vm_statistics
*stat
)
186 int count
= HOST_VM_INFO_COUNT
;
187 if (host_statistics(myHost
, HOST_VM_INFO
, (host_info_t
)stat
, &count
) != KERN_SUCCESS
) {
188 fprintf(stderr
, "%s: failed to get statistics.\n", pgmname
);
191 if (stat
->lookups
== 0)
195 * We have limited precision with the 32-bit natural_t fields
196 * in the vm_statistics structure. There's nothing we can do
197 * about counter overflows, but we can avoid percentage
198 * calculation overflows by doing the computation in floating
199 * point arithmetic ...
201 percent
= (natural_t
)(((double)stat
->hits
*100)/stat
->lookups
);