From e02d52ce8d45550a4d77f11971e31cf0732e5f0c Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 4 Feb 2020 00:49:40 +0000 Subject: Monitor average tick durations & report them in /spark tps --- .../me/lucko/spark/fabric/FabricTickCounter.java | 66 ---------------------- .../java/me/lucko/spark/fabric/FabricTickHook.java | 66 ++++++++++++++++++++++ .../fabric/plugin/FabricClientSparkPlugin.java | 8 +-- .../fabric/plugin/FabricServerSparkPlugin.java | 8 +-- 4 files changed, 74 insertions(+), 74 deletions(-) delete mode 100644 spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickCounter.java create mode 100644 spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickHook.java (limited to 'spark-fabric/src') diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickCounter.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickCounter.java deleted file mode 100644 index 7781e03..0000000 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickCounter.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.fabric; - -import me.lucko.spark.common.sampler.AbstractTickCounter; -import me.lucko.spark.common.sampler.TickCounter; -import net.fabricmc.fabric.api.event.client.ClientTickCallback; -import net.fabricmc.fabric.api.event.server.ServerTickCallback; -import net.minecraft.client.MinecraftClient; -import net.minecraft.server.MinecraftServer; - -public abstract class FabricTickCounter extends AbstractTickCounter implements TickCounter { - - protected boolean closed = false; - - @Override - public void close() { - this.closed = true; - } - - public static final class Server extends FabricTickCounter implements ServerTickCallback { - @Override - public void tick(MinecraftServer minecraftServer) { - if (!this.closed) { - onTick(); - } - } - - @Override - public void start() { - ServerTickCallback.EVENT.register(this); - } - } - - public static final class Client extends FabricTickCounter implements ClientTickCallback { - @Override - public void tick(MinecraftClient minecraftClient) { - if (!this.closed) { - onTick(); - } - } - - @Override - public void start() { - ClientTickCallback.EVENT.register(this); - } - } -} diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickHook.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickHook.java new file mode 100644 index 0000000..17c286f --- /dev/null +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricTickHook.java @@ -0,0 +1,66 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * 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 . + */ + +package me.lucko.spark.fabric; + +import me.lucko.spark.common.sampler.tick.AbstractTickHook; +import me.lucko.spark.common.sampler.tick.TickHook; +import net.fabricmc.fabric.api.event.client.ClientTickCallback; +import net.fabricmc.fabric.api.event.server.ServerTickCallback; +import net.minecraft.client.MinecraftClient; +import net.minecraft.server.MinecraftServer; + +public abstract class FabricTickHook extends AbstractTickHook implements TickHook { + + protected boolean closed = false; + + @Override + public void close() { + this.closed = true; + } + + public static final class Server extends FabricTickHook implements ServerTickCallback { + @Override + public void tick(MinecraftServer minecraftServer) { + if (!this.closed) { + onTick(); + } + } + + @Override + public void start() { + ServerTickCallback.EVENT.register(this); + } + } + + public static final class Client extends FabricTickHook implements ClientTickCallback { + @Override + public void tick(MinecraftClient minecraftClient) { + if (!this.closed) { + onTick(); + } + } + + @Override + public void start() { + ClientTickCallback.EVENT.register(this); + } + } +} diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java index 8cacc62..88454a8 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java @@ -27,11 +27,11 @@ 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.fabric.FabricCommandSender; import me.lucko.spark.fabric.FabricSparkGameHooks; import me.lucko.spark.fabric.FabricSparkMod; -import me.lucko.spark.fabric.FabricTickCounter; +import me.lucko.spark.fabric.FabricTickHook; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.server.command.CommandOutput; @@ -122,8 +122,8 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Sugges } @Override - public TickCounter createTickCounter() { - return new FabricTickCounter.Client(); + public TickHook createTickHook() { + return new FabricTickHook.Client(); } @Override diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java index 6399198..5db40af 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java @@ -26,10 +26,10 @@ 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.fabric.FabricCommandSender; import me.lucko.spark.fabric.FabricSparkMod; -import me.lucko.spark.fabric.FabricTickCounter; +import me.lucko.spark.fabric.FabricTickHook; import net.fabricmc.fabric.api.registry.CommandRegistry; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; @@ -111,8 +111,8 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman } @Override - public TickCounter createTickCounter() { - return new FabricTickCounter.Server(); + public TickHook createTickHook() { + return new FabricTickHook.Server(); } @Override -- cgit