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 ************************************************************************
47 #include <mach/mach.h>
49 vm_statistics_data_t vm_stat
, last
;
54 int pageSize
= 4096; /* set to 4k default */
59 void pstat(char *str
, int n
);
61 void get_stats(struct vm_statistics
*stat
);
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 %d%%)\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: %d hits of %d lookups (%d%% hit rate)\n",
148 vm_stat
.hits
, vm_stat
.lookups
, percent
);
156 printf("%-25s %10d.\n", str
, n
);
171 printf("%6d %6d %4d %4d %8d %8d %8d %8d %8d %8d\n",
173 vm_stat
.active_count
,
174 vm_stat
.inactive_count
,
176 vm_stat
.faults
- last
.faults
,
177 vm_stat
.cow_faults
- last
.cow_faults
,
178 vm_stat
.zero_fill_count
- last
.zero_fill_count
,
179 vm_stat
.reactivations
- last
.reactivations
,
180 vm_stat
.pageins
- last
.pageins
,
181 vm_stat
.pageouts
- last
.pageouts
);
187 struct vm_statistics
*stat
;
189 int count
= HOST_VM_INFO_COUNT
;
190 if (host_statistics(myHost
, HOST_VM_INFO
, stat
,&count
) != KERN_SUCCESS
) {
191 fprintf(stderr
, "%s: failed to get statistics.\n", pgmname
);
194 if (stat
->lookups
== 0)
197 percent
= (stat
->hits
*100)/stat
->lookups
;