2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * Author: Avadis Tevanian, Jr.
28 * Copyright (C) 1986, Avadis Tevanian, Jr.
31 * Display Mach VM statistics.
33 ************************************************************************
35 * 6-Jun-86 Avadis Tevanian, Jr. (avie) at Carnegie-Mellon University
36 * Use official Mach interface.
38 * 25-mar-99 A.Ramesh at Apple
40 ************************************************************************
46 #include <mach/mach.h>
48 vm_statistics_data_t vm_stat
, last
;
53 int pageSize
= 4096; /* set to 4k default */
58 void pstat(char *str
, int n
);
60 void get_stats(struct vm_statistics
*stat
);
75 if (sscanf(argv
[1], "%d", &delay
) != 1)
81 myHost
= mach_host_self();
83 if(host_page_size(mach_host_self(), &pageSize
) != KERN_SUCCESS
) {
84 fprintf(stderr
, "%s: failed to get pagesize; defaulting to 4K.\n", pgmname
);
103 fprintf(stderr
, "usage: %s [ repeat-interval ]\n", pgmname
);
111 printf("Mach Virtual Memory Statistics: ");
112 printf("(page size of %d bytes, cache hits %d%%)\n",
114 printf("%6s %6s %4s %4s %8s %8s %8s %8s %8s %8s\n",
125 bzero(&last
, sizeof(last
));
133 printf("Mach Virtual Memory Statistics: (page size of %d bytes)\n",
136 pstat("Pages free:", vm_stat
.free_count
);
137 pstat("Pages active:", vm_stat
.active_count
);
138 pstat("Pages inactive:", vm_stat
.inactive_count
);
139 pstat("Pages wired down:", vm_stat
.wire_count
);
140 pstat("\"Translation faults\":", vm_stat
.faults
);
141 pstat("Pages copy-on-write:", vm_stat
.cow_faults
);
142 pstat("Pages zero filled:", vm_stat
.zero_fill_count
);
143 pstat("Pages reactivated:", vm_stat
.reactivations
);
144 pstat("Pageins:", vm_stat
.pageins
);
145 pstat("Pageouts:", vm_stat
.pageouts
);
146 printf("Object cache: %d hits of %d lookups (%d%% hit rate)\n",
147 vm_stat
.hits
, vm_stat
.lookups
, percent
);
155 printf("%-25s %10d.\n", str
, n
);
170 printf("%6d %6d %4d %4d %8d %8d %8d %8d %8d %8d\n",
172 vm_stat
.active_count
,
173 vm_stat
.inactive_count
,
175 vm_stat
.faults
- last
.faults
,
176 vm_stat
.cow_faults
- last
.cow_faults
,
177 vm_stat
.zero_fill_count
- last
.zero_fill_count
,
178 vm_stat
.reactivations
- last
.reactivations
,
179 vm_stat
.pageins
- last
.pageins
,
180 vm_stat
.pageouts
- last
.pageouts
);
186 struct vm_statistics
*stat
;
188 int count
= HOST_VM_INFO_COUNT
;
189 if (host_statistics(myHost
, HOST_VM_INFO
, stat
,&count
) != KERN_SUCCESS
) {
190 fprintf(stderr
, "%s: failed to get statistics.\n", pgmname
);
193 if (stat
->lookups
== 0)
196 percent
= (stat
->hits
*100)/stat
->lookups
;