diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt index 95251b093..2e0ec5358 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt @@ -31,8 +31,8 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.elements.bossbar.BossbarLayout import de.bixilon.minosoft.gui.rendering.gui.hud.elements.chat.ChatElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.hotbar.HotbarElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.CrosshairHUDElement -import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.DebugHUDElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.PerformanceHUDElement +import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.debug.DebugHUDElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.scoreboard.ScoreboardSideElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.tab.TabListElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.title.TitleElement diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt index cbd6ec8cd..a7e14ad3e 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/CrosshairHUDElement.kt @@ -24,6 +24,7 @@ import de.bixilon.minosoft.gui.rendering.gui.atlas.AtlasElement import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.CustomHUDElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder +import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.debug.DebugHUDElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMesh import de.bixilon.minosoft.gui.rendering.system.base.BlendingFunctions import de.bixilon.minosoft.util.KUtil.toResourceLocation diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/PerformanceHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/PerformanceHUDElement.kt index e64837ccc..bf13bc8c7 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/PerformanceHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/PerformanceHUDElement.kt @@ -24,6 +24,7 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.Pollable import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder +import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.debug.DebugHUDElement import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.util.KUtil.toResourceLocation diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/debug/AllocationRate.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/debug/AllocationRate.kt new file mode 100644 index 000000000..d19acb243 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/debug/AllocationRate.kt @@ -0,0 +1,40 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 Moritz Zwerger + * + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.debug + +import de.bixilon.kutil.concurrent.schedule.RepeatedTask +import de.bixilon.kutil.concurrent.schedule.TaskScheduler + +object AllocationRate { + const val RUNS_PER_SECOND = 3 + private val RUNTIME = Runtime.getRuntime() + var allocationRate = 0L + private set + private var previous = 0L + + init { + TaskScheduler += RepeatedTask(1000 / RUNS_PER_SECOND) { tick() } + } + + private fun tick() { + val previous = this.previous + val allocated = RUNTIME.totalMemory() - RUNTIME.freeMemory() + this.previous = allocated + if (allocated < previous) { + // gc was active + return + } + this.allocationRate = (allocated - previous) * RUNS_PER_SECOND + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/debug/DebugHUDElement.kt similarity index 99% rename from src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/debug/DebugHUDElement.kt index 1d7fd605a..ef636715b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/debug/DebugHUDElement.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.gui.hud.elements.other +package de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.debug import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec4.Vec4i @@ -199,6 +199,8 @@ class DebugHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Layouted layout += LineSpacerElement(guiRenderer) + layout += AutoTextElement(guiRenderer, 1) { "Allocation rate ${AllocationRate.allocationRate.formatBytes()}/s}" } + SystemInformation.RUNTIME.apply { layout += AutoTextElement(guiRenderer, 1) { val total = maxMemory()