1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package oshi.software.os.mac.local;
18
19 import java.util.Arrays;
20 import java.util.List;
21
22 import com.sun.jna.Library;
23 import com.sun.jna.Native;
24 import com.sun.jna.Pointer;
25 import com.sun.jna.Structure;
26 import com.sun.jna.ptr.IntByReference;
27 import com.sun.jna.ptr.LongByReference;
28 import com.sun.jna.ptr.PointerByReference;
29
30
31
32
33
34
35 public interface SystemB extends Library {
36
37 SystemB INSTANCE = (SystemB) Native.loadLibrary("System", SystemB.class);
38
39
40 static int HOST_LOAD_INFO = 1;
41 static int HOST_VM_INFO = 2;
42 static int HOST_CPU_LOAD_INFO = 3;
43
44
45 static int HOST_VM_INFO64 = 4;
46 static int HOST_EXTMOD_INFO64 = 5;
47 static int HOST_EXPIRED_TASK_INFO = 6;
48
49 static int PROCESSOR_CPU_LOAD_INFO = 2;
50
51
52 static int CTL_KERN = 1;
53 static int KERN_OSVERSION = 65;
54
55 static int CTL_HW = 6;
56 static int HW_MEMSIZE = 24;
57 static int HW_LOGICALCPU = 103;
58 static int HW_LOGICALCPU_MAX = 104;
59 static int HW_CPU64BIT_CAPABLE = 107;
60
61 static int CTL_MACHDEP = 7;
62 static int MACHDEP_CPU = 102;
63 static int MACHDEP_CPU_VENDOR = 103;
64 static int MACHDEP_CPU_BRAND_STRING = 104;
65 static int MACHDEP_CPU_FAMILY = 105;
66 static int MACHDEP_CPU_MODEL = 106;
67 static int MACHDEP_CPU_STEPPING = 109;
68
69
70 static int CPU_STATE_MAX = 4;
71 static int CPU_STATE_USER = 0;
72 static int CPU_STATE_SYSTEM = 1;
73 static int CPU_STATE_IDLE = 2;
74 static int CPU_STATE_NICE = 3;
75
76
77 static int UINT64_SIZE = Native.getNativeSize(long.class);
78 static int INT_SIZE = Native.getNativeSize(int.class);
79
80 public static class HostCpuLoadInfo extends Structure {
81 public int[] cpu_ticks = new int[CPU_STATE_MAX];
82
83 @Override
84 protected List<String> getFieldOrder() {
85 return Arrays.asList(new String[] { "cpu_ticks" });
86 }
87 }
88
89 public static class HostLoadInfo extends Structure {
90 public int[] avenrun = new int[3];
91 public int[] mach_factor = new int[3];
92
93 @Override
94 protected List<String> getFieldOrder() {
95 return Arrays.asList(new String[] { "avenrun", "mach_factor" });
96 }
97 }
98
99 public static class VMStatistics extends Structure {
100 public int free_count;
101 public int active_count;
102 public int inactive_count;
103 public int wire_count;
104 public int zero_fill_count;
105 public int reactivations;
106 public int pageins;
107 public int pageouts;
108 public int faults;
109 public int cow_faults;
110 public int lookups;
111 public int hits;
112 public int purgeable_count;
113 public int purges;
114
115 public int speculative_count;
116
117 @Override
118 protected List<String> getFieldOrder() {
119 return Arrays.asList(new String[] { "free_count", "active_count",
120 "inactive_count", "wire_count", "zero_fill_count",
121 "reactivations", "pageins", "pageouts", "faults",
122 "cow_faults", "lookups", "hits", "purgeable_count",
123 "purges", "speculative_count" });
124 }
125 }
126
127 public static class VMStatistics64 extends Structure {
128 public int free_count;
129 public int active_count;
130 public int inactive_count;
131 public int wire_count;
132 public long zero_fill_count;
133 public long reactivations;
134 public long pageins;
135 public long pageouts;
136 public long faults;
137 public long cow_faults;
138 public long lookups;
139 public long hits;
140 public long purges;
141 public int purgeable_count;
142
143 public int speculative_count;
144 public long decompressions;
145 public long compressions;
146
147 public long swapins;
148
149 public long swapouts;
150
151
152 public int compressor_page_count;
153 public int throttled_count;
154
155 public int external_page_count;
156 public int internal_page_count;
157
158 public long total_uncompressed_pages_in_compressor;
159
160 @Override
161 protected List<String> getFieldOrder() {
162 return Arrays.asList(new String[] { "free_count", "active_count",
163 "inactive_count", "wire_count", "zero_fill_count",
164 "reactivations", "pageins", "pageouts", "faults",
165 "cow_faults", "lookups", "hits", "purges",
166 "purgeable_count", "speculative_count", "decompressions",
167 "compressions", "swapins", "swapouts",
168 "compressor_page_count", "throttled_count",
169 "external_page_count", "internal_page_count",
170 "total_uncompressed_pages_in_compressor" });
171 }
172 }
173
174 int mach_host_self();
175
176 int host_page_size(int machPort, LongByReference pPageSize);
177
178 int host_statistics(int machPort, int hostStat, Object stats,
179 IntByReference count);
180
181 int host_statistics64(int machPort, int hostStat, Object stats,
182 IntByReference count);
183
184 int host_processor_info(int machPort, int flavor, IntByReference procCount,
185 PointerByReference procInfo, IntByReference procInfoCount);
186
187 int sysctl(int[] name, int namelen, Pointer oldp, IntByReference oldlenp,
188 Pointer newp, int newlen);
189
190 int sysctlbyname(String name, Pointer oldp, IntByReference oldlenp,
191 Pointer newp, int newlen);
192 }