Run timings reports after end of tick

I believe we are getting data corruption by doing it in the middle of the tick, as I was seeing
really odd reports from automated ones vs command ones.

This will break issueing timings over rcon single command mode and getting the report link in the response back

But I will try to restore that (and make RCON no longer cause spikes) soon.

Reports will still generate, just because its async, the RCON connection
will drop if not in terminal mode before its done.
This commit is contained in:
Aikar 2017-02-04 20:46:27 -05:00
parent d3544dad18
commit f938ae30fd

View file

@ -1,4 +1,4 @@
From 814a2afee3c6dd679eda99f04850f658b9a947e3 Mon Sep 17 00:00:00 2001
From 54d8f0c3b52d8bd1d3e4afee2c6c3489da1c3577 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 29 Feb 2016 18:48:17 -0600
Subject: [PATCH] Timings v2
@ -6,10 +6,10 @@ Subject: [PATCH] Timings v2
diff --git a/src/main/java/co/aikar/timings/FullServerTickHandler.java b/src/main/java/co/aikar/timings/FullServerTickHandler.java
new file mode 100644
index 0000000..e5a98af
index 00000000..4d8b633e
--- /dev/null
+++ b/src/main/java/co/aikar/timings/FullServerTickHandler.java
@@ -0,0 +1,81 @@
@@ -0,0 +1,82 @@
+package co.aikar.timings;
+
+import static co.aikar.timings.TimingsManager.*;
@ -85,6 +85,7 @@ index 0000000..e5a98af
+ TimingsManager.HISTORY.add(new TimingHistory());
+ TimingsManager.resetTimings();
+ }
+ TimingsExport.reportTimings();
+ }
+
+ boolean isViolated() {
@ -93,7 +94,7 @@ index 0000000..e5a98af
+}
diff --git a/src/main/java/co/aikar/timings/NullTimingHandler.java b/src/main/java/co/aikar/timings/NullTimingHandler.java
new file mode 100644
index 0000000..8c43e20
index 00000000..8c43e206
--- /dev/null
+++ b/src/main/java/co/aikar/timings/NullTimingHandler.java
@@ -0,0 +1,61 @@
@ -160,7 +161,7 @@ index 0000000..8c43e20
+}
diff --git a/src/main/java/co/aikar/timings/TimedEventExecutor.java b/src/main/java/co/aikar/timings/TimedEventExecutor.java
new file mode 100644
index 0000000..96057fc
index 00000000..96057fc7
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimedEventExecutor.java
@@ -0,0 +1,81 @@
@ -247,7 +248,7 @@ index 0000000..96057fc
+}
diff --git a/src/main/java/co/aikar/timings/Timing.java b/src/main/java/co/aikar/timings/Timing.java
new file mode 100644
index 0000000..8b2d1b8
index 00000000..8b2d1b82
--- /dev/null
+++ b/src/main/java/co/aikar/timings/Timing.java
@@ -0,0 +1,72 @@
@ -325,7 +326,7 @@ index 0000000..8b2d1b8
+}
diff --git a/src/main/java/co/aikar/timings/TimingData.java b/src/main/java/co/aikar/timings/TimingData.java
new file mode 100644
index 0000000..f222d6b
index 00000000..f222d6b7
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingData.java
@@ -0,0 +1,120 @@
@ -451,7 +452,7 @@ index 0000000..f222d6b
+}
diff --git a/src/main/java/co/aikar/timings/TimingHandler.java b/src/main/java/co/aikar/timings/TimingHandler.java
new file mode 100644
index 0000000..916b6f9
index 00000000..916b6f9d
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingHandler.java
@@ -0,0 +1,209 @@
@ -666,7 +667,7 @@ index 0000000..916b6f9
+}
diff --git a/src/main/java/co/aikar/timings/TimingHistory.java b/src/main/java/co/aikar/timings/TimingHistory.java
new file mode 100644
index 0000000..389875b
index 00000000..389875b3
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingHistory.java
@@ -0,0 +1,342 @@
@ -1014,7 +1015,7 @@ index 0000000..389875b
+}
diff --git a/src/main/java/co/aikar/timings/TimingHistoryEntry.java b/src/main/java/co/aikar/timings/TimingHistoryEntry.java
new file mode 100644
index 0000000..0e114eb
index 00000000..0e114eb3
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingHistoryEntry.java
@@ -0,0 +1,55 @@
@ -1075,7 +1076,7 @@ index 0000000..0e114eb
+}
diff --git a/src/main/java/co/aikar/timings/TimingIdentifier.java b/src/main/java/co/aikar/timings/TimingIdentifier.java
new file mode 100644
index 0000000..623dda4
index 00000000..623dda49
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingIdentifier.java
@@ -0,0 +1,102 @@
@ -1183,10 +1184,10 @@ index 0000000..623dda4
+}
diff --git a/src/main/java/co/aikar/timings/Timings.java b/src/main/java/co/aikar/timings/Timings.java
new file mode 100644
index 0000000..4e5cf35
index 00000000..483e3669
--- /dev/null
+++ b/src/main/java/co/aikar/timings/Timings.java
@@ -0,0 +1,273 @@
@@ -0,0 +1,274 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
@ -1221,7 +1222,7 @@ index 0000000..4e5cf35
+import java.util.Queue;
+import java.util.logging.Level;
+
+@SuppressWarnings("UnusedDeclaration")
+@SuppressWarnings({"UnusedDeclaration", "WeakerAccess", "SameParameterValue"})
+public final class Timings {
+
+ private static final int MAX_HISTORY_FRAMES = 12;
@ -1430,7 +1431,8 @@ index 0000000..4e5cf35
+ if (sender == null) {
+ sender = Bukkit.getConsoleSender();
+ }
+ TimingsExport.reportTimings(sender);
+ // Schedule report for end of tick
+ TimingsExport.requestingReport.add(sender);
+ }
+
+ /*
@ -1462,7 +1464,7 @@ index 0000000..4e5cf35
+}
diff --git a/src/main/java/co/aikar/timings/TimingsCommand.java b/src/main/java/co/aikar/timings/TimingsCommand.java
new file mode 100644
index 0000000..1fa0eb5
index 00000000..56b10e89
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingsCommand.java
@@ -0,0 +1,119 @@
@ -1565,7 +1567,7 @@ index 0000000..1fa0eb5
+ "merged".equalsIgnoreCase(arg) ||
+ "separate".equalsIgnoreCase(arg)
+ ) {
+ TimingsExport.reportTimings(sender);
+ Timings.generateReport(sender);
+ } else {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ }
@ -1587,10 +1589,10 @@ index 0000000..1fa0eb5
+}
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
new file mode 100644
index 0000000..a4a7fea
index 00000000..9dd36419
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
@@ -0,0 +1,388 @@
@@ -0,0 +1,394 @@
+/*
+ * This file is licensed under the MIT License (MIT).
+ *
@ -1617,6 +1619,7 @@ index 0000000..a4a7fea
+package co.aikar.timings;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
@ -1624,6 +1627,7 @@ index 0000000..a4a7fea
+import org.bukkit.Material;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.command.MultiMessageCommandSender;
+import org.bukkit.command.RemoteConsoleCommandSender;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.MemorySection;
@ -1658,6 +1662,7 @@ index 0000000..a4a7fea
+ private final Map out;
+ private final TimingHistory[] history;
+ private static long lastReport = 0;
+ final static List<CommandSender> requestingReport = Lists.newArrayList();
+
+ private TimingsExport(CommandSender sender, Map out, TimingHistory[] history) {
+ super("Timings paste thread");
@ -1667,11 +1672,14 @@ index 0000000..a4a7fea
+ }
+
+ /**
+ * Builds an XML report of the timings to be uploaded for parsing.
+ *
+ * @param sender Who to report to
+ * Checks if any pending reports are being requested, and builds one if needed.
+ */
+ static void reportTimings(CommandSender sender) {
+ static void reportTimings() {
+ if (requestingReport.isEmpty()) {
+ return;
+ }
+ CommandSender sender = new MultiMessageCommandSender(requestingReport);
+ requestingReport.clear();
+ long now = System.currentTimeMillis();
+ final long lastReportDiff = now - lastReport;
+ if (lastReportDiff < 60000) {
@ -1981,7 +1989,7 @@ index 0000000..a4a7fea
+}
diff --git a/src/main/java/co/aikar/timings/TimingsManager.java b/src/main/java/co/aikar/timings/TimingsManager.java
new file mode 100644
index 0000000..58ed35e
index 00000000..58ed35e0
--- /dev/null
+++ b/src/main/java/co/aikar/timings/TimingsManager.java
@@ -0,0 +1,196 @@
@ -2183,7 +2191,7 @@ index 0000000..58ed35e
+}
diff --git a/src/main/java/co/aikar/timings/UnsafeTimingHandler.java b/src/main/java/co/aikar/timings/UnsafeTimingHandler.java
new file mode 100644
index 0000000..5edaba1
index 00000000..5edaba12
--- /dev/null
+++ b/src/main/java/co/aikar/timings/UnsafeTimingHandler.java
@@ -0,0 +1,51 @@
@ -2240,7 +2248,7 @@ index 0000000..5edaba1
+}
diff --git a/src/main/java/co/aikar/util/JSONUtil.java b/src/main/java/co/aikar/util/JSONUtil.java
new file mode 100644
index 0000000..5fdf7c4
index 00000000..5fdf7c4c
--- /dev/null
+++ b/src/main/java/co/aikar/util/JSONUtil.java
@@ -0,0 +1,123 @@
@ -2369,7 +2377,7 @@ index 0000000..5fdf7c4
+}
diff --git a/src/main/java/co/aikar/util/LoadingIntMap.java b/src/main/java/co/aikar/util/LoadingIntMap.java
new file mode 100644
index 0000000..79fa9d5
index 00000000..79fa9d52
--- /dev/null
+++ b/src/main/java/co/aikar/util/LoadingIntMap.java
@@ -0,0 +1,70 @@
@ -2445,7 +2453,7 @@ index 0000000..79fa9d5
+}
diff --git a/src/main/java/co/aikar/util/LoadingMap.java b/src/main/java/co/aikar/util/LoadingMap.java
new file mode 100644
index 0000000..a9f2919
index 00000000..a9f29199
--- /dev/null
+++ b/src/main/java/co/aikar/util/LoadingMap.java
@@ -0,0 +1,332 @@
@ -2783,7 +2791,7 @@ index 0000000..a9f2919
+}
diff --git a/src/main/java/co/aikar/util/MRUMapCache.java b/src/main/java/co/aikar/util/MRUMapCache.java
new file mode 100644
index 0000000..3a288d2
index 00000000..3a288d2a
--- /dev/null
+++ b/src/main/java/co/aikar/util/MRUMapCache.java
@@ -0,0 +1,100 @@
@ -2888,7 +2896,7 @@ index 0000000..3a288d2
+ }
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 5b6413b..7fd544e 100644
index 5b6413be..7fd544eb 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -538,7 +538,6 @@ public final class Bukkit {
@ -2900,7 +2908,7 @@ index 5b6413b..7fd544e 100644
/**
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 120dba2..77cfe56 100644
index 120dba25..77cfe561 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -943,12 +943,27 @@ public interface Server extends PluginMessageRecipient {
@ -2933,7 +2941,7 @@ index 120dba2..77cfe56 100644
* Sends the component to the player
*
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index 08a9739..347d218 100644
index 08a9739f..347d2189 100644
--- a/src/main/java/org/bukkit/command/Command.java
+++ b/src/main/java/org/bukkit/command/Command.java
@@ -32,7 +32,8 @@ public abstract class Command {
@ -2963,7 +2971,7 @@ index 08a9739..347d218 100644
return true;
}
diff --git a/src/main/java/org/bukkit/command/FormattedCommandAlias.java b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
index 3f07d7f..f89ad07 100644
index 3f07d7f4..f89ad075 100644
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
@@ -14,6 +14,7 @@ public class FormattedCommandAlias extends Command {
@ -2984,8 +2992,128 @@ index 3f07d7f..f89ad07 100644
private static boolean inRange(int i, int j, int k) {
return i >= j && i <= k;
}
diff --git a/src/main/java/org/bukkit/command/MultiMessageCommandSender.java b/src/main/java/org/bukkit/command/MultiMessageCommandSender.java
new file mode 100644
index 00000000..7b512fd4
--- /dev/null
+++ b/src/main/java/org/bukkit/command/MultiMessageCommandSender.java
@@ -0,0 +1,114 @@
+package org.bukkit.command;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.commons.lang.Validate;
+import org.bukkit.Bukkit;
+import org.bukkit.Server;
+import org.bukkit.permissions.Permission;
+import org.bukkit.permissions.PermissionAttachment;
+import org.bukkit.permissions.PermissionAttachmentInfo;
+import org.bukkit.plugin.Plugin;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Used for proxying messages to multiple senders.
+ * Do not use this for anything else but messages.
+ */
+public class MultiMessageCommandSender implements CommandSender {
+ private final List<CommandSender> senders;
+
+ public MultiMessageCommandSender(List<CommandSender> senders) {
+ Validate.notNull(senders);
+ Validate.notEmpty(senders);
+
+ this.senders = Lists.newArrayList(senders);
+ }
+
+ @Override
+ public void sendMessage(String message) {
+ senders.forEach((sender) -> sender.sendMessage(message));
+ }
+
+ @Override
+ public void sendMessage(String[] messages) {
+ senders.forEach((sender) -> sender.sendMessage(messages));
+ }
+
+ @Override
+ public Server getServer() {
+ return Bukkit.getServer();
+ }
+
+ @Override
+ public String getName() {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public boolean isOp() {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void setOp(boolean value) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public boolean isPermissionSet(String name) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public boolean isPermissionSet(Permission perm) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public boolean hasPermission(String name) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public boolean hasPermission(Permission perm) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public PermissionAttachment addAttachment(Plugin plugin) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void removeAttachment(PermissionAttachment attachment) {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void recalculatePermissions() {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Set<PermissionAttachmentInfo> getEffectivePermissions() {
+ throw new NotImplementedException();
+ }
+}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index 5965514..466757b 100644
index 5965514a..466757b9 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -31,7 +31,7 @@ public class SimpleCommandMap implements CommandMap {
@ -3020,7 +3148,7 @@ index 5965514..466757b 100644
// Note: we don't return the result of target.execute as thats success / failure, we return handled (true) or not handled (false)
diff --git a/src/main/java/org/bukkit/command/defaults/TimingsCommand.java b/src/main/java/org/bukkit/command/defaults/TimingsCommand.java
deleted file mode 100644
index a8f61f2..0000000
index a8f61f2d..00000000
--- a/src/main/java/org/bukkit/command/defaults/TimingsCommand.java
+++ /dev/null
@@ -1,253 +0,0 @@
@ -3278,7 +3406,7 @@ index a8f61f2..0000000
- // Spigot end
-}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 5a2dc32..5fbad9f 100644
index 5a2dc327..5fbad9f5 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -1443,6 +1443,11 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
@ -3294,7 +3422,7 @@ index 5a2dc32..5fbad9f 100644
Spigot spigot();
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index 1056186..4ee123e 100644
index 10561864..4ee123e4 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -295,7 +295,6 @@ public final class SimplePluginManager implements PluginManager {
@ -3351,7 +3479,7 @@ index 1056186..4ee123e 100644
}
}
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index 80c6a72..759c461 100644
index 80c6a72e..759c4617 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -40,7 +40,6 @@ import org.bukkit.plugin.PluginLoader;
@ -3400,7 +3528,7 @@ index 80c6a72..759c461 100644
eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
} else {
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index 4cffa13..b2cbf9e 100644
index 4cffa137..b2cbf9e4 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -15,7 +15,8 @@ import org.bukkit.plugin.PluginDescriptionFile;
@ -3414,7 +3542,7 @@ index 4cffa13..b2cbf9e 100644
private final Map<String, Class<?>> classes = new java.util.concurrent.ConcurrentHashMap<String, Class<?>>(); // Spigot
private final PluginDescriptionFile description;
diff --git a/src/main/java/org/bukkit/util/CachedServerIcon.java b/src/main/java/org/bukkit/util/CachedServerIcon.java
index 5ca863b..0480470 100644
index 5ca863b3..04804706 100644
--- a/src/main/java/org/bukkit/util/CachedServerIcon.java
+++ b/src/main/java/org/bukkit/util/CachedServerIcon.java
@@ -12,4 +12,6 @@ import org.bukkit.event.server.ServerListPingEvent;
@ -3426,7 +3554,7 @@ index 5ca863b..0480470 100644
+ public String getData(); // Spigot
+}
diff --git a/src/main/java/org/spigotmc/CustomTimingsHandler.java b/src/main/java/org/spigotmc/CustomTimingsHandler.java
index 8d98297..7e89b97 100644
index 8d982974..7e89b97b 100644
--- a/src/main/java/org/spigotmc/CustomTimingsHandler.java
+++ b/src/main/java/org/spigotmc/CustomTimingsHandler.java
@@ -1,165 +1,76 @@
@ -3656,5 +3784,5 @@ index 8d98297..7e89b97 100644
- }
}
--
2.9.3
2.11.0