aboutsummaryrefslogtreecommitdiff
path: root/spark-forge
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-02-04 00:49:40 +0000
committerLuck <git@lucko.me>2020-02-04 00:49:40 +0000
commite02d52ce8d45550a4d77f11971e31cf0732e5f0c (patch)
treecfcfb2850ff6b279276e43233e5e1acf82993a98 /spark-forge
parentd15a12788ddc8aba09f49003fcef55b927850de3 (diff)
downloadspark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.gz
spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.tar.bz2
spark-e02d52ce8d45550a4d77f11971e31cf0732e5f0c.zip
Monitor average tick durations & report them in /spark tps
Diffstat (limited to 'spark-forge')
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickHook.java (renamed from spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickCounter.java)8
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickReporter.java71
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java15
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java15
4 files changed, 97 insertions, 12 deletions
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickCounter.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickHook.java
index 7e387a7..910b5b5 100644
--- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickCounter.java
+++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickHook.java
@@ -20,16 +20,16 @@
package me.lucko.spark.forge;
-import me.lucko.spark.common.sampler.AbstractTickCounter;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.AbstractTickHook;
+import me.lucko.spark.common.sampler.tick.TickHook;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
-public class ForgeTickCounter extends AbstractTickCounter implements TickCounter {
+public class ForgeTickHook extends AbstractTickHook implements TickHook {
private final TickEvent.Type type;
- public ForgeTickCounter(TickEvent.Type type) {
+ public ForgeTickHook(TickEvent.Type type) {
this.type = type;
}
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickReporter.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickReporter.java
new file mode 100644
index 0000000..8e0b36f
--- /dev/null
+++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeTickReporter.java
@@ -0,0 +1,71 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.forge;
+
+import me.lucko.spark.common.sampler.tick.AbstractTickReporter;
+import me.lucko.spark.common.sampler.tick.TickReporter;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+
+public class ForgeTickReporter extends AbstractTickReporter implements TickReporter {
+ private final TickEvent.Type type;
+
+ private long start = 0;
+
+ public ForgeTickReporter(TickEvent.Type type) {
+ this.type = type;
+ }
+
+ @SubscribeEvent
+ public void onTick(TickEvent e) {
+ if (e.type != this.type) {
+ return;
+ }
+
+ switch (e.phase) {
+ case START:
+ this.start = System.nanoTime();
+ break;
+ case END:
+ if (this.start == 0) {
+ return;
+ }
+
+ double duration = (System.nanoTime() - this.start) / 1000000d;
+ onTick(duration);
+ break;
+ default:
+ throw new AssertionError(e.phase);
+ }
+ }
+
+ @Override
+ public void start() {
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ @Override
+ public void close() {
+ MinecraftForge.EVENT_BUS.unregister(this);
+ }
+
+}
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java
index 2b6220a..070c28a 100644
--- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java
+++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java
@@ -27,10 +27,12 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.TickHook;
+import me.lucko.spark.common.sampler.tick.TickReporter;
import me.lucko.spark.forge.ForgeCommandSender;
import me.lucko.spark.forge.ForgeSparkMod;
-import me.lucko.spark.forge.ForgeTickCounter;
+import me.lucko.spark.forge.ForgeTickHook;
+import me.lucko.spark.forge.ForgeTickReporter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.play.ClientPlayNetHandler;
import net.minecraft.command.ICommandSource;
@@ -132,8 +134,13 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Suggesti
}
@Override
- public TickCounter createTickCounter() {
- return new ForgeTickCounter(TickEvent.Type.CLIENT);
+ public TickHook createTickHook() {
+ return new ForgeTickHook(TickEvent.Type.CLIENT);
+ }
+
+ @Override
+ public TickReporter createTickReporter() {
+ return new ForgeTickReporter(TickEvent.Type.CLIENT);
}
@Override
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java
index a2aafb2..27489fb 100644
--- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java
+++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java
@@ -27,10 +27,12 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
-import me.lucko.spark.common.sampler.TickCounter;
+import me.lucko.spark.common.sampler.tick.TickHook;
+import me.lucko.spark.common.sampler.tick.TickReporter;
import me.lucko.spark.forge.ForgeCommandSender;
import me.lucko.spark.forge.ForgeSparkMod;
-import me.lucko.spark.forge.ForgeTickCounter;
+import me.lucko.spark.forge.ForgeTickHook;
+import me.lucko.spark.forge.ForgeTickReporter;
import net.minecraft.command.CommandSource;
import net.minecraft.command.ICommandSource;
import net.minecraft.entity.player.PlayerEntity;
@@ -116,8 +118,13 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command<
}
@Override
- public TickCounter createTickCounter() {
- return new ForgeTickCounter(TickEvent.Type.SERVER);
+ public TickHook createTickHook() {
+ return new ForgeTickHook(TickEvent.Type.SERVER);
+ }
+
+ @Override
+ public TickReporter createTickReporter() {
+ return new ForgeTickReporter(TickEvent.Type.SERVER);
}
@Override