#import "ITVirtualMemoryInfo.h"
+#import "ITDebug.h"
+#import <unistd.h>
@interface ITVirtualMemoryInfo (Private)
- (BOOL)refreshStats:(struct vm_statistics *)myStat;
@implementation ITVirtualMemoryInfo
-- (id)init
-{
- if ( ( self = [super init] ) ) {
- if ([self refreshStats:&stat] == NO) {
- return nil;
- }
- }
- return self;
+- (id)init {
+ if ( ( self = [super init] ) ) {
+ if ([self refreshStats:&stat] == NO) {
+ self = nil;
+ }
+ }
+ return self;
}
-- (int)pageSize
-{
- int pageSize = 0;
-
- if ( host_page_size(mach_host_self(), &pageSize) != KERN_SUCCESS ) {
- NSLog(@"Failed to get page size, defaulting to 4096/4k");
- pageSize = DEFAULT_PAGE_SIZE;
- }
-
- return pageSize;
+- (int)pageSize {
+ return getpagesize();
}
-- (int)freePages
-{
- [self refreshStats:&stat];
- return stat.free_count;
+- (int)freePages {
+ [self refreshStats:&stat];
+ return stat.free_count;
}
-- (int)activePages
-{
- [self refreshStats:&stat];
- return stat.active_count;
+- (int)activePages {
+ [self refreshStats:&stat];
+ return stat.active_count;
}
-- (int)inactivePages
-{
- [self refreshStats:&stat];
- return stat.inactive_count;
+- (int)inactivePages {
+ [self refreshStats:&stat];
+ return stat.inactive_count;
}
-- (int)wiredPages
-{
- [self refreshStats:&stat];
- return stat.wire_count;
+- (int)wiredPages {
+ [self refreshStats:&stat];
+ return stat.wire_count;
}
-- (int)faults
-{
- [self refreshStats:&stat];
- return stat.faults;
+- (int)faults {
+ [self refreshStats:&stat];
+ return stat.faults;
}
-- (int)copyOnWritePages
-{
- [self refreshStats:&stat];
- return stat.cow_faults;
+- (int)copyOnWritePages {
+ [self refreshStats:&stat];
+ return stat.cow_faults;
}
-- (int)zeroFilledPages
-{
- [self refreshStats:&stat];
- return stat.zero_fill_count;
+- (int)zeroFilledPages {
+ [self refreshStats:&stat];
+ return stat.zero_fill_count;
}
-- (int)reactivatedPages
-{
- [self refreshStats:&stat];
- return stat.reactivations;
+- (int)reactivatedPages {
+ [self refreshStats:&stat];
+ return stat.reactivations;
}
-- (int)pageins
-{
- [self refreshStats:&stat];
- return stat.pageins;
+- (int)pageins {
+ [self refreshStats:&stat];
+ return stat.pageins;
}
-- (int)pageouts
-{
- [self refreshStats:&stat];
- return stat.pageouts;
+- (int)pageouts {
+ [self refreshStats:&stat];
+ return stat.pageouts;
}
-- (int)hits
-{
- [self refreshStats:&stat];
- return stat.hits;
+- (int)hits {
+ [self refreshStats:&stat];
+ return stat.hits;
}
-- (int)lookups
-{
- [self refreshStats:&stat];
- return stat.lookups;
+- (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 );
- }
+- (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;
- NSLog(@"%i",count);
- int returned = host_statistics(myHost, HOST_VM_INFO, myStat, &count);
- if ( returned != KERN_SUCCESS ) {
- NSLog(@"Failed to get Statistics in -refreshStats method of ITVirtualMemoryInfo");
- NSLog(@"%s",strerror(returned));
- return NO;
- } else {
- return YES;
- }
+- (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
+@end
\ No newline at end of file