Optimize TPSWatcher
Remove 30 seconds TPSWatching
Dieser Commit ist enthalten in:
Ursprung
f83b1359c6
Commit
bb2bf2577e
13
SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java
Normale Datei
13
SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java
Normale Datei
@ -0,0 +1,13 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import net.minecraft.server.v1_10_R1.MinecraftServer;
|
||||
|
||||
public class SpigotTPS_10 {
|
||||
|
||||
private SpigotTPS_10(){}
|
||||
|
||||
static double[] getTps(){
|
||||
return MinecraftServer.getServer().recentTps;
|
||||
}
|
||||
|
||||
}
|
13
SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java
Normale Datei
13
SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java
Normale Datei
@ -0,0 +1,13 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.MinecraftServer;
|
||||
|
||||
public class SpigotTPS_12 {
|
||||
|
||||
private SpigotTPS_12(){}
|
||||
|
||||
static double[] getTps(){
|
||||
return MinecraftServer.getServer().recentTps;
|
||||
}
|
||||
|
||||
}
|
13
SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java
Normale Datei
13
SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java
Normale Datei
@ -0,0 +1,13 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import net.minecraft.server.v1_14_R1.MinecraftServer;
|
||||
|
||||
public class SpigotTPS_14 {
|
||||
|
||||
private SpigotTPS_14(){}
|
||||
|
||||
static double[] getTps(){
|
||||
return MinecraftServer.getServer().recentTps;
|
||||
}
|
||||
|
||||
}
|
13
SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java
Normale Datei
13
SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java
Normale Datei
@ -0,0 +1,13 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.MinecraftServer;
|
||||
|
||||
public class SpigotTPS_15 {
|
||||
|
||||
private SpigotTPS_15(){}
|
||||
|
||||
static double[] getTps(){
|
||||
return MinecraftServer.getServer().recentTps;
|
||||
}
|
||||
|
||||
}
|
13
SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java
Normale Datei
13
SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java
Normale Datei
@ -0,0 +1,13 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
|
||||
public class SpigotTPS_8 {
|
||||
|
||||
private SpigotTPS_8(){}
|
||||
|
||||
static double[] getTps(){
|
||||
return MinecraftServer.getServer().recentTps;
|
||||
}
|
||||
|
||||
}
|
13
SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java
Normale Datei
13
SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java
Normale Datei
@ -0,0 +1,13 @@
|
||||
package de.steamwar.core;
|
||||
|
||||
import net.minecraft.server.v1_9_R2.MinecraftServer;
|
||||
|
||||
public class SpigotTPS_9 {
|
||||
|
||||
private SpigotTPS_9(){}
|
||||
|
||||
static double[] getTps(){
|
||||
return MinecraftServer.getServer().recentTps;
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class Core extends JavaPlugin{
|
||||
private static Core instance;
|
||||
private static final int version;
|
||||
private static TPSWatcher tpsWatcher;
|
||||
|
||||
static{
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
@ -53,7 +52,6 @@ public class Core extends JavaPlugin{
|
||||
@Override
|
||||
public void onLoad() {
|
||||
setInstance(this);
|
||||
tpsWatcher = new TPSWatcher();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,10 +80,6 @@ public class Core extends JavaPlugin{
|
||||
return version;
|
||||
}
|
||||
|
||||
public static TPSWatcher getTpsWatcher() {
|
||||
return tpsWatcher;
|
||||
}
|
||||
|
||||
private static void setInstance(Core instance) {
|
||||
Core.instance = instance;
|
||||
}
|
||||
|
@ -21,45 +21,20 @@ package de.steamwar.core;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class TPSWatcher {
|
||||
|
||||
private LinkedList<Double> meter = new LinkedList<>();
|
||||
private int count = 30;
|
||||
private static final double tickTimeDefault = 1000;
|
||||
private static final double tickDefault = 20.0;
|
||||
|
||||
private double sum = 0;
|
||||
private int sumCount = 0;
|
||||
|
||||
private void add(double tps) {
|
||||
sum += tps;
|
||||
sumCount++;
|
||||
if (sumCount > 20) {
|
||||
meter.addLast(sum);
|
||||
if (meter.size() > count) meter.removeFirst();
|
||||
sum = 0;
|
||||
sumCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private double average(int count) {
|
||||
count = Math.min(count, meter.size());
|
||||
if (count == 0) return 20.0;
|
||||
Iterator<Double> doubleIterator = meter.iterator();
|
||||
double total = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
total += doubleIterator.next();
|
||||
}
|
||||
return total / count;
|
||||
}
|
||||
private static TPSWatcher tps_OneSecond = new TPSWatcher(1000);
|
||||
private static TPSWatcher tps_TenSecond = new TPSWatcher(10000);
|
||||
|
||||
private long lastTime = System.currentTimeMillis();
|
||||
|
||||
private static final double tickTimeDefault = 1000 / 20.0;
|
||||
private static final double tickDefault = 20.0;
|
||||
private double tps = 20.0;
|
||||
|
||||
TPSWatcher() {
|
||||
private TPSWatcher(long timeInterval) {
|
||||
timeInterval = timeInterval / 50;
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
long tickTime = System.currentTimeMillis() - lastTime;
|
||||
lastTime = System.currentTimeMillis();
|
||||
@ -68,25 +43,65 @@ public class TPSWatcher {
|
||||
if (tickTime != 0) {
|
||||
now = (tickTimeDefault / tickTime) * tickDefault;
|
||||
}
|
||||
add(now);
|
||||
}, 1, 1);
|
||||
if (now < 0) {
|
||||
now = 0;
|
||||
}
|
||||
tps = now;
|
||||
}, timeInterval, timeInterval);
|
||||
}
|
||||
|
||||
public enum TpsAverage {
|
||||
LAST_SECOND(1),
|
||||
LAST_TEN_SECONDS(10),
|
||||
LAST_THIRTY_SECONDS(30);
|
||||
public enum TPSType {
|
||||
|
||||
private final int count;
|
||||
|
||||
TpsAverage(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
// With own implementation
|
||||
ONE_SECOND,
|
||||
TEN_SECONDS,
|
||||
// With getting the values from Spigot itself
|
||||
ONE_MINUTE,
|
||||
FIVE_MINUTES,
|
||||
TEN_MINUTES
|
||||
|
||||
}
|
||||
|
||||
public double getTPS(TpsAverage average) {
|
||||
return average(average.count);
|
||||
public double getTPS() {
|
||||
return getTPS(TPSType.ONE_SECOND);
|
||||
}
|
||||
|
||||
public double getTPS(TPSType tpsType) {
|
||||
switch (tpsType) {
|
||||
case TEN_SECONDS:
|
||||
return round(tps_TenSecond.tps);
|
||||
case ONE_MINUTE:
|
||||
return round(getSpigotTPS()[0]);
|
||||
case FIVE_MINUTES:
|
||||
return round(getSpigotTPS()[1]);
|
||||
case TEN_MINUTES:
|
||||
return round(getSpigotTPS()[2]);
|
||||
|
||||
default:
|
||||
return round(tps_OneSecond.tps);
|
||||
}
|
||||
}
|
||||
|
||||
private double[] getSpigotTPS() {
|
||||
switch (Core.getVersion()) {
|
||||
case 8:
|
||||
return SpigotTPS_8.getTps();
|
||||
case 9:
|
||||
return SpigotTPS_9.getTps();
|
||||
case 10:
|
||||
return SpigotTPS_10.getTps();
|
||||
case 14:
|
||||
return SpigotTPS_14.getTps();
|
||||
case 15:
|
||||
return SpigotTPS_15.getTps();
|
||||
|
||||
default:
|
||||
return SpigotTPS_12.getTps();
|
||||
}
|
||||
}
|
||||
|
||||
private double round(double d) {
|
||||
return Math.round(d * 10) / 10.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren