forked from MeloNX/MeloNX
fix usage stat update
This commit is contained in:
parent
a00c8c909f
commit
affefc35a8
@ -8,6 +8,8 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import java.io.RandomAccessFile
|
import java.io.RandomAccessFile
|
||||||
@ -15,8 +17,8 @@ import java.io.RandomAccessFile
|
|||||||
class PerformanceMonitor {
|
class PerformanceMonitor {
|
||||||
val numberOfCores = Runtime.getRuntime().availableProcessors()
|
val numberOfCores = Runtime.getRuntime().availableProcessors()
|
||||||
|
|
||||||
fun getFrequencies(): List<Double> {
|
fun getFrequencies(frequencies: MutableList<Double>){
|
||||||
val frequencies = mutableListOf<Double>()
|
frequencies.clear()
|
||||||
for (i in 0..<numberOfCores) {
|
for (i in 0..<numberOfCores) {
|
||||||
var freq = 0.0
|
var freq = 0.0
|
||||||
try {
|
try {
|
||||||
@ -33,12 +35,10 @@ class PerformanceMonitor {
|
|||||||
|
|
||||||
frequencies.add(freq)
|
frequencies.add(freq)
|
||||||
}
|
}
|
||||||
|
|
||||||
return frequencies.toList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMemoryUsage(): List<Int> {
|
fun getMemoryUsage(mem: MutableList<Int>){
|
||||||
val mem = mutableListOf<Int>()
|
mem.clear()
|
||||||
MainActivity.mainViewModel?.activity?.apply {
|
MainActivity.mainViewModel?.activity?.apply {
|
||||||
val actManager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
val actManager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||||||
val memInfo = ActivityManager.MemoryInfo()
|
val memInfo = ActivityManager.MemoryInfo()
|
||||||
@ -49,41 +49,5 @@ class PerformanceMonitor {
|
|||||||
mem.add((totalMemory - availMemory).toInt())
|
mem.add((totalMemory - availMemory).toInt())
|
||||||
mem.add(totalMemory.toInt())
|
mem.add(totalMemory.toInt())
|
||||||
}
|
}
|
||||||
return mem.toList()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun RenderUsage() {
|
|
||||||
LazyColumn {
|
|
||||||
val frequencies = getFrequencies()
|
|
||||||
val mem = getMemoryUsage()
|
|
||||||
|
|
||||||
for (i in 0..<numberOfCores) {
|
|
||||||
item {
|
|
||||||
Row {
|
|
||||||
Text(modifier = Modifier.padding(2.dp), text = "CPU ${i}")
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
Text(text = "${frequencies[i]} MHz")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mem.isNotEmpty()) {
|
|
||||||
item {
|
|
||||||
Row {
|
|
||||||
Text(modifier = Modifier.padding(2.dp), text = "Used")
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
Text(text = "${mem[0]} MB")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
item {
|
|
||||||
Row {
|
|
||||||
Text(modifier = Modifier.padding(2.dp), text = "Total")
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
Text(text = "${mem[1]} MB")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -322,11 +322,15 @@ class MainViewModel(val activity: MainActivity) {
|
|||||||
fun setStatStates(
|
fun setStatStates(
|
||||||
fifo: MutableState<Double>,
|
fifo: MutableState<Double>,
|
||||||
gameFps: MutableState<Double>,
|
gameFps: MutableState<Double>,
|
||||||
gameTime: MutableState<Double>
|
gameTime: MutableState<Double>,
|
||||||
|
mem: MutableList<Int>,
|
||||||
|
frequencies: MutableList<Double>
|
||||||
) {
|
) {
|
||||||
fifoState = fifo
|
fifoState = fifo
|
||||||
gameFpsState = gameFps
|
gameFpsState = gameFps
|
||||||
gameTimeState = gameTime
|
gameTimeState = gameTime
|
||||||
|
MainActivity.performanceMonitor.getMemoryUsage(mem)
|
||||||
|
MainActivity.performanceMonitor.getFrequencies(frequencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateStats(
|
fun updateStats(
|
||||||
|
@ -5,13 +5,16 @@ import androidx.compose.foundation.layout.Arrangement
|
|||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.wrapContentHeight
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
import androidx.compose.foundation.layout.wrapContentWidth
|
import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.material3.AlertDialogDefaults
|
import androidx.compose.material3.AlertDialogDefaults
|
||||||
import androidx.compose.material3.BasicAlertDialog
|
import androidx.compose.material3.BasicAlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
@ -27,6 +30,7 @@ import androidx.compose.material3.Switch
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.mutableDoubleStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@ -333,13 +337,19 @@ class GameViews {
|
|||||||
@Composable
|
@Composable
|
||||||
fun GameStats(mainViewModel: MainViewModel) {
|
fun GameStats(mainViewModel: MainViewModel) {
|
||||||
val fifo = remember {
|
val fifo = remember {
|
||||||
mutableStateOf(0.0)
|
mutableDoubleStateOf(0.0)
|
||||||
}
|
}
|
||||||
val gameFps = remember {
|
val gameFps = remember {
|
||||||
mutableStateOf(0.0)
|
mutableDoubleStateOf(0.0)
|
||||||
}
|
}
|
||||||
val gameTime = remember {
|
val gameTime = remember {
|
||||||
mutableStateOf(0.0)
|
mutableDoubleStateOf(0.0)
|
||||||
|
}
|
||||||
|
val mem = remember {
|
||||||
|
mutableListOf<Int>(0,0)
|
||||||
|
}
|
||||||
|
val frequencies = remember {
|
||||||
|
mutableListOf<Double>()
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
@ -354,14 +364,37 @@ class GameViews {
|
|||||||
Text(text = "${String.format("%.3f", fifo.value)} %")
|
Text(text = "${String.format("%.3f", fifo.value)} %")
|
||||||
Text(text = "${String.format("%.3f", gameFps.value)} FPS")
|
Text(text = "${String.format("%.3f", gameFps.value)} FPS")
|
||||||
Text(text = "${String.format("%.3f", gameTimeVal)} ms")
|
Text(text = "${String.format("%.3f", gameTimeVal)} ms")
|
||||||
Box(modifier = Modifier.width(84.dp)) {
|
Box(modifier = Modifier.width(96.dp)) {
|
||||||
MainActivity.performanceMonitor.RenderUsage()
|
Column {
|
||||||
|
LazyColumn {
|
||||||
|
itemsIndexed(frequencies) { i, t ->
|
||||||
|
Row {
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.padding(2.dp),
|
||||||
|
text = "CPU $i"
|
||||||
|
)
|
||||||
|
Spacer(Modifier.weight(1f))
|
||||||
|
Text(text = "$t MHz")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row {
|
||||||
|
Text(modifier = Modifier.padding(2.dp), text = "Used")
|
||||||
|
Spacer(Modifier.weight(1f))
|
||||||
|
Text(text = "${mem[0]} MB")
|
||||||
|
}
|
||||||
|
Row {
|
||||||
|
Text(modifier = Modifier.padding(2.dp), text = "Total")
|
||||||
|
Spacer(Modifier.weight(1f))
|
||||||
|
Text(text = "${mem[1]} MB")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mainViewModel.setStatStates(fifo, gameFps, gameTime)
|
mainViewModel.setStatStates(fifo, gameFps, gameTime, mem, frequencies)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user