-
Notifications
You must be signed in to change notification settings - Fork 1
/
HelloCpuFeatures.java
50 lines (42 loc) · 1.66 KB
/
HelloCpuFeatures.java
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
package cpufeatures;
import cpufeatures.x86.X86Info;
import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
public final class HelloCpuFeatures {
private static String format(int value) {
return String.format("%3d (0x%02x)", value, value);
}
private static List<String> format(Collection<? extends Enum<?>> enums) {
return enums.stream()
.map(Enum::name)
.sorted().toList();
}
@Test
public void helloWorld() {
CpuFeatures.load();
var keys = new LinkedHashMap<String, String>();
CpuArchitecture arch = CpuArchitecture.get();
switch (arch) {
case AARCH64 -> throw new UnsupportedOperationException();
case ARM -> throw new UnsupportedOperationException();
case X86 -> {
X86Info info = X86Info.get();
keys.put("arch", "x86");
keys.put("family", format(info.family()));
keys.put("model", format(info.model()));
keys.put("stepping", format(info.stepping()));
keys.put("vendor", info.vendor());
keys.put("brand", info.brandString());
keys.put("uarch", info.uarch().name());
var featureSet = format(info.featureSet());
keys.put("flags", "(" + featureSet.size() + ") " + featureSet);
}
default -> throw new RuntimeException("Invalid architecture " + arch);
}
for (var entry : keys.entrySet()) {
System.out.printf("%10s: %s%n", entry.getKey(), entry.getValue());
}
}
}