diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-12-29 04:03:32 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-12-29 04:03:32 +0100 |
commit | e3d18c673d90d2eae5c4548ac00bc27da6c330f9 (patch) | |
tree | 5eb85aaff38b237305b2d43b42383e661a4925ad /src/main/java/at | |
parent | e645055ab82b2f6f5d8173a72db0ef7088e25f9a (diff) | |
download | skyhanni-e3d18c673d90d2eae5c4548ac00bc27da6c330f9.tar.gz skyhanni-e3d18c673d90d2eae5c4548ac00bc27da6c330f9.tar.bz2 skyhanni-e3d18c673d90d2eae5c4548ac00bc27da6c330f9.zip |
added event timings print for debug
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/DevData.java | 5 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt | 29 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java b/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java index 30672ac2e..85b527947 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/DevData.java @@ -123,4 +123,9 @@ public class DevData { @ConfigEditorBoolean @ConfigAccordionId(id = 2) public boolean filterBiomeIdBounds = false; + + @Expose + @ConfigOption(name = "Print Event Timings", desc = "Prints every 10 seconds the timings of all SkyHanni events in the chat.") + @ConfigEditorBoolean + public boolean printEventTimings = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt index 506894a9a..fc130de50 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt @@ -1,17 +1,42 @@ package at.hannibal2.skyhanni.events +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.test.GriffinJavaUtils import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.Event -abstract class LorenzEvent: Event() { +abstract class LorenzEvent : Event() { + + companion object { + val map = mutableMapOf<String, Long>() + var lastPrint = 0L + } + private val eventName by lazy { this::class.simpleName } fun postAndCatch(): Boolean { return runCatching { - MinecraftForge.EVENT_BUS.post(this) + if (!SkyHanniMod.feature.dev.printEventTimings) { + return MinecraftForge.EVENT_BUS.post(this) + } + val start = System.currentTimeMillis() + val result = MinecraftForge.EVENT_BUS.post(this) + val end = System.currentTimeMillis() - start + eventName?.let { map.put(it, end + map.getOrDefault(it, 0)) } + if (System.currentTimeMillis() > lastPrint + 10_000) { + lastPrint = System.currentTimeMillis() + println(" ") + println("Event Timings!") + for (entry in GriffinJavaUtils.sortByValue(map)) { + println(entry.key + ": " + entry.value + " ms") + } + println(" ") + map.clear() + } + result }.onFailure { it.printStackTrace() LorenzUtils.chat("§cSkyHanni caught and logged an ${it::class.simpleName ?: "error"} at ${eventName}.") |