1
2
3
4
5 package oshi.driver.unix.solaris.kstat;
6
7 import static oshi.software.os.unix.solaris.SolarisOperatingSystem.HAS_KSTAT2;
8
9 import com.sun.jna.platform.unix.solaris.LibKstat.Kstat;
10
11 import oshi.annotation.concurrent.ThreadSafe;
12 import oshi.util.platform.unix.solaris.KstatUtil;
13 import oshi.util.platform.unix.solaris.KstatUtil.KstatChain;
14 import oshi.util.tuples.Pair;
15
16
17
18
19 @ThreadSafe
20 public final class SystemPages {
21
22 private SystemPages() {
23 }
24
25
26
27
28
29
30 public static Pair<Long, Long> queryAvailableTotal() {
31 if (HAS_KSTAT2) {
32
33 return queryAvailableTotal2();
34 }
35 long memAvailable = 0;
36 long memTotal = 0;
37
38 try (KstatChain kc = KstatUtil.openChain()) {
39 Kstat ksp = kc.lookup(null, -1, "system_pages");
40
41 if (ksp != null && kc.read(ksp)) {
42 memAvailable = KstatUtil.dataLookupLong(ksp, "availrmem");
43 memTotal = KstatUtil.dataLookupLong(ksp, "physmem");
44 }
45 }
46 return new Pair<>(memAvailable, memTotal);
47 }
48
49 private static Pair<Long, Long> queryAvailableTotal2() {
50 Object[] results = KstatUtil.queryKstat2("kstat:/pages/unix/system_pages", "availrmem", "physmem");
51 long avail = results[0] == null ? 0L : (long) results[0];
52 long total = results[1] == null ? 0L : (long) results[1];
53 return new Pair<>(avail, total);
54 }
55 }