diff options
Diffstat (limited to 'src/main/java/at')
3 files changed, 55 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java index 7f7b9af63..bdce11628 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java @@ -85,4 +85,10 @@ public class DebugConfig { @ConfigOption(name = "Hot Swap Detection", desc = "Show chat messages when Hot Swap starts and ends.") @ConfigEditorBoolean public boolean hotSwapDetection = false; + + @Expose + @ConfigOption(name = "SkyHanni Event Counter", desc = "Count once per second how many skyhanni events gets triggered, " + + "show the total amount in console output.") + @ConfigEditorBoolean + public boolean eventCounter = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt b/src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt new file mode 100644 index 000000000..70de5e436 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt @@ -0,0 +1,46 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import kotlin.time.Duration.Companion.seconds + +object EventCounter { + private val config get() = SkyHanniMod.feature.dev.debug + + private var map = mutableMapOf<String, Int>() + private var lastUpdate = SimpleTimeMark.farPast() + + fun count(eventName: String) { + if (!isEnabled()) return + + map.addOrPut(eventName, 1) + + if (lastUpdate == SimpleTimeMark.farPast()) { + lastUpdate = SimpleTimeMark.now() + } + + if (lastUpdate.passedSince() > 1.seconds) { + lastUpdate = SimpleTimeMark.now() + + print(map) + + map.clear() + } + } + + private fun print(map: MutableMap<String, Int>) { + println("") + var total = 0 + for ((name, amount) in map.entries.sortedBy { it.value }) { + println("$name (${amount.addSeparators()} times)") + total += amount + } + println("") + println("total: ${total.addSeparators()}") + } + + private fun isEnabled() = LorenzUtils.onHypixel && config.eventCounter +} diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt index 21f9d07e8..766da4c14 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.events +import at.hannibal2.skyhanni.data.EventCounter import at.hannibal2.skyhanni.mixins.transformers.AccessorEventBus import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.LorenzUtils @@ -10,7 +11,7 @@ import net.minecraftforge.fml.common.eventhandler.IEventListener abstract class LorenzEvent : Event() { private val eventName by lazy { - this::class.simpleName + this::class.simpleName!! } fun postAndCatch() = postAndCatchAndBlock {} @@ -21,6 +22,7 @@ abstract class LorenzEvent : Event() { ignoreErrorCache: Boolean = false, onError: (Throwable) -> Unit, ): Boolean { + EventCounter.count(eventName) val visibleErrors = 3 var errors = 0 for (listener in getListeners()) { |