-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileSystem.m
executable file
·145 lines (109 loc) · 3.68 KB
/
FileSystem.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// FileSystem.m
// aBattery
//
// Created by Neel Banerjee on 4/19/09.
// Copyright 2009 Om Design LLC. All rights reserved.
//
#import "FileSystem.h"
#import <sys/sysctl.h>
#import <mach/mach.h>
@implementation FileSystem
-(id) getString{
return [NSString stringWithFormat:@"Not implemented"];
}
-(void) dealloc {
[super dealloc];
free(statfsptr);
}
- (double)freeMemory {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
}
- (double)activeMemory {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.active_count) / 1024.0) / 1024.0;
}
- (double)inactiveMemory {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.inactive_count) / 1024.0) / 1024.0;
}
- (double)wireMemory {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.wire_count) / 1024.0) / 1024.0;
}
- (double)zeroFillMemory {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.zero_fill_count) / 1024.0) / 1024.0;
}
- (double)reactivations {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size *vmStats.reactivations) / 1024.0) / 1024.0;
}
- (int)pageins {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return vmStats.pageins;
}
- (int)pageouts {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return vmStats.pageouts;
}
- (int)faults {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return vmStats.faults;
}
- (double)totalMemory {
host_basic_info_data_t hostInfo;
mach_msg_type_number_t infoCount = HOST_BASIC_INFO_COUNT;
kern_return_t kernReturn = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return (hostInfo.memory_size/ 1024.0) / 1024.0;
}
@end