From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: AlphaKR93 Date: Wed, 15 May 2024 12:43:03 +0900 Subject: [PATCH] Completely remove timings implementations diff --git a/src/main/java/co/aikar/timings/FullServerTickHandler.java b/src/main/java/co/aikar/timings/FullServerTickHandler.java deleted file mode 100644 index 73b125979e2f2dfd13cbf689a90b29cc68a36e09..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/FullServerTickHandler.java +++ /dev/null @@ -1,89 +0,0 @@ -package co.aikar.timings; - -import static co.aikar.timings.TimingsManager.*; - -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; - -/** - * @deprecated Timings will be removed in the future - */ -@Deprecated(forRemoval = true) -public class FullServerTickHandler extends TimingHandler { - private static final TimingIdentifier IDENTITY = new TimingIdentifier("Minecraft", "Full Server Tick", null); - final TimingData minuteData; - double avgFreeMemory = -1D; - double avgUsedMemory = -1D; - FullServerTickHandler() { - super(IDENTITY); - minuteData = new TimingData(id); - - TIMING_MAP.put(IDENTITY, this); - } - - @NotNull - @Override - public Timing startTiming() { - if (TimingsManager.needsFullReset) { - TimingsManager.resetTimings(); - } else if (TimingsManager.needsRecheckEnabled) { - TimingsManager.recheckEnabled(); - } - return super.startTiming(); - } - - @Override - public void stopTiming() { - super.stopTiming(); - if (!isEnabled()) { - return; - } - if (TimingHistory.timedTicks % 20 == 0) { - final Runtime runtime = Runtime.getRuntime(); - double usedMemory = runtime.totalMemory() - runtime.freeMemory(); - double freeMemory = runtime.maxMemory() - usedMemory; - if (this.avgFreeMemory == -1) { - this.avgFreeMemory = freeMemory; - } else { - this.avgFreeMemory = (this.avgFreeMemory * (59 / 60D)) + (freeMemory * (1 / 60D)); - } - - if (this.avgUsedMemory == -1) { - this.avgUsedMemory = usedMemory; - } else { - this.avgUsedMemory = (this.avgUsedMemory * (59 / 60D)) + (usedMemory * (1 / 60D)); - } - } - - long start = System.nanoTime(); - TimingsManager.tick(); - long diff = System.nanoTime() - start; - TIMINGS_TICK.addDiff(diff, null); - // addDiff for TIMINGS_TICK incremented this, bring it back down to 1 per tick. - record.setCurTickCount(record.getCurTickCount()-1); - - minuteData.setCurTickTotal(record.getCurTickTotal()); - minuteData.setCurTickCount(1); - - boolean violated = isViolated(); - minuteData.processTick(violated); - TIMINGS_TICK.processTick(violated); - processTick(violated); - - - if (TimingHistory.timedTicks % 1200 == 0) { - MINUTE_REPORTS.add(new TimingHistory.MinuteReport()); - TimingHistory.resetTicks(false); - minuteData.reset(); - } - if (TimingHistory.timedTicks % Timings.getHistoryInterval() == 0) { - TimingsManager.HISTORY.add(new TimingHistory()); - TimingsManager.resetTimings(); - } - //Bukkit.getUnsafe().reportTimings(); - } - - boolean isViolated() { - return record.getCurTickTotal() > 50000000; - } -} diff --git a/src/main/java/co/aikar/timings/NullTimingHandler.java b/src/main/java/co/aikar/timings/NullTimingHandler.java deleted file mode 100644 index 42e7e712403676171d34d5f2be27e48e7a071ebd..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/NullTimingHandler.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @deprecated Timings will be removed in the future - */ -@Deprecated(forRemoval = true) -public final class NullTimingHandler implements Timing { - public static final Timing NULL = new NullTimingHandler(); - @NotNull - @Override - public Timing startTiming() { - return this; - } - - @Override - public void stopTiming() { - - } - - @NotNull - @Override - public Timing startTimingIfSync() { - return this; - } - - @Override - public void stopTimingIfSync() { - - } - - @Override - public void abort() { - - } - - @Nullable - @Override - public TimingHandler getTimingHandler() { - return null; - } - - @Override - public void close() { - - } -} diff --git a/src/main/java/co/aikar/timings/TimedEventExecutor.java b/src/main/java/co/aikar/timings/TimedEventExecutor.java deleted file mode 100644 index 438a9c76381ea3f5b774e2232ff56c5dc6f82586..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/TimedEventExecutor.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import org.bukkit.Bukkit; -import org.bukkit.event.Event; -import org.bukkit.event.EventException; -import org.bukkit.event.Listener; -import org.bukkit.plugin.EventExecutor; -import org.bukkit.plugin.Plugin; - -import java.lang.reflect.Method; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @deprecated Timings will be removed in the future - */ -@Deprecated(forRemoval = true) -public class TimedEventExecutor implements EventExecutor { - - private final EventExecutor executor; - private final Timing timings; - - /** - * Wraps an event executor and associates a timing handler to it. - * - * @param executor Executor to wrap - * @param plugin Owning plugin - * @param method EventHandler method - * @param eventClass Owning class - */ - public TimedEventExecutor(@NotNull EventExecutor executor, @NotNull Plugin plugin, @Nullable Method method, @NotNull Class eventClass) { - this.executor = executor; - String id; - - if (method == null) { - if (executor.getClass().getEnclosingClass() != null) { // Oh Skript, how we love you - method = executor.getClass().getEnclosingMethod(); - } - } - - if (method != null) { - id = method.getDeclaringClass().getName(); - } else { - id = executor.getClass().getName(); - } - - - final String eventName = eventClass.getSimpleName(); - boolean verbose = "BlockPhysicsEvent".equals(eventName); - this.timings = Timings.ofSafe(plugin, (verbose ? "## " : "") + - "Event: " + id + " (" + eventName + ")"); - } - - @Override - public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { - if (event.isAsynchronous() || !Timings.timingsEnabled || !Bukkit.isPrimaryThread()) { - executor.execute(listener, event); - return; - } - //try (Timing ignored = timings.startTiming()){ // Purpur - executor.execute(listener, event); - //} // Purpur - } - - @Override - @NotNull - public String toString() { - return "TimedEventExecutor['" + this.executor.toString() + "']"; - } -} diff --git a/src/main/java/co/aikar/timings/Timing.java b/src/main/java/co/aikar/timings/Timing.java index 8709c955bac34bc546a8e022cfac808bc61ee793..228a9fa4ad569d69166ea990b5cc7e07b15e567a 100644 --- a/src/main/java/co/aikar/timings/Timing.java +++ b/src/main/java/co/aikar/timings/Timing.java @@ -40,7 +40,12 @@ public interface Timing extends AutoCloseable { */ @NotNull @io.papermc.paper.annotation.DoNotUse // Purpur - Timing startTiming(); + // Plazma start - Completely remove timings implementation + @Deprecated(forRemoval = true) + default Timing startTiming() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); + } + // Plazma end - Completely remove timings implementation /** *

Stops timing and records the data. Propagates the data up to group handlers.

@@ -48,7 +53,12 @@ public interface Timing extends AutoCloseable { * Will automatically be called when this Timing is used with try-with-resources */ @io.papermc.paper.annotation.DoNotUse // Purpur - void stopTiming(); + // Plazma start - Completely remove timings implementation + @Deprecated(forRemoval = true) + default void stopTiming() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); + } + // Plazma end - Completely remove timings implementation /** * Starts timing the execution until {@link #stopTiming()} is called. @@ -59,7 +69,12 @@ public interface Timing extends AutoCloseable { */ @NotNull @io.papermc.paper.annotation.DoNotUse // Purpur - Timing startTimingIfSync(); + // Plazma start - Completely remove timings implementation + @Deprecated(forRemoval = true) + default Timing startTimingIfSync() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); + } + // Plazma end - Completely remove timings implementation /** *

Stops timing and records the data. Propagates the data up to group handlers.

@@ -69,14 +84,23 @@ public interface Timing extends AutoCloseable { * But only if we are on the primary thread. */ @io.papermc.paper.annotation.DoNotUse // Purpur - void stopTimingIfSync(); + // Plazma start - Completely remove timings implementation + @Deprecated(forRemoval = true) + default void stopTimingIfSync() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); + } + // Plazma end - Completely remove timings implementation /** * @deprecated Doesn't do anything - Removed */ - @Deprecated + @Deprecated(forRemoval = true) @io.papermc.paper.annotation.DoNotUse // Purpur - void abort(); + // Plazma start - Completely remove timings implementation + default void abort() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); + } + // Plazma end - Completely remove timings implementation /** * Used internally to get the actual backing Handler in the case of delegated Handlers @@ -84,9 +108,22 @@ public interface Timing extends AutoCloseable { * @return TimingHandler */ @Nullable - TimingHandler getTimingHandler(); + // Plazma start - Completely remove timings implementation + @Deprecated(forRemoval = true) + @io.papermc.paper.annotation.DoNotUse + default TimingHandler getTimingHandler() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); + } + // Plazma end - Completely remove timings implementation + @Override @io.papermc.paper.annotation.DoNotUse // Purpur - void close(); + // Plazma start - Completely remove timings implementation + @Deprecated(forRemoval = true) + default void close() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); + } + // Plazma end - Completely remove timings implementation + } diff --git a/src/main/java/co/aikar/timings/TimingData.java b/src/main/java/co/aikar/timings/TimingData.java deleted file mode 100644 index a5d13a1e44edb861f45c83a9b4309fbf799d407d..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/TimingData.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import java.util.List; -import org.jetbrains.annotations.NotNull; - -import static co.aikar.util.JSONUtil.toArray; - -/** - *

Lightweight object for tracking timing data

- * - * This is broken out to reduce memory usage - */ -class TimingData { - private final int id; - private int count = 0; - private int lagCount = 0; - private long totalTime = 0; - private long lagTotalTime = 0; - private int curTickCount = 0; - private long curTickTotal = 0; - - TimingData(int id) { - this.id = id; - } - - private TimingData(TimingData data) { - this.id = data.id; - this.totalTime = data.totalTime; - this.lagTotalTime = data.lagTotalTime; - this.count = data.count; - this.lagCount = data.lagCount; - } - - void add(long diff) { - ++curTickCount; - curTickTotal += diff; - } - - void processTick(boolean violated) { - totalTime += curTickTotal; - count += curTickCount; - if (violated) { - lagTotalTime += curTickTotal; - lagCount += curTickCount; - } - curTickTotal = 0; - curTickCount = 0; - } - - void reset() { - count = 0; - lagCount = 0; - curTickTotal = 0; - curTickCount = 0; - totalTime = 0; - lagTotalTime = 0; - } - - protected TimingData clone() { - return new TimingData(this); - } - - @NotNull - List export() { - List list = toArray( - id, - count, - totalTime); - if (lagCount > 0) { - list.add(lagCount); - list.add(lagTotalTime); - } - return list; - } - - boolean hasData() { - return count > 0; - } - - long getTotalTime() { - return totalTime; - } - - int getCurTickCount() { - return curTickCount; - } - - void setCurTickCount(int curTickCount) { - this.curTickCount = curTickCount; - } - - long getCurTickTotal() { - return curTickTotal; - } - - void setCurTickTotal(long curTickTotal) { - this.curTickTotal = curTickTotal; - } -} diff --git a/src/main/java/co/aikar/timings/TimingHandler.java b/src/main/java/co/aikar/timings/TimingHandler.java index 41d10421e1e79711e2e90ff2dc225bfd9cac9284..3bd19b990078a177a4bd197f617c0f871ceb9d3a 100644 --- a/src/main/java/co/aikar/timings/TimingHandler.java +++ b/src/main/java/co/aikar/timings/TimingHandler.java @@ -1,226 +1,3 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ package co.aikar.timings; -import co.aikar.util.LoadingIntMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; - -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -class TimingHandler implements Timing { - - private static AtomicInteger idPool = new AtomicInteger(1); - private static Deque TIMING_STACK = new ArrayDeque<>(); - final int id = idPool.getAndIncrement(); - - final TimingIdentifier identifier; - private final boolean verbose; - - private final Int2ObjectOpenHashMap children = new LoadingIntMap<>(TimingData::new); - - final TimingData record; - private TimingHandler startParent; - private final TimingHandler groupHandler; - - private long start = 0; - private int timingDepth = 0; - private boolean added; - private boolean timed; - private boolean enabled; - - TimingHandler(@NotNull TimingIdentifier id) { - this.identifier = id; - this.verbose = id.name.startsWith("##"); - this.record = new TimingData(this.id); - this.groupHandler = id.groupHandler; - - TimingIdentifier.getGroup(id.group).handlers.add(this); - checkEnabled(); - } - - final void checkEnabled() { - enabled = Timings.timingsEnabled && (!verbose || Timings.verboseEnabled); - } - - void processTick(boolean violated) { - if (timingDepth != 0 || record.getCurTickCount() == 0) { - timingDepth = 0; - start = 0; - return; - } - - record.processTick(violated); - for (TimingData handler : children.values()) { - handler.processTick(violated); - } - } - - @NotNull - @Override - public Timing startTimingIfSync() { - startTiming(); - return this; - } - - @Override - public void stopTimingIfSync() { - stopTiming(); - } - - @NotNull - public Timing startTiming() { - if (!enabled || !Bukkit.isPrimaryThread()) { - return this; - } - if (++timingDepth == 1) { - startParent = TIMING_STACK.peekLast(); - start = System.nanoTime(); - } - TIMING_STACK.addLast(this); - return this; - } - - public void stopTiming() { - if (!enabled || timingDepth <= 0 || start == 0 || !Bukkit.isPrimaryThread()) { - return; - } - - popTimingStack(); - if (--timingDepth == 0) { - addDiff(System.nanoTime() - start, startParent); - startParent = null; - start = 0; - } - } - - private void popTimingStack() { - TimingHandler last; - while ((last = TIMING_STACK.removeLast()) != this) { - last.timingDepth = 0; - if ("Minecraft".equalsIgnoreCase(last.identifier.group)) { - Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Look above this for any errors and report this to " + io.papermc.paper.ServerBuildInfo.buildInfo().brandName() + " unless it has a plugin in the stack trace (" + last.identifier + " did not stopTiming)"); // Plazma - Fork-friendly Rebranding - } else { - Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to the plugin " + last.identifier.group + " (Look for errors above this in the logs) (" + last.identifier + " did not stopTiming)", new Throwable()); - } - - boolean found = TIMING_STACK.contains(this); - if (!found) { - // We aren't even in the stack... Don't pop everything - TIMING_STACK.addLast(last); - break; - } - } - } - - @Override - public final void abort() { - - } - - void addDiff(long diff, @Nullable TimingHandler parent) { - if (parent != null) { - parent.children.get(id).add(diff); - } - - record.add(diff); - if (!added) { - added = true; - timed = true; - TimingsManager.HANDLERS.add(this); - } - if (groupHandler != null) { - groupHandler.addDiff(diff, parent); - groupHandler.children.get(id).add(diff); - } - } - - /** - * Reset this timer, setting all values to zero. - */ - void reset(boolean full) { - record.reset(); - if (full) { - timed = false; - } - start = 0; - timingDepth = 0; - added = false; - children.clear(); - checkEnabled(); - } - - @NotNull - @Override - public TimingHandler getTimingHandler() { - return this; - } - - @Override - public boolean equals(Object o) { - return (this == o); - } - - @Override - public int hashCode() { - return id; - } - - /** - * This is simply for the Closeable interface so it can be used with try-with-resources () - */ - @Override - public void close() { - stopTimingIfSync(); - } - - public boolean isSpecial() { - return this == TimingsManager.FULL_SERVER_TICK || this == TimingsManager.TIMINGS_TICK; - } - - boolean isTimed() { - return timed; - } - - public boolean isEnabled() { - return enabled; - } - - @NotNull - TimingData[] cloneChildren() { - final TimingData[] clonedChildren = new TimingData[children.size()]; - int i = 0; - for (TimingData child : children.values()) { - clonedChildren[i++] = child.clone(); - } - return clonedChildren; - } -} +@Deprecated(forRemoval = true) interface TimingHandler {} // Plazma - Completely remove timings implementation diff --git a/src/main/java/co/aikar/timings/TimingHistory.java b/src/main/java/co/aikar/timings/TimingHistory.java deleted file mode 100644 index 6f6eb1a2e6c8d49014a7ae44540ee282bae5200e..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/TimingHistory.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import co.aikar.timings.TimingHistory.RegionData.RegionId; -import com.google.common.base.Function; -import com.google.common.collect.Sets; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.BlockState; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import co.aikar.util.LoadingMap; -import co.aikar.util.MRUMapCache; - -import java.lang.management.ManagementFactory; -import java.util.Collection; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static co.aikar.timings.TimingsManager.FULL_SERVER_TICK; -import static co.aikar.timings.TimingsManager.MINUTE_REPORTS; -import static co.aikar.util.JSONUtil.*; - -/** - * Internal. - * - * @deprecated Timings will be removed in the future - */ -@Deprecated(forRemoval = true) -@SuppressWarnings({"deprecation", "SuppressionAnnotation", "Convert2Lambda", "Anonymous2MethodRef"}) -public class TimingHistory { - public static long lastMinuteTime; - public static long timedTicks; - public static long playerTicks; - public static long entityTicks; - public static long tileEntityTicks; - public static long activatedEntityTicks; - private static int worldIdPool = 1; - static Map worldMap = LoadingMap.newHashMap(new Function() { - @NotNull - @Override - public Integer apply(@Nullable String input) { - return worldIdPool++; - } - }); - private final long endTime; - private final long startTime; - private final long totalTicks; - private final long totalTime; // Represents all time spent running the server this history - private final MinuteReport[] minuteReports; - - private final TimingHistoryEntry[] entries; - final Set tileEntityTypeSet = Sets.newHashSet(); - final Set entityTypeSet = Sets.newHashSet(); - private final Map worlds; - - TimingHistory() { - this.endTime = System.currentTimeMillis() / 1000; - this.startTime = TimingsManager.historyStart / 1000; - if (timedTicks % 1200 != 0 || MINUTE_REPORTS.isEmpty()) { - this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size() + 1]); - this.minuteReports[this.minuteReports.length - 1] = new MinuteReport(); - } else { - this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size()]); - } - long ticks = 0; - for (MinuteReport mp : this.minuteReports) { - ticks += mp.ticksRecord.timed; - } - this.totalTicks = ticks; - this.totalTime = FULL_SERVER_TICK.record.getTotalTime(); - this.entries = new TimingHistoryEntry[TimingsManager.HANDLERS.size()]; - - int i = 0; - for (TimingHandler handler : TimingsManager.HANDLERS) { - entries[i++] = new TimingHistoryEntry(handler); - } - - // Information about all loaded chunks/entities - //noinspection unchecked - this.worlds = toObjectMapper(Bukkit.getWorlds(), new Function() { - @NotNull - @Override - public JSONPair apply(World world) { - Map regions = LoadingMap.newHashMap(RegionData.LOADER); - - for (Chunk chunk : world.getLoadedChunks()) { - RegionData data = regions.get(new RegionId(chunk.getX(), chunk.getZ())); - - for (Entity entity : chunk.getEntities()) { - if (entity == null) { - Bukkit.getLogger().warning("Null entity detected in chunk at position x: " + chunk.getX() + ", z: " + chunk.getZ()); - continue; - } - - data.entityCounts.get(entity.getType()).increment(); - } - - for (BlockState tileEntity : chunk.getTileEntities(false)) { - if (tileEntity == null) { - Bukkit.getLogger().warning("Null tileentity detected in chunk at position x: " + chunk.getX() + ", z: " + chunk.getZ()); - continue; - } - - data.tileEntityCounts.get(tileEntity.getBlock().getType()).increment(); - } - } - return pair( - worldMap.get(world.getName()), - toArrayMapper(regions.values(),new Function() { - @NotNull - @Override - public Object apply(RegionData input) { - return toArray( - input.regionId.x, - input.regionId.z, - toObjectMapper(input.entityCounts.entrySet(), - new Function, JSONPair>() { - @NotNull - @Override - public JSONPair apply(Map.Entry entry) { - entityTypeSet.add(entry.getKey()); - return pair( - String.valueOf(entry.getKey().ordinal()), - entry.getValue().count() - ); - } - } - ), - toObjectMapper( - input.tileEntityCounts.entrySet(), - entry -> { - tileEntityTypeSet.add(entry.getKey()); - return pair( - String.valueOf(entry.getKey().ordinal()), - entry.getValue().count() - ); - } - ) - ); - } - }) - ); - } - }); - } - static class RegionData { - final RegionId regionId; - @SuppressWarnings("Guava") - static Function LOADER = new Function() { - @NotNull - @Override - public RegionData apply(@NotNull RegionId id) { - return new RegionData(id); - } - }; - RegionData(@NotNull RegionId id) { - this.regionId = id; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - RegionData that = (RegionData) o; - - return regionId.equals(that.regionId); - - } - - @Override - public int hashCode() { - return regionId.hashCode(); - } - - @SuppressWarnings("unchecked") - final Map entityCounts = MRUMapCache.of(LoadingMap.of( - new EnumMap(EntityType.class), k -> new Counter() - )); - @SuppressWarnings("unchecked") - final Map tileEntityCounts = MRUMapCache.of(LoadingMap.of( - new EnumMap(Material.class), k -> new Counter() - )); - - static class RegionId { - final int x, z; - final long regionId; - RegionId(int x, int z) { - this.x = x >> 5 << 5; - this.z = z >> 5 << 5; - this.regionId = ((long) (this.x) << 32) + (this.z >> 5 << 5) - Integer.MIN_VALUE; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - RegionId regionId1 = (RegionId) o; - - return regionId == regionId1.regionId; - - } - - @Override - public int hashCode() { - return (int) (regionId ^ (regionId >>> 32)); - } - } - } - static void resetTicks(boolean fullReset) { - if (fullReset) { - // Non full is simply for 1 minute reports - timedTicks = 0; - } - lastMinuteTime = System.nanoTime(); - playerTicks = 0; - tileEntityTicks = 0; - entityTicks = 0; - activatedEntityTicks = 0; - } - - @NotNull - Object export() { - return createObject( - pair("s", startTime), - pair("e", endTime), - pair("tk", totalTicks), - pair("tm", totalTime), - pair("w", worlds), - pair("h", toArrayMapper(entries, new Function() { - @Nullable - @Override - public Object apply(TimingHistoryEntry entry) { - TimingData record = entry.data; - if (!record.hasData()) { - return null; - } - return entry.export(); - } - })), - pair("mp", toArrayMapper(minuteReports, new Function() { - @NotNull - @Override - public Object apply(MinuteReport input) { - return input.export(); - } - })) - ); - } - - static class MinuteReport { - final long time = System.currentTimeMillis() / 1000; - - final TicksRecord ticksRecord = new TicksRecord(); - final PingRecord pingRecord = new PingRecord(); - final TimingData fst = TimingsManager.FULL_SERVER_TICK.minuteData.clone(); - final double tps = 1E9 / ( System.nanoTime() - lastMinuteTime ) * ticksRecord.timed; - final double usedMemory = TimingsManager.FULL_SERVER_TICK.avgUsedMemory; - final double freeMemory = TimingsManager.FULL_SERVER_TICK.avgFreeMemory; - final double loadAvg = ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage(); - - @NotNull - List export() { - return toArray( - time, - Math.round(tps * 100D) / 100D, - Math.round(pingRecord.avg * 100D) / 100D, - fst.export(), - toArray(ticksRecord.timed, - ticksRecord.player, - ticksRecord.entity, - ticksRecord.activatedEntity, - ticksRecord.tileEntity - ), - usedMemory, - freeMemory, - loadAvg - ); - } - } - - private static class TicksRecord { - final long timed; - final long player; - final long entity; - final long tileEntity; - final long activatedEntity; - - TicksRecord() { - timed = timedTicks - (TimingsManager.MINUTE_REPORTS.size() * 1200); - player = playerTicks; - entity = entityTicks; - tileEntity = tileEntityTicks; - activatedEntity = activatedEntityTicks; - } - - } - - private static class PingRecord { - final double avg; - - PingRecord() { - final Collection onlinePlayers = Bukkit.getOnlinePlayers(); - int totalPing = 0; - for (Player player : onlinePlayers) { - totalPing += player.spigot().getPing(); - } - avg = onlinePlayers.isEmpty() ? 0 : totalPing / onlinePlayers.size(); - } - } - - - private static class Counter { - private int count = 0; - public int increment() { - return ++count; - } - public int count() { - return count; - } - } -} diff --git a/src/main/java/co/aikar/timings/TimingHistoryEntry.java b/src/main/java/co/aikar/timings/TimingHistoryEntry.java deleted file mode 100644 index 86d5ac6bd0d7d0003688761aceb3f3343575319f..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/TimingHistoryEntry.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import com.google.common.base.Function; - -import java.util.List; -import org.jetbrains.annotations.NotNull; - -import static co.aikar.util.JSONUtil.toArrayMapper; - -class TimingHistoryEntry { - final TimingData data; - private final TimingData[] children; - - TimingHistoryEntry(@NotNull TimingHandler handler) { - this.data = handler.record.clone(); - children = handler.cloneChildren(); - } - - @NotNull - List export() { - List result = data.export(); - if (children.length > 0) { - result.add( - toArrayMapper(children, new Function() { - @NotNull - @Override - public Object apply(TimingData child) { - return child.export(); - } - }) - ); - } - return result; - } -} diff --git a/src/main/java/co/aikar/timings/TimingIdentifier.java b/src/main/java/co/aikar/timings/TimingIdentifier.java deleted file mode 100644 index df142a89b8c43acb81eb383eac0ef048a1f49a6e..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/TimingIdentifier.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import co.aikar.util.LoadingMap; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - *

Used as a basis for fast HashMap key comparisons for the Timing Map.

- * - * This class uses interned strings giving us the ability to do an identity check instead of equals() on the strings - */ -final class TimingIdentifier { - /** - * Holds all groups. Autoloads on request for a group by name. - */ - static final Map GROUP_MAP = LoadingMap.of(new ConcurrentHashMap<>(64, .5F), TimingGroup::new); - private static final TimingGroup DEFAULT_GROUP = getGroup("Minecraft"); - final String group; - final String name; - final TimingHandler groupHandler; - private final int hashCode; - - TimingIdentifier(@Nullable String group, @NotNull String name, @Nullable Timing groupHandler) { - this.group = group != null ? group: DEFAULT_GROUP.name; - this.name = name; - this.groupHandler = groupHandler != null ? groupHandler.getTimingHandler() : null; - this.hashCode = (31 * this.group.hashCode()) + this.name.hashCode(); - } - - @NotNull - static TimingGroup getGroup(@Nullable String groupName) { - if (groupName == null) { - //noinspection ConstantConditions - return DEFAULT_GROUP; - } - - return GROUP_MAP.get(groupName); - } - - @Override - public boolean equals(Object o) { - if (o == null) { - return false; - } - - TimingIdentifier that = (TimingIdentifier) o; - return Objects.equals(group, that.group) && Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public String toString() { - return "TimingIdentifier{id=" + group + ":" + name +'}'; - } - - static class TimingGroup { - - private static AtomicInteger idPool = new AtomicInteger(1); - final int id = idPool.getAndIncrement(); - - final String name; - final List handlers = Collections.synchronizedList(new ArrayList<>(64)); - - private TimingGroup(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - TimingGroup that = (TimingGroup) o; - return id == that.id; - } - - @Override - public int hashCode() { - return id; - } - } -} diff --git a/src/main/java/co/aikar/timings/Timings.java b/src/main/java/co/aikar/timings/Timings.java index 27a02f0c3261067d8e4ee6169c62cecbbfe50d42..3d0cf82b59d0d6ebc84fc589d75b508bf6acbded 100644 --- a/src/main/java/co/aikar/timings/Timings.java +++ b/src/main/java/co/aikar/timings/Timings.java @@ -44,18 +44,8 @@ import org.jetbrains.annotations.Nullable; * @deprecated Timings will be removed in the future */ @Deprecated(forRemoval = true) -@SuppressWarnings({"UnusedDeclaration", "WeakerAccess", "SameParameterValue"}) public final class Timings { - final static List requestingReport = Lists.newArrayList(); - private static final int MAX_HISTORY_FRAMES = 12; - public static final Timing NULL_HANDLER = new NullTimingHandler(); - static boolean timingsEnabled = false; - static boolean verboseEnabled = false; - private static int historyInterval = -1; - private static int historyLength = -1; - private static boolean warnedAboutDeprecationOnEnable; - private Timings() {} /** @@ -66,12 +56,10 @@ public final class Timings { * @return Handler */ @NotNull + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static Timing of(@NotNull Plugin plugin, @NotNull String name) { - Timing pluginHandler = null; - if (plugin != null) { - pluginHandler = ofSafe(plugin.getName(), "Combined Total", TimingsManager.PLUGIN_GROUP_HANDLER); - } - return of(plugin, name, pluginHandler); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -87,10 +75,10 @@ public final class Timings { * @return Timing Handler */ @NotNull + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static Timing of(@NotNull Plugin plugin, @NotNull String name, @Nullable Timing groupHandler) { - Preconditions.checkNotNull(plugin, "Plugin can not be null"); - Bukkit.getLogger().warning(String.format("Plugin '%s' is creating timing '%s' - this is deprecated behavior, please report it to the authors: %s", plugin.getName(), name, String.join(", ", plugin.getDescription().getAuthors()))); - return TimingsManager.getHandler(plugin.getName(), name, groupHandler); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -105,8 +93,10 @@ public final class Timings { * @return Timing Handler */ @NotNull + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static Timing ofStart(@NotNull Plugin plugin, @NotNull String name) { - return ofStart(plugin, name, null); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -122,10 +112,10 @@ public final class Timings { * @return Timing Handler */ @NotNull + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static Timing ofStart(@NotNull Plugin plugin, @NotNull String name, @Nullable Timing groupHandler) { - Timing timing = of(plugin, name, groupHandler); - //timing.startTiming(); // Purpur - return timing; + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -133,8 +123,10 @@ public final class Timings { * * @return Enabled or not */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static boolean isTimingsEnabled() { - return timingsEnabled; + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -144,28 +136,16 @@ public final class Timings { * * @param enabled Should timings be reported */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static void setTimingsEnabled(boolean enabled) { - if (enabled && !warnedAboutDeprecationOnEnable) { - //Bukkit.getLogger().severe(PlainTextComponentSerializer.plainText().serialize(deprecationMessage())); - warnedAboutDeprecationOnEnable = true; - } + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static Component deprecationMessage() { - return Component.text() - .color(TextColor.color(0xffc93a)) - .append(Component.text("[!] The timings profiler is in no-op mode and will be fully removed in a later update.")) - .append(Component.newline()) - .append(Component.text(" We recommend migrating to the spark profiler.")) - .append(Component.newline()) - .append( - Component.text(" For more information please visit: ") - .append( - Component.text() - .content("https://github.com/PaperMC/Paper/discussions/10565") - .clickEvent(ClickEvent.openUrl("https://github.com/PaperMC/Paper/discussions/10565"))) - ) - .build(); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -175,8 +155,10 @@ public final class Timings { * * @return Enabled or not */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static boolean isVerboseTimingsEnabled() { - return verboseEnabled; + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -187,9 +169,10 @@ public final class Timings { * * @param enabled Should high-frequency timings be reported */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static void setVerboseTimingsEnabled(boolean enabled) { - verboseEnabled = enabled; - TimingsManager.needsRecheckEnabled = true; + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -199,8 +182,10 @@ public final class Timings { * * @return Interval in ticks */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static int getHistoryInterval() { - return historyInterval; + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -213,12 +198,10 @@ public final class Timings { * * @param interval Interval in ticks */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static void setHistoryInterval(int interval) { - historyInterval = Math.max(20*60, interval); - // Recheck the history length with the new Interval - if (historyLength != -1) { - setHistoryLength(historyLength); - } + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -228,8 +211,10 @@ public final class Timings { * * @return Duration in Ticks */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static int getHistoryLength() { - return historyLength; + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -243,30 +228,19 @@ public final class Timings { * * @param length Duration in ticks */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static void setHistoryLength(int length) { - // Cap at 12 History Frames, 1 hour at 5 minute frames. - int maxLength = historyInterval * MAX_HISTORY_FRAMES; - // For special cases of servers with special permission to bypass the max. - // This max helps keep data file sizes reasonable for processing on Aikar's Timing parser side. - // Setting this will not help you bypass the max unless Aikar has added an exception on the API side. - if (System.getProperty("timings.bypassMax") != null) { - maxLength = Integer.MAX_VALUE; - } - historyLength = Math.max(Math.min(maxLength, length), historyInterval); - Queue oldQueue = TimingsManager.HISTORY; - int frames = (getHistoryLength() / getHistoryInterval()); - if (length > maxLength) { - Bukkit.getLogger().log(Level.WARNING, "Timings Length too high. Requested " + length + ", max is " + maxLength + ". To get longer history, you must increase your interval. Set Interval to " + Math.ceil(length / MAX_HISTORY_FRAMES) + " to achieve this length."); - } - TimingsManager.HISTORY = EvictingQueue.create(frames); - TimingsManager.HISTORY.addAll(oldQueue); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** * Resets all Timing Data */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static void reset() { - TimingsManager.reset(); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -275,11 +249,10 @@ public final class Timings { * If sender is null, ConsoleCommandSender will be used. * @param sender The sender to send to, or null to use the ConsoleCommandSender */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static void generateReport(@Nullable CommandSender sender) { - if (sender == null) { - sender = Bukkit.getConsoleSender(); - } - requestingReport.add(sender); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } /** @@ -287,39 +260,11 @@ public final class Timings { * Use with {@link org.bukkit.command.BufferedCommandSender} to get full response when done! * @param sender The listener to send responses too. */ + @Deprecated(forRemoval = true) // Plazma - Completely remove timings implementation + @io.papermc.paper.annotation.DoNotUse // Plazma - Completely remove timings implementation public static void generateReport(@NotNull TimingsReportListener sender) { - Preconditions.checkNotNull(sender); - requestingReport.add(sender); - } - - /* - ================= - Protected API: These are for internal use only in Bukkit/CraftBukkit - These do not have isPrimaryThread() checks in the startTiming/stopTiming - ================= - */ - @NotNull - static TimingHandler ofSafe(@NotNull String name) { - return ofSafe(null, name, null); - } - - @NotNull - static Timing ofSafe(@Nullable Plugin plugin, @NotNull String name) { - Timing pluginHandler = null; - if (plugin != null) { - pluginHandler = ofSafe(plugin.getName(), "Combined Total", TimingsManager.PLUGIN_GROUP_HANDLER); - } - return ofSafe(plugin != null ? plugin.getName() : "Minecraft - Invalid Plugin", name, pluginHandler); - } - - @NotNull - static TimingHandler ofSafe(@NotNull String name, @Nullable Timing groupHandler) { - return ofSafe(null, name, groupHandler); + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use spark instead."); // Plazma - Completely remove timings implementation } - @NotNull - static TimingHandler ofSafe(@Nullable String groupName, @NotNull String name, @Nullable Timing groupHandler) { - return TimingsManager.getHandler(groupName, name, groupHandler); - } } diff --git a/src/main/java/co/aikar/timings/TimingsCommand.java b/src/main/java/co/aikar/timings/TimingsCommand.java deleted file mode 100644 index f28eec202237461cb489a2b13289d813381a25bc..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/TimingsCommand.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.defaults.BukkitCommand; -import org.bukkit.util.StringUtil; - -import java.util.ArrayList; -import java.util.List; -import org.jetbrains.annotations.NotNull; - -import static net.kyori.adventure.text.Component.text; - -/** - * @deprecated Timings will be removed in the future - */ -@Deprecated(forRemoval = true) -public class TimingsCommand extends BukkitCommand { - private static final List TIMINGS_SUBCOMMANDS = ImmutableList.of("report", "reset", "on", "off", "paste", "verbon", "verboff"); - private long lastResetAttempt = 0; - - public TimingsCommand(@NotNull String name) { - super(name); - this.description = "Manages Spigot Timings data to see performance of the server."; - this.usageMessage = "/timings";// "; // Purpur - this.setPermission("bukkit.command.timings"); - } - - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) { - if (!testPermission(sender)) { - return true; - } - if (true) { - net.kyori.adventure.text.minimessage.MiniMessage mm = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage(); - sender.sendMessage(mm.deserialize("Purpur has removed timings to save your performance. Please use /spark instead")); - sender.sendMessage(mm.deserialize("For more information, view its documentation at")); - sender.sendMessage(mm.deserialize("https://spark.lucko.me/docs/Command-Usage")); // Purpur - return true; - } - if (args.length < 1) { - sender.sendMessage(text("Usage: " + this.usageMessage, NamedTextColor.RED)); - return true; - } - final String arg = args[0]; - if ("on".equalsIgnoreCase(arg)) { - Timings.setTimingsEnabled(true); - sender.sendMessage(text("Enabled Timings & Reset")); - return true; - } else if ("off".equalsIgnoreCase(arg)) { - Timings.setTimingsEnabled(false); - sender.sendMessage(text("Disabled Timings")); - return true; - } - - if (!Timings.isTimingsEnabled()) { - sender.sendMessage(text("Please enable timings by typing /timings on")); - return true; - } - - long now = System.currentTimeMillis(); - if ("verbon".equalsIgnoreCase(arg)) { - Timings.setVerboseTimingsEnabled(true); - sender.sendMessage(text("Enabled Verbose Timings")); - return true; - } else if ("verboff".equalsIgnoreCase(arg)) { - Timings.setVerboseTimingsEnabled(false); - sender.sendMessage(text("Disabled Verbose Timings")); - return true; - } else if ("reset".equalsIgnoreCase(arg)) { - if (now - lastResetAttempt < 30000) { - TimingsManager.reset(); - sender.sendMessage(text("Timings reset. Please wait 5-10 minutes before using /timings report.", NamedTextColor.RED)); - } else { - lastResetAttempt = now; - sender.sendMessage(text("WARNING: Timings v2 should not be reset. If you are experiencing lag, please wait 3 minutes and then issue a report. The best timings will include 10+ minutes, with data before and after your lag period. If you really want to reset, run this command again within 30 seconds.", NamedTextColor.RED)); - } - } else if ( - "paste".equalsIgnoreCase(arg) || - "report".equalsIgnoreCase(arg) || - "get".equalsIgnoreCase(arg) || - "merged".equalsIgnoreCase(arg) || - "separate".equalsIgnoreCase(arg) - ) { - Timings.generateReport(sender); - } else { - sender.sendMessage(text("Usage: " + this.usageMessage, NamedTextColor.RED)); - } - return true; - } - - @NotNull - @Override - public List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - Preconditions.checkNotNull(sender, "Sender cannot be null"); - Preconditions.checkNotNull(args, "Arguments cannot be null"); - Preconditions.checkNotNull(alias, "Alias cannot be null"); - - if (false && args.length == 1) { // Purpur - return StringUtil.copyPartialMatches(args[0], TIMINGS_SUBCOMMANDS, - new ArrayList(TIMINGS_SUBCOMMANDS.size())); - } - return ImmutableList.of(); - } -} diff --git a/src/main/java/co/aikar/timings/TimingsManager.java b/src/main/java/co/aikar/timings/TimingsManager.java deleted file mode 100644 index e72ad05abada04426e32a73d02b21cb69079d268..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/TimingsManager.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import co.aikar.util.LoadingMap; -import com.google.common.collect.EvictingQueue; -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.command.Command; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.PluginClassLoader; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @deprecated Timings will be removed in the future - */ -@Deprecated(forRemoval = true) -public final class TimingsManager { - static final Map TIMING_MAP = LoadingMap.of( - new ConcurrentHashMap<>(4096, .5F), TimingHandler::new - ); - public static final FullServerTickHandler FULL_SERVER_TICK = new FullServerTickHandler(); - public static final TimingHandler TIMINGS_TICK = Timings.ofSafe("Timings Tick", FULL_SERVER_TICK); - public static final Timing PLUGIN_GROUP_HANDLER = Timings.ofSafe("Plugins"); - public static String url = "https://timings.aikar.co/"; - public static List hiddenConfigs = new ArrayList(); - public static boolean privacy = false; - - static final List HANDLERS = new ArrayList<>(1024); - static final List MINUTE_REPORTS = new ArrayList<>(64); - - static EvictingQueue HISTORY = EvictingQueue.create(12); - static long timingStart = 0; - static long historyStart = 0; - static boolean needsFullReset = false; - static boolean needsRecheckEnabled = false; - - private TimingsManager() {} - - /** - * Resets all timing data on the next tick - */ - static void reset() { - needsFullReset = true; - } - - /** - * Ticked every tick by CraftBukkit to count the number of times a timer - * caused TPS loss. - */ - static void tick() { - if (Timings.timingsEnabled) { - boolean violated = FULL_SERVER_TICK.isViolated(); - - for (TimingHandler handler : HANDLERS) { - if (handler.isSpecial()) { - // We manually call this - continue; - } - handler.processTick(violated); - } - - TimingHistory.playerTicks += Bukkit.getOnlinePlayers().size(); - TimingHistory.timedTicks++; - // Generate TPS/Ping/Tick reports every minute - } - } - static void stopServer() { - Timings.timingsEnabled = false; - recheckEnabled(); - } - static void recheckEnabled() { - synchronized (TIMING_MAP) { - for (TimingHandler timings : TIMING_MAP.values()) { - timings.checkEnabled(); - } - } - needsRecheckEnabled = false; - } - static void resetTimings() { - if (needsFullReset) { - // Full resets need to re-check every handlers enabled state - // Timing map can be modified from async so we must sync on it. - synchronized (TIMING_MAP) { - for (TimingHandler timings : TIMING_MAP.values()) { - timings.reset(true); - } - } - Bukkit.getLogger().log(Level.INFO, "Timings Reset"); - HISTORY.clear(); - needsFullReset = false; - needsRecheckEnabled = false; - timingStart = System.currentTimeMillis(); - } else { - // Soft resets only need to act on timings that have done something - // Handlers can only be modified on main thread. - for (TimingHandler timings : HANDLERS) { - timings.reset(false); - } - } - - HANDLERS.clear(); - MINUTE_REPORTS.clear(); - - TimingHistory.resetTicks(true); - historyStart = System.currentTimeMillis(); - } - - @NotNull - static TimingHandler getHandler(@Nullable String group, @NotNull String name, @Nullable Timing parent) { - return TIMING_MAP.get(new TimingIdentifier(group, name, parent)); - } - - - /** - *

Due to access restrictions, we need a helper method to get a Command TimingHandler with String group

- * - * Plugins should never call this - * - * @param pluginName Plugin this command is associated with - * @param command Command to get timings for - * @return TimingHandler - */ - @NotNull - public static Timing getCommandTiming(@Nullable String pluginName, @NotNull Command command) { - Plugin plugin = null; - final Server server = Bukkit.getServer(); - if (!( server == null || pluginName == null || - "minecraft".equals(pluginName) || "bukkit".equals(pluginName) || - "spigot".equalsIgnoreCase(pluginName) || "paper".equals(pluginName) - )) { - plugin = server.getPluginManager().getPlugin(pluginName); - } - if (plugin == null) { - // Plugin is passing custom fallback prefix, try to look up by class loader - plugin = getPluginByClassloader(command.getClass()); - } - if (plugin == null) { - return Timings.ofSafe("Command: " + pluginName + ":" + command.getTimingName()); - } - - return Timings.ofSafe(plugin, "Command: " + pluginName + ":" + command.getTimingName()); - } - - /** - * Looks up the class loader for the specified class, and if it is a PluginClassLoader, return the - * Plugin that created this class. - * - * @param clazz Class to check - * @return Plugin if created by a plugin - */ - @Nullable - public static Plugin getPluginByClassloader(@Nullable Class clazz) { - if (clazz == null) { - return null; - } - final ClassLoader classLoader = clazz.getClassLoader(); - if (classLoader instanceof PluginClassLoader) { - PluginClassLoader pluginClassLoader = (PluginClassLoader) classLoader; - return pluginClassLoader.getPlugin(); - } - return null; - } -} diff --git a/src/main/java/co/aikar/timings/TimingsReportListener.java b/src/main/java/co/aikar/timings/TimingsReportListener.java index df066d6f8d55afbc0c1897c486d638657a5f8df9..2ff0c2f9771a39a01f7fee879487eaaed1fe4c8e 100644 --- a/src/main/java/co/aikar/timings/TimingsReportListener.java +++ b/src/main/java/co/aikar/timings/TimingsReportListener.java @@ -1,90 +1,3 @@ package co.aikar.timings; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.command.MessageCommandSender; -import org.bukkit.command.RemoteConsoleCommandSender; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -/** - * @deprecated Timings will be removed in the future - */ -@Deprecated(forRemoval = true) -@SuppressWarnings("WeakerAccess") -public class TimingsReportListener implements net.kyori.adventure.audience.ForwardingAudience, MessageCommandSender { - private final List senders; - private final Runnable onDone; - private String timingsURL; - - public TimingsReportListener(@NotNull CommandSender senders) { - this(senders, null); - } - public TimingsReportListener(@NotNull CommandSender sender, @Nullable Runnable onDone) { - this(Lists.newArrayList(sender), onDone); - } - public TimingsReportListener(@NotNull List senders) { - this(senders, null); - } - public TimingsReportListener(@NotNull List senders, @Nullable Runnable onDone) { - Preconditions.checkNotNull(senders); - Preconditions.checkArgument(!senders.isEmpty(), "senders is empty"); - - this.senders = Lists.newArrayList(senders); - this.onDone = onDone; - } - - @Nullable - public String getTimingsURL() { - return timingsURL; - } - - public void done() { - done(null); - } - - public void done(@Nullable String url) { - this.timingsURL = url; - if (onDone != null) { - onDone.run(); - } - for (CommandSender sender : senders) { - if (sender instanceof TimingsReportListener) { - ((TimingsReportListener) sender).done(); - } - } - } - - @Override - public void sendMessage(final @NotNull net.kyori.adventure.identity.Identity source, final @NotNull net.kyori.adventure.text.Component message, final @NotNull net.kyori.adventure.audience.MessageType type) { - net.kyori.adventure.audience.ForwardingAudience.super.sendMessage(source, message, type); - } - - @NotNull - @Override - public Iterable audiences() { - return this.senders; - } - - @Override - public void sendMessage(@NotNull String message) { - senders.forEach((sender) -> sender.sendMessage(message)); - } - - public void addConsoleIfNeeded() { - boolean hasConsole = false; - for (CommandSender sender : this.senders) { - if (sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender) { - hasConsole = true; - } - } - if (!hasConsole) { - this.senders.add(Bukkit.getConsoleSender()); - } - } -} +@Deprecated(forRemoval = true) interface TimingsReportListener {} // Plazma - Completely remove timings implementation diff --git a/src/main/java/co/aikar/timings/UnsafeTimingHandler.java b/src/main/java/co/aikar/timings/UnsafeTimingHandler.java deleted file mode 100644 index 632c4961515f5052551f841cfa840e60bba7a257..0000000000000000000000000000000000000000 --- a/src/main/java/co/aikar/timings/UnsafeTimingHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package co.aikar.timings; - -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; - -class UnsafeTimingHandler extends TimingHandler { - - UnsafeTimingHandler(@NotNull TimingIdentifier id) { - super(id); - } - - private static void checkThread() { - if (!Bukkit.isPrimaryThread()) { - throw new IllegalStateException("Calling Timings from Async Operation"); - } - } - - @NotNull - @Override - public Timing startTiming() { - checkThread(); - return super.startTiming(); - } - - @Override - public void stopTiming() { - checkThread(); - super.stopTiming(); - } -} diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java index abe256e1e45ce28036da4aa1586715bc8a1a3414..cf055d721c4c66eba9479ad88f3b6a514bf9677d 100644 --- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java +++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java @@ -12,7 +12,7 @@ public class FormattedCommandAlias extends Command { public FormattedCommandAlias(@NotNull String alias, @NotNull String[] formatStrings) { super(alias); - timings = co.aikar.timings.TimingsManager.getCommandTiming("minecraft", this); // Spigot + // timings = co.aikar.timings.TimingsManager.getCommandTiming("minecraft", this); // Spigot // Thunderbolt - Remove remaining timings implementations this.formatStrings = formatStrings; } diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java index 7740ad53796d08584bb0110f99af5639993e4d71..3806c3887d9ba58370747ed165c2a644d811f5e1 100644 --- a/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -39,7 +39,7 @@ public class SimpleCommandMap implements CommandMap { register("bukkit", new VersionCommand("version")); register("bukkit", new ReloadCommand("reload")); //register("bukkit", new PluginsCommand("plugins")); // Paper - register("bukkit", new co.aikar.timings.TimingsCommand("timings")); // Paper + //register("bukkit", new co.aikar.timings.TimingsCommand("timings")); // Paper // Plazma - Completely remove timings implementation } public void setFallbackCommands() { @@ -71,7 +71,7 @@ public class SimpleCommandMap implements CommandMap { */ @Override public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) { - command.timings = co.aikar.timings.TimingsManager.getCommandTiming(fallbackPrefix, command); // Paper + //command.timings = co.aikar.timings.TimingsManager.getCommandTiming(fallbackPrefix, command); // Paper // Plazma - Completely remove timings implementation label = label.toLowerCase(Locale.ROOT).trim(); fallbackPrefix = fallbackPrefix.toLowerCase(Locale.ROOT).trim(); boolean registered = register(label, command, false, fallbackPrefix); @@ -166,11 +166,13 @@ public class SimpleCommandMap implements CommandMap { parsedArgs = event.getArgs(); // Purpur end + /* // Plazma - Completely remove timings implementation // Paper start - Plugins do weird things to workaround normal registration if (target.timings == null) { target.timings = co.aikar.timings.TimingsManager.getCommandTiming(null, target); } // Paper end + */ // Plazma - Completely remove timings implementation try { //try (co.aikar.timings.Timing ignored = target.timings.startTiming()) { // Paper - use try with resources // Purpur diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java index 47153dee66782a00b980ecf15e8774ab6f3d887d..25d8b2f57c42890b05433fac04ce60efdc6ae34d 100644 --- a/src/main/java/org/bukkit/plugin/PluginManager.java +++ b/src/main/java/org/bukkit/plugin/PluginManager.java @@ -312,7 +312,13 @@ public interface PluginManager extends io.papermc.paper.plugin.PermissionManager * * @return True if event timings are to be used */ - public boolean useTimings(); + // Plazma start - Completely remove timings implementation + @Deprecated(forRemoval = true) + @io.papermc.paper.annotation.DoNotUse + default boolean useTimings() { + return false; + } + // Plazma end - Completely remove timings implementation // Paper start @org.jetbrains.annotations.ApiStatus.Internal diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 6b6edf9007997d9672e4c850464c1b71cb55f6b4..11b973b70ce62a6e227d343bdef6dcb9ece3f97d 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -61,7 +61,7 @@ public final class SimplePluginManager implements PluginManager { public final Map> defSubs = new HashMap>(); public PluginManager paperPluginManager; // Paper end - private boolean useTimings = false; + //private boolean useTimings = false; // Plazma - Completely remove timings implementation public SimplePluginManager(@NotNull Server instance, @NotNull SimpleCommandMap commandMap) { server = instance; @@ -718,18 +718,7 @@ public final class SimplePluginManager implements PluginManager { Preconditions.checkArgument(priority != null, "Priority cannot be null"); Preconditions.checkArgument(executor != null, "Executor cannot be null"); Preconditions.checkArgument(plugin != null, "Plugin cannot be null"); - if (true) {this.paperPluginManager.registerEvent(event, listener, priority, executor, plugin, ignoreCancelled); return;} // Paper - - if (!plugin.isEnabled()) { - throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled"); - } - - executor = new co.aikar.timings.TimedEventExecutor(executor, plugin, null, event); // Paper - if (false) { // Spigot - RL handles useTimings check now // Paper - getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled)); - } else { - getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled)); - } + this.paperPluginManager.registerEvent(event, listener, priority, executor, plugin, ignoreCancelled); // Paper // Plazma - Completely remove timings implementation } @NotNull @@ -959,8 +948,8 @@ public final class SimplePluginManager implements PluginManager { @Override public boolean useTimings() { - if (true) {return this.paperPluginManager.useTimings();} // Paper - return co.aikar.timings.Timings.isTimingsEnabled(); // Spigot + // TODO: Plazma - warn on use + return false; // Plazma - Completely remove timings implementation } /** @@ -970,7 +959,7 @@ public final class SimplePluginManager implements PluginManager { */ @Deprecated(forRemoval = true) public void useTimings(boolean use) { - co.aikar.timings.Timings.setTimingsEnabled(use); // Paper + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use Spark instead."); // Plazma - Completely remove timings implementation } // Paper start diff --git a/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java b/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java deleted file mode 100644 index 1d76e30b82ca56bb4cf3b9a33f5a129ab829e3f0..0000000000000000000000000000000000000000 --- a/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.bukkit.plugin; - -import org.bukkit.event.Event; -import org.bukkit.event.EventException; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Extends RegisteredListener to include timing information - */ -public class TimedRegisteredListener extends RegisteredListener { - private int count; - private long totalTime; - private Class eventClass; - private boolean multiple = false; - - public TimedRegisteredListener(@NotNull final Listener pluginListener, @NotNull final EventExecutor eventExecutor, @NotNull final EventPriority eventPriority, @NotNull final Plugin registeredPlugin, final boolean listenCancelled) { - super(pluginListener, eventExecutor, eventPriority, registeredPlugin, listenCancelled); - } - - @Override - public void callEvent(@NotNull Event event) throws EventException { - if (event.isAsynchronous()) { - super.callEvent(event); - return; - } - count++; - Class newEventClass = event.getClass(); - if (this.eventClass == null) { - this.eventClass = newEventClass; - } else if (!this.eventClass.equals(newEventClass)) { - multiple = true; - this.eventClass = getCommonSuperclass(newEventClass, this.eventClass).asSubclass(Event.class); - } - long start = System.nanoTime(); - super.callEvent(event); - totalTime += System.nanoTime() - start; - } - - @NotNull - private static Class getCommonSuperclass(@NotNull Class class1, @NotNull Class class2) { - while (!class1.isAssignableFrom(class2)) { - class1 = class1.getSuperclass(); - } - return class1; - } - - /** - * Resets the call count and total time for this listener - */ - public void reset() { - count = 0; - totalTime = 0; - } - - /** - * Gets the total times this listener has been called - * - * @return Times this listener has been called - */ - public int getCount() { - return count; - } - - /** - * Gets the total time calls to this listener have taken - * - * @return Total time for all calls of this listener - */ - public long getTotalTime() { - return totalTime; - } - - /** - * Gets the class of the events this listener handled. If it handled - * multiple classes of event, the closest shared superclass will be - * returned, such that for any event this listener has handled, - * this.getEventClass().isAssignableFrom(event.getClass()) - * and no class this.getEventClass().isAssignableFrom(clazz) - * {@literal && this.getEventClass() != clazz &&} - * event.getClass().isAssignableFrom(clazz) for all handled events. - * - * @return the event class handled by this RegisteredListener - */ - @Nullable - public Class getEventClass() { - return eventClass; - } - - /** - * Gets whether this listener has handled multiple events, such that for - * some two events, eventA.getClass() != eventB.getClass(). - * - * @return true if this listener has handled multiple events - */ - public boolean hasMultiple() { - return multiple; - } -} diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 0c6ca7588fb3d6b6497ddf032fe75e5c6c9719e5..e20dc7bdbd7f6040af82f638576e5ccc2d48f12f 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -39,11 +39,11 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.SimplePluginManager; -import org.bukkit.plugin.TimedRegisteredListener; +//import org.bukkit.plugin.TimedRegisteredListener; // Plazma - Completely remove timings implementation import org.bukkit.plugin.UnknownDependencyException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.spigotmc.CustomTimingsHandler; // Spigot +// import org.spigotmc.CustomTimingsHandler; // Spigot // Thunderbolt - Remove remaining timings implementations import org.yaml.snakeyaml.error.YAMLException; /** @@ -233,7 +233,7 @@ public final class JavaPluginLoader implements PluginLoader { Preconditions.checkArgument(plugin != null, "Plugin can not be null"); Preconditions.checkArgument(listener != null, "Listener can not be null"); - boolean useTimings = server.getPluginManager().useTimings(); + //boolean useTimings = server.getPluginManager().useTimings(); // Plazma - Completely remove timings implementation Map, Set> ret = new HashMap, Set>(); Set methods; try { @@ -294,26 +294,22 @@ public final class JavaPluginLoader implements PluginLoader { } } - EventExecutor executor = new co.aikar.timings.TimedEventExecutor(new EventExecutor() { // Paper - @Override - public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { // Paper - try { - if (!eventClass.isAssignableFrom(event.getClass())) { - return; - } - method.invoke(listener, event); - } catch (InvocationTargetException ex) { - throw new EventException(ex.getCause()); - } catch (Throwable t) { - throw new EventException(t); + // Thunderbolt start - Remove remaining timings implementations + // Paper + EventExecutor executor = (listener1, event) -> { // Paper + try { + if (!eventClass.isAssignableFrom(event.getClass())) { + return; } + method.invoke(listener1, event); + } catch (InvocationTargetException ex) { + throw new EventException(ex.getCause()); + } catch (Throwable t) { + throw new EventException(t); } - }, plugin, method, eventClass); // Paper - if (false) { // Spigot - RL handles useTimings check now - eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); - } else { - eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); - } + }; // Paper + eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); + // Thunderbolt end - Remove remaining timings implementations } return ret; } diff --git a/src/main/java/org/plazmamc/plazma/DeprecationException.java b/src/main/java/org/plazmamc/plazma/DeprecationException.java new file mode 100644 index 0000000000000000000000000000000000000000..70114a474f92bd605b27f7e610946c0467b78f24 --- /dev/null +++ b/src/main/java/org/plazmamc/plazma/DeprecationException.java @@ -0,0 +1,7 @@ +package org.plazmamc.plazma; + +public class DeprecationException extends RuntimeException { + public DeprecationException(String message) { + super(message); + } +} diff --git a/src/main/java/org/spigotmc/CustomTimingsHandler.java b/src/main/java/org/spigotmc/CustomTimingsHandler.java index 9c2d605c50cbf9aefa56ec209df9f6cea1392e89..d799c5131abd81a987472aaa7cf105f1e958337f 100644 --- a/src/main/java/org/spigotmc/CustomTimingsHandler.java +++ b/src/main/java/org/spigotmc/CustomTimingsHandler.java @@ -1,67 +1,28 @@ -/* - * This file is licensed under the MIT License (MIT). - * - * Copyright (c) 2014 Daniel Ennis - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ +// Plazma start - Completely remove timings implementation package org.spigotmc; -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; -import org.bukkit.plugin.AuthorNagException; -import co.aikar.timings.Timing; -import co.aikar.timings.Timings; -import co.aikar.timings.TimingsManager; +import io.papermc.paper.annotation.DoNotUse; -import java.lang.reflect.Method; -import java.util.logging.Level; - -/** - * This is here for legacy purposes incase any plugin used it. - * - * If you use this, migrate ASAP as this will be removed in the future! - * - * @deprecated - * @see co.aikar.timings.Timings#of - */ @Deprecated(forRemoval = true) public final class CustomTimingsHandler { - private final Timing handler; - public CustomTimingsHandler(@NotNull String name) { - Timing timing; + @Deprecated(forRemoval = true) + @DoNotUse + public CustomTimingsHandler(String name) { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use Spark instead."); + } - new AuthorNagException("Deprecated use of CustomTimingsHandler. Please Switch to Timings.of ASAP").printStackTrace(); - try { - final Method ofSafe = TimingsManager.class.getDeclaredMethod("getHandler", String.class, String.class, Timing.class); - ofSafe.setAccessible(true); - timing = (Timing) ofSafe.invoke(null,"Minecraft", "(Deprecated API) " + name, null); - } catch (Exception e) { - e.printStackTrace(); - Bukkit.getLogger().log(Level.SEVERE, "This handler could not be registered"); - timing = Timings.NULL_HANDLER; - } - handler = timing; + @Deprecated(forRemoval = true) + @DoNotUse + public void startTiming() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use Spark instead."); } - public void startTiming() { /*handler.startTiming();*/ } // Purpur - public void stopTiming() { /*handler.stopTiming();*/ } // Purpur + @Deprecated(forRemoval = true) + @DoNotUse + public void stopTiming() { + throw new org.plazmamc.plazma.DeprecationException("Timings are deprecated and removed. Use Spark instead."); + } } +// Plazma end - Completely remove timings implementation diff --git a/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java b/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java deleted file mode 100644 index 9ed416ed57676c845833736f93ed6088513c6da4..0000000000000000000000000000000000000000 --- a/src/test/java/org/bukkit/plugin/TimedRegisteredListenerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.bukkit.plugin; - -import static org.bukkit.support.MatcherAssert.*; -import static org.hamcrest.Matchers.*; -import org.bukkit.event.Event; -import org.bukkit.event.EventException; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.player.PlayerEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.junit.jupiter.api.Test; - -public class TimedRegisteredListenerTest { - - @Test - public void testEventClass() throws EventException { - Listener listener = new Listener() {}; - EventExecutor executor = new EventExecutor() { - @Override - public void execute(Listener listener, Event event) {} - }; - TestPlugin plugin = new TestPlugin("Test"); - - PlayerInteractEvent interactEvent = new PlayerInteractEvent(null, null, null, null, null); - PlayerMoveEvent moveEvent = new PlayerMoveEvent(null, null, null); - BlockBreakEvent breakEvent = new BlockBreakEvent(null, null); - - TimedRegisteredListener trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false); - - // Ensure that the correct event type is reported for a single event - trl.callEvent(interactEvent); - assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class)); - // Ensure that no superclass is used in lieu of the actual event, after two identical event types - trl.callEvent(interactEvent); - assertThat(trl.getEventClass(), is((Object) PlayerInteractEvent.class)); - // Ensure that the closest superclass of the two events is chosen - trl.callEvent(moveEvent); - assertThat(trl.getEventClass(), is((Object) PlayerEvent.class)); - // As above, so below - trl.callEvent(breakEvent); - assertThat(trl.getEventClass(), is((Object) Event.class)); - // In the name of being thorough, check that it never travels down the hierarchy again. - trl.callEvent(breakEvent); - assertThat(trl.getEventClass(), is((Object) Event.class)); - - trl = new TimedRegisteredListener(listener, executor, EventPriority.NORMAL, plugin, false); - - trl.callEvent(breakEvent); - assertThat(trl.getEventClass(), is((Object) BlockBreakEvent.class)); - // Test moving up the class hierarchy by more than one class at a time - trl.callEvent(moveEvent); - assertThat(trl.getEventClass(), is((Object) Event.class)); - } -}