Upstream Paper
This commit is contained in:
@@ -41,7 +41,7 @@ import org.bukkit.Bukkit;
|
||||
class TimingHandler implements Timing {
|
||||
|
||||
private static AtomicInteger idPool = new AtomicInteger(1);
|
||||
static Deque<TimingHandler> TIMING_STACK = new ArrayDeque<>();
|
||||
private static Deque<TimingHandler> TIMING_STACK = new ArrayDeque<>();
|
||||
final int id = idPool.getAndIncrement();
|
||||
|
||||
final TimingIdentifier identifier;
|
||||
@@ -151,10 +151,16 @@ class TimingHandler implements Timing {
|
||||
|
||||
public void stopTiming() {
|
||||
if (enabled && timingDepth > 0 && (ThreadAssertion.isMainThread() || Bukkit.isPrimaryThread()) && --timingDepth == 0 && start != 0) { // Akarin
|
||||
TimingHandler last = TIMING_STACK.removeLast();
|
||||
if (last != this) {
|
||||
Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to Paper! ( " + this.identifier + ":" + last +")", new Throwable());
|
||||
TIMING_STACK.addLast(last); // Add it back
|
||||
TimingHandler last;
|
||||
while ((last = TIMING_STACK.removeLast()) != this) {
|
||||
last.timingDepth = 0;
|
||||
String reportTo;
|
||||
if ("minecraft".equals(last.identifier.group)) {
|
||||
reportTo = "Paper! This is a potential bug in Paper";
|
||||
} else {
|
||||
reportTo = "the plugin " + last.identifier.group + "(Look for errors above this in the logs)";
|
||||
}
|
||||
Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to " + reportTo + " (" + last.identifier +" did not stopTiming)", new Throwable());
|
||||
}
|
||||
addDiff(System.nanoTime() - start, TIMING_STACK.peekLast());
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class MinecraftTimings {
|
||||
*/
|
||||
public static Timing getPluginTaskTimings(BukkitTask bukkitTask, long period) {
|
||||
if (!bukkitTask.isSync()) {
|
||||
return null;
|
||||
return NullTimingHandler.NULL;
|
||||
}
|
||||
Plugin plugin;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.craftbukkit.scheduler;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import co.aikar.timings.NullTimingHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import co.aikar.timings.MinecraftTimings; // Paper
|
||||
import co.aikar.timings.Timing; // Paper
|
||||
@@ -57,7 +59,7 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||||
}
|
||||
this.id = id;
|
||||
this.period = period;
|
||||
timings = task != null ? MinecraftTimings.getPluginTaskTimings(this, period) : null; // Paper
|
||||
timings = task != null ? MinecraftTimings.getPluginTaskTimings(this, period) : NullTimingHandler.NULL; // Paper
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,13 +79,13 @@ public class CraftTask implements BukkitTask, Runnable { // Spigot
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timings != null && isSync()) timings.startTimingUnsafe(); // Paper
|
||||
try (Timing ignored = timings.startTiming()) { // Paper
|
||||
if (rTask != null) {
|
||||
rTask.run();
|
||||
} else {
|
||||
cTask.accept(this);
|
||||
}
|
||||
if (timings != null && isSync()) timings.stopTimingUnsafe(); // Paper
|
||||
} // Paper
|
||||
}
|
||||
|
||||
long getPeriod() {
|
||||
|
||||
Reference in New Issue
Block a user