forked from MeloNX/MeloNX
android - add performance stats
This commit is contained in:
parent
96c4edb697
commit
e926499e32
@ -37,6 +37,7 @@ class MainActivity : BaseActivity() {
|
||||
var mainViewModel: MainViewModel? = null
|
||||
var AppPath : String = ""
|
||||
var StorageHelper: SimpleStorageHelper? = null
|
||||
val performanceMonitor = PerformanceMonitor()
|
||||
|
||||
@JvmStatic
|
||||
fun updateRenderSessionPerformance(gameTime : Long)
|
||||
@ -120,6 +121,8 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val freq = performanceMonitor.getFrequencies()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
|
@ -0,0 +1,113 @@
|
||||
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.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import java.io.RandomAccessFile
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class PerformanceMonitor {
|
||||
val numberOfCores = Runtime.getRuntime().availableProcessors()
|
||||
private var isMonitoring: Boolean = false
|
||||
fun startMonitoring() {
|
||||
if(isMonitoring)
|
||||
return
|
||||
|
||||
isMonitoring = true
|
||||
|
||||
thread {
|
||||
monitor()
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
fun monitor(){
|
||||
while(isMonitoring) {
|
||||
//lastCpuUsages = HardwarePropertiesManager.
|
||||
|
||||
//Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
fun getFrequencies() : List<Double> {
|
||||
val frequencies = mutableListOf<Double>()
|
||||
for (i in 0..<numberOfCores){
|
||||
var freq = 0.0;
|
||||
try {
|
||||
val reader = RandomAccessFile(
|
||||
"/sys/devices/system/cpu/cpu${i}/cpufreq/scaling_cur_freq",
|
||||
"r"
|
||||
)
|
||||
val f = reader.readLine()
|
||||
freq = f.toDouble() / 1000.0
|
||||
}
|
||||
catch (e:Exception){
|
||||
|
||||
}
|
||||
|
||||
frequencies.add(freq)
|
||||
}
|
||||
|
||||
return frequencies.toList()
|
||||
}
|
||||
|
||||
fun getMemoryUsage() : List<Int> {
|
||||
val mem = mutableListOf<Int>()
|
||||
MainActivity.mainViewModel?.activity?.apply {
|
||||
val actManager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
||||
val memInfo = ActivityManager.MemoryInfo()
|
||||
actManager.getMemoryInfo(memInfo)
|
||||
val availMemory = memInfo.availMem.toDouble()/(1024*1024)
|
||||
val totalMemory= memInfo.totalMem.toDouble()/(1024*1024)
|
||||
|
||||
mem.add((totalMemory - availMemory).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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.material3.AlertDialog
|
||||
@ -18,11 +19,13 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -30,7 +33,9 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.PointerEventType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.compose.ui.window.Popup
|
||||
import compose.icons.CssGgIcons
|
||||
@ -197,8 +202,10 @@ class GameViews {
|
||||
mainViewModel.motionSensorManager?.unregister()
|
||||
})
|
||||
}
|
||||
Row(modifier = Modifier.padding(8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
Row(
|
||||
modifier = Modifier.padding(8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
IconButton(modifier = Modifier.padding(4.dp), onClick = {
|
||||
showMore.value = false
|
||||
showController.value = !showController.value
|
||||
@ -338,13 +345,18 @@ class GameViews {
|
||||
modifier = Modifier.padding(16.dp),
|
||||
color = MaterialTheme.colorScheme.background.copy(0.4f)
|
||||
) {
|
||||
Column {
|
||||
var gameTimeVal = 0.0
|
||||
if (!gameTime.value.isInfinite())
|
||||
gameTimeVal = gameTime.value
|
||||
Text(text = "${String.format("%.3f", fifo.value)} %")
|
||||
Text(text = "${String.format("%.3f", gameFps.value)} FPS")
|
||||
Text(text = "${String.format("%.3f", gameTimeVal)} ms")
|
||||
CompositionLocalProvider(LocalTextStyle provides TextStyle(fontSize = 10.sp)) {
|
||||
Column {
|
||||
var gameTimeVal = 0.0
|
||||
if (!gameTime.value.isInfinite())
|
||||
gameTimeVal = gameTime.value
|
||||
Text(text = "${String.format("%.3f", fifo.value)} %")
|
||||
Text(text = "${String.format("%.3f", gameFps.value)} FPS")
|
||||
Text(text = "${String.format("%.3f", gameTimeVal)} ms")
|
||||
Box(modifier = Modifier.width(84.dp)) {
|
||||
MainActivity.performanceMonitor.RenderUsage()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user