Skip to content

Commit 54faeae

Browse files
Re-add CPU model detection and add GPU model detection via OSHI
1 parent 531c27b commit 54faeae

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
<version>1.20.4-R0.1-SNAPSHOT</version>
1919
<scope>provided</scope>
2020
</dependency>
21+
22+
<dependency>
23+
<groupId>com.github.oshi</groupId>
24+
<artifactId>oshi-core</artifactId>
25+
<version>6.4.5</version>
26+
<!-- This is a vanilla dependency, as of 1.20.4 -->
27+
<scope>provided</scope>
28+
</dependency>
2129
</dependencies>
2230

2331
<repositories>

src/main/java/pw/kaboom/extras/commands/CommandServerInfo.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,35 @@
55
import org.bukkit.command.Command;
66
import org.bukkit.command.CommandExecutor;
77
import org.bukkit.command.CommandSender;
8+
import oshi.SystemInfo;
9+
import oshi.hardware.GraphicsCard;
10+
import oshi.hardware.HardwareAbstractionLayer;
811

912
import javax.annotation.Nonnull;
1013
import java.lang.management.ManagementFactory;
1114
import java.net.InetAddress;
1215

1316
public final class CommandServerInfo implements CommandExecutor {
17+
private static final String[] GPU_DEVICES;
18+
private static final String PROCESSOR_NAME;
19+
20+
static {
21+
// No need to store this in a static variable as it would
22+
// just waste memory & won't be accessed outside construction
23+
// anyway.
24+
25+
final SystemInfo systemInfo = new SystemInfo();
26+
final HardwareAbstractionLayer hardware = systemInfo.getHardware();
27+
28+
GPU_DEVICES = hardware.getGraphicsCards()
29+
.stream()
30+
.map(GraphicsCard::getName)
31+
.toArray(String[]::new);
32+
PROCESSOR_NAME = hardware.getProcessor()
33+
.getProcessorIdentifier()
34+
.getName();
35+
}
36+
1437
private void sendInfoMessage(final CommandSender target, final String description,
1538
final String value) {
1639
target.sendMessage(
@@ -50,13 +73,23 @@ public boolean onCommand(final @Nonnull CommandSender sender,
5073
+ ManagementFactory.getRuntimeMXBean().getVmVersion()
5174
);
5275

76+
sendInfoMessage(sender, "CPU model", PROCESSOR_NAME);
77+
5378
sendInfoMessage(sender, "CPU cores",
5479
String.valueOf(Runtime.getRuntime().availableProcessors())
5580
);
5681
sendInfoMessage(sender, "CPU load",
5782
String.valueOf(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())
5883
);
5984

85+
for (int i = 0; i < GPU_DEVICES.length; i++) {
86+
sendInfoMessage(
87+
sender,
88+
"GPU device (" + i + ")",
89+
GPU_DEVICES[i]
90+
);
91+
}
92+
6093
final long heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
6194
final long nonHeapUsage = ManagementFactory.getMemoryMXBean()
6295
.getNonHeapMemoryUsage().getUsed();

0 commit comments

Comments
 (0)