1 #import "ITVirtualMemoryInfo.h"
3 @interface ITVirtualMemoryInfo (Private)
4 - (BOOL)refreshStats:(struct vm_statistics *)myStat;
7 @implementation ITVirtualMemoryInfo
11 if ( ( self = [super init] ) ) {
12 if ([self refreshStats:&stat] == NO) {
23 if ( host_page_size(mach_host_self(), &pageSize) != KERN_SUCCESS ) {
24 NSLog(@"Failed to get page size, defaulting to 4096/4k");
25 pageSize = DEFAULT_PAGE_SIZE;
33 [self refreshStats:&stat];
34 return stat.free_count;
39 [self refreshStats:&stat];
40 return stat.active_count;
45 [self refreshStats:&stat];
46 return stat.inactive_count;
51 [self refreshStats:&stat];
52 return stat.wire_count;
57 [self refreshStats:&stat];
61 - (int)copyOnWritePages
63 [self refreshStats:&stat];
64 return stat.cow_faults;
67 - (int)zeroFilledPages
69 [self refreshStats:&stat];
70 return stat.zero_fill_count;
73 - (int)reactivatedPages
75 [self refreshStats:&stat];
76 return stat.reactivations;
81 [self refreshStats:&stat];
87 [self refreshStats:&stat];
93 [self refreshStats:&stat];
99 [self refreshStats:&stat];
103 - (int)hitratePercentage
105 [self refreshStats:&stat];
106 if ( stat.lookups == 0 ) {
109 return ( ( stat.hits * 100 ) / stat.lookups );
113 - (BOOL)refreshStats:(struct vm_statistics *)myStat
115 bzero(&myStat,sizeof(myStat));
116 mach_port_t myHost = mach_host_self();
117 int count = HOST_VM_INFO_COUNT;
119 int returned = host_statistics(myHost, HOST_VM_INFO, myStat, &count);
120 if ( returned != KERN_SUCCESS ) {
121 NSLog(@"Failed to get Statistics in -refreshStats method of ITVirtualMemoryInfo");
122 NSLog(@"%s",strerror(returned));