1 #import "ITVirtualMemoryInfo.h"
4 @interface ITVirtualMemoryInfo (Private)
5 - (BOOL)refreshStats:(struct vm_statistics *)myStat;
8 @implementation ITVirtualMemoryInfo
12 if ( ( self = [super init] ) ) {
13 if ([self refreshStats:&stat] == NO) {
27 [self refreshStats:&stat];
28 return stat.free_count;
33 [self refreshStats:&stat];
34 return stat.active_count;
39 [self refreshStats:&stat];
40 return stat.inactive_count;
45 [self refreshStats:&stat];
46 return stat.wire_count;
51 [self refreshStats:&stat];
55 - (int)copyOnWritePages
57 [self refreshStats:&stat];
58 return stat.cow_faults;
61 - (int)zeroFilledPages
63 [self refreshStats:&stat];
64 return stat.zero_fill_count;
67 - (int)reactivatedPages
69 [self refreshStats:&stat];
70 return stat.reactivations;
75 [self refreshStats:&stat];
81 [self refreshStats:&stat];
87 [self refreshStats:&stat];
93 [self refreshStats:&stat];
97 - (int)hitratePercentage
99 [self refreshStats:&stat];
100 if ( stat.lookups == 0 ) {
103 return ( ( stat.hits * 100 ) / stat.lookups );
107 - (BOOL)refreshStats:(struct vm_statistics *)myStat
109 bzero(&myStat,sizeof(myStat));
110 mach_port_t myHost = mach_host_self();
111 int count = HOST_VM_INFO_COUNT;
113 int returned = host_statistics(myHost, HOST_VM_INFO, myStat, &count);
114 if ( returned != KERN_SUCCESS ) {
115 NSLog(@"Failed to get Statistics in -refreshStats method of ITVirtualMemoryInfo");
116 NSLog(@"%s",strerror(returned));