forked from MeloNX/MeloNX
android - fix cpu and mem stats update
This commit is contained in:
parent
08853515af
commit
ab0845d732
@ -2,16 +2,7 @@ package org.ryujinx.android
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context.ACTIVITY_SERVICE
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import java.io.RandomAccessFile
|
||||
|
||||
class PerformanceMonitor {
|
||||
@ -37,8 +28,9 @@ class PerformanceMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
fun getMemoryUsage(mem: MutableList<Int>){
|
||||
mem.clear()
|
||||
fun getMemoryUsage(
|
||||
usedMem: MutableState<Int>,
|
||||
totalMem: MutableState<Int>) {
|
||||
MainActivity.mainViewModel?.activity?.apply {
|
||||
val actManager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||||
val memInfo = ActivityManager.MemoryInfo()
|
||||
@ -46,8 +38,8 @@ class PerformanceMonitor {
|
||||
val availMemory = memInfo.availMem.toDouble() / (1024 * 1024)
|
||||
val totalMemory = memInfo.totalMem.toDouble() / (1024 * 1024)
|
||||
|
||||
mem.add((totalMemory - availMemory).toInt())
|
||||
mem.add(totalMemory.toInt())
|
||||
usedMem.value = (totalMemory - availMemory).toInt()
|
||||
totalMem.value = totalMemory.toInt()
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,9 @@ class MainViewModel(val activity: MainActivity) {
|
||||
private var gameTimeState: MutableState<Double>? = null
|
||||
private var gameFpsState: MutableState<Double>? = null
|
||||
private var fifoState: MutableState<Double>? = null
|
||||
private var usedMemState: MutableState<Int>? = null
|
||||
private var totalMemState: MutableState<Int>? = null
|
||||
private var frequenciesState: MutableList<Double>? = null
|
||||
private var progress: MutableState<String>? = null
|
||||
private var progressValue: MutableState<Float>? = null
|
||||
private var showLoading: MutableState<Boolean>? = null
|
||||
@ -349,14 +352,16 @@ class MainViewModel(val activity: MainActivity) {
|
||||
fifo: MutableState<Double>,
|
||||
gameFps: MutableState<Double>,
|
||||
gameTime: MutableState<Double>,
|
||||
mem: MutableList<Int>,
|
||||
usedMem: MutableState<Int>,
|
||||
totalMem: MutableState<Int>,
|
||||
frequencies: MutableList<Double>
|
||||
) {
|
||||
fifoState = fifo
|
||||
gameFpsState = gameFps
|
||||
gameTimeState = gameTime
|
||||
MainActivity.performanceMonitor.getMemoryUsage(mem)
|
||||
MainActivity.performanceMonitor.getFrequencies(frequencies)
|
||||
usedMemState = usedMem
|
||||
totalMemState = totalMem
|
||||
frequenciesState = frequencies
|
||||
}
|
||||
|
||||
fun updateStats(
|
||||
@ -373,6 +378,15 @@ class MainViewModel(val activity: MainActivity) {
|
||||
gameTimeState?.apply {
|
||||
this.value = gameTime
|
||||
}
|
||||
usedMemState?.let { usedMem ->
|
||||
totalMemState?.let { totalMem ->
|
||||
MainActivity.performanceMonitor.getMemoryUsage(
|
||||
usedMem,
|
||||
totalMem
|
||||
)
|
||||
}
|
||||
}
|
||||
frequenciesState?.let { MainActivity.performanceMonitor.getFrequencies(it) }
|
||||
}
|
||||
|
||||
fun setGameController(controller: GameController) {
|
||||
|
@ -13,7 +13,6 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
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.BasicAlertDialog
|
||||
@ -31,6 +30,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.mutableDoubleStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -345,8 +345,11 @@ class GameViews {
|
||||
val gameTime = remember {
|
||||
mutableDoubleStateOf(0.0)
|
||||
}
|
||||
val mem = remember {
|
||||
mutableListOf<Int>(0,0)
|
||||
val usedMem = remember {
|
||||
mutableIntStateOf(0)
|
||||
}
|
||||
val totalMem = remember {
|
||||
mutableIntStateOf(0)
|
||||
}
|
||||
val frequencies = remember {
|
||||
mutableListOf<Double>()
|
||||
@ -381,12 +384,12 @@ class GameViews {
|
||||
Row {
|
||||
Text(modifier = Modifier.padding(2.dp), text = "Used")
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(text = "${mem[0]} MB")
|
||||
Text(text = "${usedMem.value} MB")
|
||||
}
|
||||
Row {
|
||||
Text(modifier = Modifier.padding(2.dp), text = "Total")
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(text = "${mem[1]} MB")
|
||||
Text(text = "${totalMem.value} MB")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -394,7 +397,7 @@ class GameViews {
|
||||
}
|
||||
}
|
||||
|
||||
mainViewModel.setStatStates(fifo, gameFps, gameTime, mem, frequencies)
|
||||
mainViewModel.setStatStates(fifo, gameFps, gameTime, usedMem, totalMem, frequencies)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user