mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-12 03:13:46 +01:00
Updated CPU Usage method #631
This commit is contained in:
parent
e974e987d9
commit
efa98483a0
@ -40,13 +40,7 @@ public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
|
||||
* @return the TPS
|
||||
*/
|
||||
private TPS calculateTPS(long diff, long now) {
|
||||
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
|
||||
double averageCPUUsage = operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0;
|
||||
|
||||
if (averageCPUUsage < 0) { // If unavailable, getSystemLoadAverage() returns -1
|
||||
averageCPUUsage = -1;
|
||||
}
|
||||
double averageCPUUsage = getCPUUsage();
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
@ -63,6 +57,23 @@ public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
|
||||
return getTPS(diff, now, averageCPUUsage, usedMemory, entityCount, loadedChunks, playersOnline);
|
||||
}
|
||||
|
||||
private double getCPUUsage() {
|
||||
double averageCPUUsage;
|
||||
|
||||
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
|
||||
com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
|
||||
averageCPUUsage = nativeOsBean.getSystemCpuLoad();
|
||||
} else {
|
||||
int availableProcessors = osBean.getAvailableProcessors();
|
||||
averageCPUUsage = osBean.getSystemLoadAverage() / availableProcessors;
|
||||
}
|
||||
if (averageCPUUsage < 0) { // If unavailable, getSystemLoadAverage() returns -1
|
||||
averageCPUUsage = -1;
|
||||
}
|
||||
return averageCPUUsage * 100.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the TPS for Spigot / Bukkit
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user