mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
samples: add more metrics to software3D
This commit is contained in:
parent
18e92a49e3
commit
8c344b3812
|
@ -47,7 +47,7 @@ fun main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val (scene, updater) = geometry()
|
val (scene, updater) = geometry()
|
||||||
val taskCount = 1// Runtime.getRuntime().availableProcessors()
|
val taskCount = Runtime.getRuntime().availableProcessors()
|
||||||
println("Running on $taskCount CPUs")
|
println("Running on $taskCount CPUs")
|
||||||
val rasters = (0 until taskCount).map { Raster(SCENE_WIDTH, (SCENE_HEIGHT + taskCount - 1) / taskCount) }
|
val rasters = (0 until taskCount).map { Raster(SCENE_WIDTH, (SCENE_HEIGHT + taskCount - 1) / taskCount) }
|
||||||
val renderers = rasters.mapIndexed { index, raster ->
|
val renderers = rasters.mapIndexed { index, raster ->
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.teavm.samples.software3d.teavm
|
package org.teavm.samples.software3d.teavm
|
||||||
|
|
||||||
|
import org.teavm.jso.browser.Window
|
||||||
import org.teavm.jso.dom.html.HTMLDocument
|
import org.teavm.jso.dom.html.HTMLDocument
|
||||||
import org.teavm.jso.dom.html.HTMLElement
|
import org.teavm.jso.dom.html.HTMLElement
|
||||||
import org.teavm.jso.dom.html.HTMLOptionElement
|
import org.teavm.jso.dom.html.HTMLOptionElement
|
||||||
|
@ -34,20 +35,29 @@ fun main(args: Array<out String>) {
|
||||||
|
|
||||||
fun runController() {
|
fun runController() {
|
||||||
val performanceIndicator = HTMLDocument.current().getElementById("performance-indicator")
|
val performanceIndicator = HTMLDocument.current().getElementById("performance-indicator")
|
||||||
|
val performanceIndicatorWorkerAverage = HTMLDocument.current().getElementById(
|
||||||
|
"performance-indicator-worker-average")
|
||||||
var performanceIndicatorByWorkers: List<HTMLElement> = emptyList()
|
var performanceIndicatorByWorkers: List<HTMLElement> = emptyList()
|
||||||
val maxWorkers = Runtime.getRuntime().availableProcessors()
|
val maxWorkers = Runtime.getRuntime().availableProcessors()
|
||||||
var workerType = WorkerType.JS
|
var workerType = WorkerType.JS
|
||||||
|
val performanceByWorkers = LongArray(maxWorkers)
|
||||||
|
var workerCount = maxWorkers
|
||||||
|
|
||||||
val controller = Controller(SCENE_WIDTH, SCENE_HEIGHT) { index, value ->
|
val controller = Controller(SCENE_WIDTH, SCENE_HEIGHT) { index, value ->
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
performanceIndicator.innerText = value.toString()
|
performanceIndicator.innerText = value.toString()
|
||||||
} else {
|
} else {
|
||||||
|
performanceByWorkers[index] = value
|
||||||
performanceIndicatorByWorkers.getOrNull(index)?.let {
|
performanceIndicatorByWorkers.getOrNull(index)?.let {
|
||||||
it.innerText = value.toString()
|
it.innerText = value.toString()
|
||||||
}
|
}
|
||||||
|
val average = performanceByWorkers.slice(0 until workerCount).average().toLong()
|
||||||
|
performanceIndicatorWorkerAverage.innerText = average.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
performanceIndicatorByWorkers = recreatePerformanceIndicators(maxWorkers)
|
performanceIndicatorByWorkers = recreatePerformanceIndicators(maxWorkers)
|
||||||
controller.startRendering(maxWorkers, workerType)
|
controller.startRendering(maxWorkers, workerType)
|
||||||
|
startTimer()
|
||||||
|
|
||||||
val cpuSelector = HTMLDocument.current().getElementById("workers") as HTMLSelectElement
|
val cpuSelector = HTMLDocument.current().getElementById("workers") as HTMLSelectElement
|
||||||
for (i in 1..maxWorkers) {
|
for (i in 1..maxWorkers) {
|
||||||
|
@ -61,7 +71,9 @@ fun runController() {
|
||||||
val newValue = cpuSelector.value.toInt()
|
val newValue = cpuSelector.value.toInt()
|
||||||
if (controller.tasks != newValue) {
|
if (controller.tasks != newValue) {
|
||||||
controller.startRendering(newValue, workerType)
|
controller.startRendering(newValue, workerType)
|
||||||
|
startTimer()
|
||||||
performanceIndicatorByWorkers = recreatePerformanceIndicators(newValue)
|
performanceIndicatorByWorkers = recreatePerformanceIndicators(newValue)
|
||||||
|
workerCount = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,10 +87,27 @@ fun runController() {
|
||||||
if (workerType != newValue) {
|
if (workerType != newValue) {
|
||||||
workerType = newValue
|
workerType = newValue
|
||||||
controller.startRendering(controller.tasks, workerType)
|
controller.startRendering(controller.tasks, workerType)
|
||||||
|
startTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentTimeout: Int? = null
|
||||||
|
|
||||||
|
private fun startTimer() {
|
||||||
|
currentTimeout?.let { Window.clearTimeout(it) }
|
||||||
|
val timerDisplay = HTMLDocument.current().getElementById("timer")
|
||||||
|
val startTime = System.currentTimeMillis()
|
||||||
|
var seconds = 0
|
||||||
|
fun updateTimer() {
|
||||||
|
val time = System.currentTimeMillis() - startTime
|
||||||
|
val nextTime = (time / 1000) * 1000 + 1000
|
||||||
|
timerDisplay.innerText = seconds++.toString()
|
||||||
|
currentTimeout = Window.setTimeout({ updateTimer() }, (nextTime - time).toInt())
|
||||||
|
}
|
||||||
|
updateTimer()
|
||||||
|
}
|
||||||
|
|
||||||
private fun recreatePerformanceIndicators(count: Int): List<HTMLElement> {
|
private fun recreatePerformanceIndicators(count: Int): List<HTMLElement> {
|
||||||
val container = HTMLDocument.current().getElementById("performance-indicators-by-workers")
|
val container = HTMLDocument.current().getElementById("performance-indicators-by-workers")
|
||||||
while (container.hasChildNodes()) {
|
while (container.hasChildNodes()) {
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
</select></div>
|
</select></div>
|
||||||
<div><label for="workers">Workers:</label> <select id="workers"></select></div>
|
<div><label for="workers">Workers:</label> <select id="workers"></select></div>
|
||||||
<div>Average frame rendering time, microseconds: <span id="performance-indicator"></span></div>
|
<div>Average frame rendering time, microseconds: <span id="performance-indicator"></span></div>
|
||||||
|
<div>Average by worker: <span id="performance-indicator-worker-average"></span></div>
|
||||||
|
<div>Time passed: <span id="timer"></span></div>
|
||||||
<div>By worker:</div>
|
<div>By worker:</div>
|
||||||
<ol id="performance-indicators-by-workers"></ol>
|
<ol id="performance-indicators-by-workers"></ol>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user