diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-04 03:16:04 +0100 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-04 03:16:04 +0100 |
| commit | 04a7e098fb49d0aa26678c07932f7a6de2940a6d (patch) | |
| tree | fb31edba75b666a1f23375d44a7f9127787fc069 /src/main/java/at/hannibal2/skyhanni/data | |
| parent | 1f9c097cb6e24bba4496b029b156052410df2629 (diff) | |
| download | skyhanni-04a7e098fb49d0aa26678c07932f7a6de2940a6d.tar.gz skyhanni-04a7e098fb49d0aa26678c07932f7a6de2940a6d.tar.bz2 skyhanni-04a7e098fb49d0aa26678c07932f7a6de2940a6d.zip | |
Added the debug feature SkyHanni Event Counter.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt | 46 |
1 files changed, 46 insertions, 0 deletions
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 +} |
