-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITVirtualMemoryInfo.m
108 lines (89 loc) · 1.87 KB
/
ITVirtualMemoryInfo.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#import "ITVirtualMemoryInfo.h"
#import "ITDebug.h"
#import <unistd.h>
@interface ITVirtualMemoryInfo (Private)
- (BOOL)refreshStats:(struct vm_statistics *)myStat;
@end
@implementation ITVirtualMemoryInfo
- (id)init {
if ( ( self = [super init] ) ) {
if ([self refreshStats:&stat] == NO) {
self = nil;
}
}
return self;
}
- (int)pageSize {
return getpagesize();
}
- (int)freePages {
[self refreshStats:&stat];
return stat.free_count;
}
- (int)activePages {
[self refreshStats:&stat];
return stat.active_count;
}
- (int)inactivePages {
[self refreshStats:&stat];
return stat.inactive_count;
}
- (int)wiredPages {
[self refreshStats:&stat];
return stat.wire_count;
}
- (int)faults {
[self refreshStats:&stat];
return stat.faults;
}
- (int)copyOnWritePages {
[self refreshStats:&stat];
return stat.cow_faults;
}
- (int)zeroFilledPages {
[self refreshStats:&stat];
return stat.zero_fill_count;
}
- (int)reactivatedPages {
[self refreshStats:&stat];
return stat.reactivations;
}
- (int)pageins {
[self refreshStats:&stat];
return stat.pageins;
}
- (int)pageouts {
[self refreshStats:&stat];
return stat.pageouts;
}
- (int)hits {
[self refreshStats:&stat];
return stat.hits;
}
- (int)lookups {
[self refreshStats:&stat];
return stat.lookups;
}
- (int)hitratePercentage {
[self refreshStats:&stat];
if ( stat.lookups == 0 ) {
return 0;
} else {
return ( ( stat.hits * 100 ) / stat.lookups );
}
}
- (BOOL)refreshStats:(struct vm_statistics *)myStat {
bzero(myStat,sizeof(myStat));
mach_port_t myHost = mach_host_self();
int count = HOST_VM_INFO_COUNT;
ITDebugLog(@"%i",count);
int returned = host_statistics(myHost, HOST_VM_INFO, myStat, &count);
if ( returned != KERN_SUCCESS ) {
ITDebugLog(@"Failed to get Statistics in -refreshStats method of ITVirtualMemoryInfo");
ITDebugLog(@"%s",strerror(returned));
return NO;
} else {
return YES;
}
}
@end