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/sponge/SpongeSparkPlugin.java | 9 ++-- .../me/lucko/spark/sponge/SpongeTickCounter.java | 50 ---------------------- .../java/me/lucko/spark/sponge/SpongeTickHook.java | 50 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 54 deletions(-) delete mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java (limited to 'spark-sponge') diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java index d221f04..ae0efef 100644 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java @@ -24,7 +24,7 @@ import com.google.inject.Inject; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.SparkPlugin; import me.lucko.spark.common.sampler.ThreadDumper; -import me.lucko.spark.common.sampler.TickCounter; +import me.lucko.spark.common.sampler.tick.TickHook; import org.spongepowered.api.Game; import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandResult; @@ -41,12 +41,13 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; -import javax.annotation.Nullable; import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.stream.Stream; +import javax.annotation.Nullable; + @Plugin( id = "spark", name = "spark", @@ -119,8 +120,8 @@ public class SpongeSparkPlugin implements SparkPlugin { } @Override - public TickCounter createTickCounter() { - return new SpongeTickCounter(this); + public TickHook createTickHook() { + return new SpongeTickHook(this); } private static final class SparkCommand implements CommandCallable { diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java deleted file mode 100644 index d7823b1..0000000 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickCounter.java +++ /dev/null @@ -1,50 +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.sponge; - -import me.lucko.spark.common.sampler.AbstractTickCounter; -import me.lucko.spark.common.sampler.TickCounter; -import org.spongepowered.api.scheduler.Task; - -public class SpongeTickCounter extends AbstractTickCounter implements TickCounter, Runnable { - private final SpongeSparkPlugin plugin; - private Task task; - - public SpongeTickCounter(SpongeSparkPlugin plugin) { - this.plugin = plugin; - } - - @Override - public void run() { - onTick(); - } - - @Override - public void start() { - this.task = Task.builder().intervalTicks(1).name("spark-ticker").execute(this).submit(this.plugin); - } - - @Override - public void close() { - this.task.cancel(); - } - -} diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java new file mode 100644 index 0000000..2fdc459 --- /dev/null +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java @@ -0,0 +1,50 @@ +/* + * 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.sponge; + +import me.lucko.spark.common.sampler.tick.AbstractTickHook; +import me.lucko.spark.common.sampler.tick.TickHook; +import org.spongepowered.api.scheduler.Task; + +public class SpongeTickHook extends AbstractTickHook implements TickHook, Runnable { + private final SpongeSparkPlugin plugin; + private Task task; + + public SpongeTickHook(SpongeSparkPlugin plugin) { + this.plugin = plugin; + } + + @Override + public void run() { + onTick(); + } + + @Override + public void start() { + this.task = Task.builder().intervalTicks(1).name("spark-ticker").execute(this).submit(this.plugin); + } + + @Override + public void close() { + this.task.cancel(); + } + +} -- cgit