Highly Optimized Tick Loop

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2017-01-26 21:50:51 +00:00
parent 68214fb1a0
commit cd82f21617
3 changed files with 150 additions and 59 deletions

View File

@@ -107,10 +107,11 @@
private static final int OVERLOADED_TICKS_THRESHOLD = 20; private static final int OVERLOADED_TICKS_THRESHOLD = 20;
private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeUtil.NANOSECONDS_PER_SECOND; private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeUtil.NANOSECONDS_PER_SECOND;
private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100; private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100;
@@ -277,6 +302,19 @@ @@ -276,6 +301,25 @@
private static final AtomicReference<RuntimeException> fatalException = new AtomicReference();
private final SuppressedExceptionCollector suppressedExceptions; private final SuppressedExceptionCollector suppressedExceptions;
private final DiscontinuousFrame tickFrame; private final DiscontinuousFrame tickFrame;
+
+ // CraftBukkit start + // CraftBukkit start
+ public final WorldLoader.DataLoadContext worldLoader; + public final WorldLoader.DataLoadContext worldLoader;
+ public org.bukkit.craftbukkit.CraftServer server; + public org.bukkit.craftbukkit.CraftServer server;
@@ -123,11 +124,16 @@
+ public Commands vanillaCommandDispatcher; + public Commands vanillaCommandDispatcher;
+ private boolean forceTicks; + private boolean forceTicks;
+ // CraftBukkit end + // CraftBukkit end
+ + // Spigot start
+ public static final int TPS = 20;
+ public static final int TICK_TIME = 1000000000 / MinecraftServer.TPS;
+ private static final int SAMPLE_INTERVAL = 100;
+ public final double[] recentTps = new double[ 3 ];
+ // Spigot end
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) { public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference(); AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new Thread(() -> { @@ -290,14 +334,14 @@
@@ -290,14 +328,14 @@
thread.setPriority(8); thread.setPriority(8);
} }
@@ -144,7 +150,7 @@
super("Server"); super("Server");
this.metricsRecorder = InactiveMetricsRecorder.INSTANCE; this.metricsRecorder = InactiveMetricsRecorder.INSTANCE;
this.onMetricsRecordingStopped = (methodprofilerresults) -> { this.onMetricsRecordingStopped = (methodprofilerresults) -> {
@@ -319,36 +357,63 @@ @@ -319,36 +363,63 @@
this.scoreboard = new ServerScoreboard(this); this.scoreboard = new ServerScoreboard(this);
this.customBossEvents = new CustomBossEvents(); this.customBossEvents = new CustomBossEvents();
this.suppressedExceptions = new SuppressedExceptionCollector(); this.suppressedExceptions = new SuppressedExceptionCollector();
@@ -223,7 +229,7 @@
} }
private void readScoreboard(DimensionDataStorage persistentStateManager) { private void readScoreboard(DimensionDataStorage persistentStateManager) {
@@ -357,7 +422,7 @@ @@ -357,7 +428,7 @@
protected abstract boolean initServer() throws IOException; protected abstract boolean initServer() throws IOException;
@@ -232,7 +238,7 @@
if (!JvmProfiler.INSTANCE.isRunning()) { if (!JvmProfiler.INSTANCE.isRunning()) {
; ;
} }
@@ -365,12 +430,8 @@ @@ -365,12 +436,8 @@
boolean flag = false; boolean flag = false;
ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted(); ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted();
@@ -246,7 +252,7 @@
if (profiledduration != null) { if (profiledduration != null) {
profiledduration.finish(true); profiledduration.finish(true);
} }
@@ -387,23 +448,217 @@ @@ -387,23 +454,217 @@
protected void forceDifficulty() {} protected void forceDifficulty() {}
@@ -478,10 +484,12 @@
if (!iworlddataserver.isInitialized()) { if (!iworlddataserver.isInitialized()) {
try { try {
@@ -427,30 +682,8 @@ @@ -425,32 +686,10 @@
iworlddataserver.setInitialized(true); }
}
iworlddataserver.setInitialized(true);
- }
-
- this.getPlayerList().addWorldborderListener(worldserver); - this.getPlayerList().addWorldborderListener(worldserver);
- if (this.worldData.getCustomBossEvents() != null) { - if (this.worldData.getCustomBossEvents() != null) {
- this.getCustomBossEvents().load(this.worldData.getCustomBossEvents(), this.registryAccess()); - this.getCustomBossEvents().load(this.worldData.getCustomBossEvents(), this.registryAccess());
@@ -502,15 +510,15 @@
- worldborder.addListener(new BorderChangeListener.DelegateBorderChangeListener(worldserver1.getWorldBorder())); - worldborder.addListener(new BorderChangeListener.DelegateBorderChangeListener(worldserver1.getWorldBorder()));
- this.levels.put(resourcekey1, worldserver1); - this.levels.put(resourcekey1, worldserver1);
- } - }
- } }
-
- worldborder.applySettings(iworlddataserver.getWorldBorder()); - worldborder.applySettings(iworlddataserver.getWorldBorder());
} }
+ // CraftBukkit end + // CraftBukkit end
private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) { private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) {
if (debugWorld) { if (debugWorld) {
@@ -458,6 +691,21 @@ @@ -458,6 +697,21 @@
} else { } else {
ServerChunkCache chunkproviderserver = world.getChunkSource(); ServerChunkCache chunkproviderserver = world.getChunkSource();
ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition()); ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition());
@@ -532,7 +540,7 @@
int i = chunkproviderserver.getGenerator().getSpawnHeight(world); int i = chunkproviderserver.getGenerator().getSpawnHeight(world);
if (i < world.getMinY()) { if (i < world.getMinY()) {
@@ -516,31 +764,36 @@ @@ -516,31 +770,36 @@
iworlddataserver.setGameType(GameType.SPECTATOR); iworlddataserver.setGameType(GameType.SPECTATOR);
} }
@@ -580,7 +588,7 @@
ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks"); ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks");
if (forcedchunk != null) { if (forcedchunk != null) {
@@ -555,10 +808,17 @@ @@ -555,10 +814,17 @@
} }
} }
@@ -602,7 +610,7 @@
} }
public GameType getDefaultGameType() { public GameType getDefaultGameType() {
@@ -588,12 +848,16 @@ @@ -588,12 +854,16 @@
worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force); worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force);
} }
@@ -621,7 +629,7 @@
if (flush) { if (flush) {
Iterator iterator1 = this.getAllLevels().iterator(); Iterator iterator1 = this.getAllLevels().iterator();
@@ -628,18 +892,40 @@ @@ -628,18 +898,40 @@
this.stopServer(); this.stopServer();
} }
@@ -662,7 +670,21 @@
} }
MinecraftServer.LOGGER.info("Saving worlds"); MinecraftServer.LOGGER.info("Saving worlds");
@@ -727,7 +1013,7 @@ @@ -720,6 +1012,13 @@
}
+ // Spigot Start
+ private static double calcTps(double avg, double exp, double tps)
+ {
+ return ( avg * exp ) + ( tps * ( 1 - exp ) );
+ }
+ // Spigot End
+
protected void runServer() {
try {
if (!this.initServer()) {
@@ -727,9 +1026,12 @@
} }
this.nextTickTimeNanos = Util.getNanos(); this.nextTickTimeNanos = Util.getNanos();
@@ -670,8 +692,13 @@
+ this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error + this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus(); this.status = this.buildServerStatus();
+ // Spigot start
+ Arrays.fill( this.recentTps, 20 );
+ long tickSection = Util.getMillis(), tickCount = 1;
while (this.running) { while (this.running) {
@@ -744,6 +1030,7 @@ long i;
@@ -744,11 +1046,23 @@
if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) { if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) {
long k = j / i; long k = j / i;
@@ -679,7 +706,23 @@
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", j / TimeUtil.NANOSECONDS_PER_MILLISECOND, k); MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", j / TimeUtil.NANOSECONDS_PER_MILLISECOND, k);
this.nextTickTimeNanos += k * i; this.nextTickTimeNanos += k * i;
this.lastOverloadWarningNanos = this.nextTickTimeNanos; this.lastOverloadWarningNanos = this.nextTickTimeNanos;
@@ -757,6 +1044,7 @@ }
}
+ // Spigot start
+ if ( tickCount++ % MinecraftServer.SAMPLE_INTERVAL == 0 )
+ {
+ long curTime = Util.getMillis();
+ double currentTps = 1E3 / ( curTime - tickSection ) * MinecraftServer.SAMPLE_INTERVAL;
+ this.recentTps[0] = MinecraftServer.calcTps( this.recentTps[0], 0.92, currentTps ); // 1/exp(5sec/1min)
+ this.recentTps[1] = MinecraftServer.calcTps( this.recentTps[1], 0.9835, currentTps ); // 1/exp(5sec/5min)
+ this.recentTps[2] = MinecraftServer.calcTps( this.recentTps[2], 0.9945, currentTps ); // 1/exp(5sec/15min)
+ tickSection = curTime;
+ }
+ // Spigot end
boolean flag = i == 0L;
@@ -757,6 +1071,7 @@
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount); this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
} }
@@ -687,7 +730,7 @@
this.nextTickTimeNanos += i; this.nextTickTimeNanos += i;
try { try {
@@ -830,6 +1118,13 @@ @@ -830,6 +1145,13 @@
this.services.profileCache().clearExecutor(); this.services.profileCache().clearExecutor();
} }
@@ -701,7 +744,7 @@
this.onServerExit(); this.onServerExit();
} }
@@ -889,9 +1184,16 @@ @@ -889,9 +1211,16 @@
} }
private boolean haveTime() { private boolean haveTime() {
@@ -719,7 +762,7 @@
public static boolean throwIfFatalException() { public static boolean throwIfFatalException() {
RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get(); RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get();
@@ -903,7 +1205,7 @@ @@ -903,7 +1232,7 @@
} }
public static void setFatalException(RuntimeException exception) { public static void setFatalException(RuntimeException exception) {
@@ -728,7 +771,7 @@
} }
@Override @Override
@@ -977,7 +1279,7 @@ @@ -977,7 +1306,7 @@
} }
} }
@@ -737,7 +780,7 @@
Profiler.get().incrementCounter("runTask"); Profiler.get().incrementCounter("runTask");
super.doRunTask(ticktask); super.doRunTask(ticktask);
} }
@@ -1025,6 +1327,7 @@ @@ -1025,6 +1354,7 @@
} }
public void tickServer(BooleanSupplier shouldKeepTicking) { public void tickServer(BooleanSupplier shouldKeepTicking) {
@@ -745,7 +788,7 @@
long i = Util.getNanos(); long i = Util.getNanos();
int j = this.pauseWhileEmptySeconds() * 20; int j = this.pauseWhileEmptySeconds() * 20;
@@ -1041,11 +1344,13 @@ @@ -1041,11 +1371,13 @@
this.autoSave(); this.autoSave();
} }
@@ -759,7 +802,7 @@
++this.tickCount; ++this.tickCount;
this.tickRateManager.tick(); this.tickRateManager.tick();
this.tickChildren(shouldKeepTicking); this.tickChildren(shouldKeepTicking);
@@ -1055,7 +1360,7 @@ @@ -1055,7 +1387,7 @@
} }
--this.ticksUntilAutosave; --this.ticksUntilAutosave;
@@ -768,7 +811,7 @@
this.autoSave(); this.autoSave();
} }
@@ -1071,10 +1376,13 @@ @@ -1071,10 +1403,13 @@
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F; this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
this.logTickMethodTime(i); this.logTickMethodTime(i);
gameprofilerfiller.pop(); gameprofilerfiller.pop();
@@ -783,7 +826,7 @@
MinecraftServer.LOGGER.debug("Autosave started"); MinecraftServer.LOGGER.debug("Autosave started");
ProfilerFiller gameprofilerfiller = Profiler.get(); ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -1082,6 +1390,7 @@ @@ -1082,6 +1417,7 @@
this.saveEverything(true, false, false); this.saveEverything(true, false, false);
gameprofilerfiller.pop(); gameprofilerfiller.pop();
MinecraftServer.LOGGER.debug("Autosave finished"); MinecraftServer.LOGGER.debug("Autosave finished");
@@ -791,7 +834,7 @@
} }
private void logTickMethodTime(long tickStartTime) { private void logTickMethodTime(long tickStartTime) {
@@ -1154,11 +1463,34 @@ @@ -1154,11 +1490,34 @@
this.getPlayerList().getPlayers().forEach((entityplayer) -> { this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing(); entityplayer.connection.suspendFlushing();
}); });
@@ -804,7 +847,7 @@
+ SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot + SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot
gameprofilerfiller.popPush("levels"); gameprofilerfiller.popPush("levels");
Iterator iterator = this.getAllLevels().iterator(); Iterator iterator = this.getAllLevels().iterator();
+
+ // CraftBukkit start + // CraftBukkit start
+ // Run tasks that are waiting on processing + // Run tasks that are waiting on processing
+ SpigotTimings.processQueueTimer.startTiming(); // Spigot + SpigotTimings.processQueueTimer.startTiming(); // Spigot
@@ -812,7 +855,7 @@
+ this.processQueue.remove().run(); + this.processQueue.remove().run();
+ } + }
+ SpigotTimings.processQueueTimer.stopTiming(); // Spigot + SpigotTimings.processQueueTimer.stopTiming(); // Spigot
+
+ SpigotTimings.timeUpdateTimer.startTiming(); // Spigot + SpigotTimings.timeUpdateTimer.startTiming(); // Spigot
+ // Send time updates to everyone, it will get the right time from the world the player is in. + // Send time updates to everyone, it will get the right time from the world the player is in.
+ if (this.tickCount % 20 == 0) { + if (this.tickCount % 20 == 0) {
@@ -826,7 +869,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next(); ServerLevel worldserver = (ServerLevel) iterator.next();
@@ -1167,16 +1499,20 @@ @@ -1167,16 +1526,20 @@
return s + " " + String.valueOf(worldserver.dimension().location()); return s + " " + String.valueOf(worldserver.dimension().location());
}); });
@@ -847,7 +890,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
@@ -1189,18 +1525,24 @@ @@ -1189,18 +1552,24 @@
} }
gameprofilerfiller.popPush("connection"); gameprofilerfiller.popPush("connection");
@@ -872,10 +915,12 @@
gameprofilerfiller.popPush("send chunks"); gameprofilerfiller.popPush("send chunks");
iterator = this.playerList.getPlayers().iterator(); iterator = this.playerList.getPlayers().iterator();
@@ -1267,6 +1609,22 @@ @@ -1265,7 +1634,23 @@
@Nullable
public ServerLevel getLevel(ResourceKey<Level> key) {
return (ServerLevel) this.levels.get(key); return (ServerLevel) this.levels.get(key);
} + }
+
+ // CraftBukkit start + // CraftBukkit start
+ public void addLevel(ServerLevel level) { + public void addLevel(ServerLevel level) {
+ Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels; + Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
@@ -889,13 +934,12 @@
+ Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels); + Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
+ newLevels.remove(level.dimension()); + newLevels.remove(level.dimension());
+ this.levels = Collections.unmodifiableMap(newLevels); + this.levels = Collections.unmodifiableMap(newLevels);
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
public Set<ResourceKey<Level>> levelKeys() { public Set<ResourceKey<Level>> levelKeys() {
return this.levels.keySet(); return this.levels.keySet();
} @@ -1296,7 +1681,7 @@
@@ -1296,7 +1654,7 @@
@DontObfuscate @DontObfuscate
public String getServerModName() { public String getServerModName() {
@@ -904,7 +948,7 @@
} }
public SystemReport fillSystemReport(SystemReport details) { public SystemReport fillSystemReport(SystemReport details) {
@@ -1507,7 +1865,7 @@ @@ -1507,7 +1892,7 @@
} }
public ServerConnectionListener getConnection() { public ServerConnectionListener getConnection() {
@@ -913,7 +957,7 @@
} }
public boolean isReady() { public boolean isReady() {
@@ -1634,11 +1992,11 @@ @@ -1634,11 +2019,11 @@
public CompletableFuture<Void> reloadResources(Collection<String> dataPacks) { public CompletableFuture<Void> reloadResources(Collection<String> dataPacks) {
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
@@ -927,7 +971,7 @@
}, this).thenCompose((immutablelist) -> { }, this).thenCompose((immutablelist) -> {
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist); MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess()); List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
@@ -1654,6 +2012,7 @@ @@ -1654,6 +2039,7 @@
}).thenAcceptAsync((minecraftserver_reloadableresources) -> { }).thenAcceptAsync((minecraftserver_reloadableresources) -> {
this.resources.close(); this.resources.close();
this.resources = minecraftserver_reloadableresources; this.resources = minecraftserver_reloadableresources;
@@ -935,7 +979,7 @@
this.packRepository.setSelected(dataPacks); this.packRepository.setSelected(dataPacks);
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures()); WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
@@ -1952,7 +2311,7 @@ @@ -1952,7 +2338,7 @@
final List<String> list = Lists.newArrayList(); final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules(); final GameRules gamerules = this.getGameRules();
@@ -944,7 +988,7 @@
@Override @Override
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) { public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key))); list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key)));
@@ -2058,7 +2417,7 @@ @@ -2058,7 +2444,7 @@
try { try {
label51: label51:
{ {
@@ -953,23 +997,20 @@
try { try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules()); arraylist = Lists.newArrayList(NativeModuleLister.listModules());
@@ -2105,9 +2464,25 @@ @@ -2108,6 +2494,22 @@
if (bufferedwriter != null) {
bufferedwriter.close(); }
}
+
+ }
+
+ // CraftBukkit start + // CraftBukkit start
+ public boolean isDebugging() { + public boolean isDebugging() {
+ return false; + return false;
+ } + }
+
+ @Deprecated + @Deprecated
+ public static MinecraftServer getServer() { + public static MinecraftServer getServer() {
+ return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null; + return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null;
} + }
+
+ @Deprecated + @Deprecated
+ public static RegistryAccess getDefaultRegistryAccess() { + public static RegistryAccess getDefaultRegistryAccess() {
+ return CraftRegistry.getMinecraftRegistry(); + return CraftRegistry.getMinecraftRegistry();
@@ -979,7 +1020,7 @@
private ProfilerFiller createProfiler() { private ProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) { if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> { this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
@@ -2234,6 +2609,11 @@ @@ -2234,6 +2636,11 @@
} }
} }

View File

@@ -266,4 +266,9 @@ public class SpigotConfig
} }
} }
} }
private static void tpsCommand()
{
SpigotConfig.commands.put( "tps", new TicksPerSecondCommand( "tps" ) );
}
} }

View File

@@ -0,0 +1,45 @@
package org.spigotmc;
import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
public class TicksPerSecondCommand extends Command
{
public TicksPerSecondCommand(String name)
{
super( name );
this.description = "Gets the current ticks per second for the server";
this.usageMessage = "/tps";
this.setPermission( "bukkit.command.tps" );
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args)
{
if ( !this.testPermission( sender ) )
{
return true;
}
StringBuilder sb = new StringBuilder( ChatColor.GOLD + "TPS from last 1m, 5m, 15m: " );
for ( double tps : MinecraftServer.getServer().recentTps )
{
sb.append( this.format( tps ) );
sb.append( ", " );
}
sender.sendMessage( sb.substring( 0, sb.length() - 2 ) );
sender.sendMessage(ChatColor.GOLD + "Current Memory Usage: " + ChatColor.GREEN + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) + "/" + (Runtime.getRuntime().totalMemory() / (1024 * 1024)) + " mb (Max: "
+ (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " mb)");
return true;
}
private String format(double tps)
{
return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
+ ( ( tps > 20.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 );
}
}