1
0
forked from MeloNX/MeloNX

android - fix cpu and mem stats update

This commit is contained in:
Emmanuel Hansen 2024-07-24 20:57:34 +00:00
parent 08853515af
commit ab0845d732
3 changed files with 31 additions and 22 deletions

View File

@ -2,16 +2,7 @@ package org.ryujinx.android
import android.app.ActivityManager import android.app.ActivityManager
import android.content.Context.ACTIVITY_SERVICE 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.MutableState
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import java.io.RandomAccessFile import java.io.RandomAccessFile
class PerformanceMonitor { class PerformanceMonitor {
@ -37,8 +28,9 @@ class PerformanceMonitor {
} }
} }
fun getMemoryUsage(mem: MutableList<Int>){ fun getMemoryUsage(
mem.clear() usedMem: MutableState<Int>,
totalMem: MutableState<Int>) {
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()
@ -46,8 +38,8 @@ class PerformanceMonitor {
val availMemory = memInfo.availMem.toDouble() / (1024 * 1024) val availMemory = memInfo.availMem.toDouble() / (1024 * 1024)
val totalMemory = memInfo.totalMem.toDouble() / (1024 * 1024) val totalMemory = memInfo.totalMem.toDouble() / (1024 * 1024)
mem.add((totalMemory - availMemory).toInt()) usedMem.value = (totalMemory - availMemory).toInt()
mem.add(totalMemory.toInt()) totalMem.value = totalMemory.toInt()
} }
} }
} }

View File

@ -35,6 +35,9 @@ class MainViewModel(val activity: MainActivity) {
private var gameTimeState: MutableState<Double>? = null private var gameTimeState: MutableState<Double>? = null
private var gameFpsState: MutableState<Double>? = null private var gameFpsState: MutableState<Double>? = null
private var fifoState: 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 progress: MutableState<String>? = null
private var progressValue: MutableState<Float>? = null private var progressValue: MutableState<Float>? = null
private var showLoading: MutableState<Boolean>? = null private var showLoading: MutableState<Boolean>? = null
@ -349,14 +352,16 @@ class MainViewModel(val activity: MainActivity) {
fifo: MutableState<Double>, fifo: MutableState<Double>,
gameFps: MutableState<Double>, gameFps: MutableState<Double>,
gameTime: MutableState<Double>, gameTime: MutableState<Double>,
mem: MutableList<Int>, usedMem: MutableState<Int>,
totalMem: MutableState<Int>,
frequencies: MutableList<Double> frequencies: MutableList<Double>
) { ) {
fifoState = fifo fifoState = fifo
gameFpsState = gameFps gameFpsState = gameFps
gameTimeState = gameTime gameTimeState = gameTime
MainActivity.performanceMonitor.getMemoryUsage(mem) usedMemState = usedMem
MainActivity.performanceMonitor.getFrequencies(frequencies) totalMemState = totalMem
frequenciesState = frequencies
} }
fun updateStats( fun updateStats(
@ -373,6 +378,15 @@ class MainViewModel(val activity: MainActivity) {
gameTimeState?.apply { gameTimeState?.apply {
this.value = gameTime this.value = gameTime
} }
usedMemState?.let { usedMem ->
totalMemState?.let { totalMem ->
MainActivity.performanceMonitor.getMemoryUsage(
usedMem,
totalMem
)
}
}
frequenciesState?.let { MainActivity.performanceMonitor.getFrequencies(it) }
} }
fun setGameController(controller: GameController) { fun setGameController(controller: GameController) {

View File

@ -13,7 +13,6 @@ 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.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed 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
@ -31,6 +30,7 @@ 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.mutableDoubleStateOf
import androidx.compose.runtime.mutableIntStateOf
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
@ -345,8 +345,11 @@ class GameViews {
val gameTime = remember { val gameTime = remember {
mutableDoubleStateOf(0.0) mutableDoubleStateOf(0.0)
} }
val mem = remember { val usedMem = remember {
mutableListOf<Int>(0,0) mutableIntStateOf(0)
}
val totalMem = remember {
mutableIntStateOf(0)
} }
val frequencies = remember { val frequencies = remember {
mutableListOf<Double>() mutableListOf<Double>()
@ -381,12 +384,12 @@ class GameViews {
Row { Row {
Text(modifier = Modifier.padding(2.dp), text = "Used") Text(modifier = Modifier.padding(2.dp), text = "Used")
Spacer(Modifier.weight(1f)) Spacer(Modifier.weight(1f))
Text(text = "${mem[0]} MB") Text(text = "${usedMem.value} MB")
} }
Row { Row {
Text(modifier = Modifier.padding(2.dp), text = "Total") Text(modifier = Modifier.padding(2.dp), text = "Total")
Spacer(Modifier.weight(1f)) 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)
} }
} }
} }