Skip to content

Commit

Permalink
Adds more memory stat dumping for production apps
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Jul 20, 2024
1 parent fa06aef commit b80008d
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
*/
package com.vitorpamplona.amethyst.ui.navigation

import android.app.ActivityManager
import android.content.Context
import android.content.pm.ApplicationInfo
import android.os.Debug
import android.util.Log
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -66,6 +68,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.core.content.getSystemService
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand Down Expand Up @@ -1034,6 +1037,14 @@ fun debugState(context: Context) {

Log.d("STATE DUMP", "Total Native Heap Allocated: " + nativeHeap + " MB")

val activityManager: ActivityManager? = context.getSystemService()
if (activityManager != null) {
val isLargeHeap = (context.applicationInfo.flags and ApplicationInfo.FLAG_LARGE_HEAP) != 0
val memClass = if (isLargeHeap) activityManager.largeMemoryClass else activityManager.memoryClass

Log.d("STATE DUMP", "Memory Class " + memClass + " MB (largeHeap $isLargeHeap)")
}

Log.d("STATE DUMP", "Connected Relays: " + RelayPool.connectedRelays())

val imageLoader = Coil.imageLoader(context)
Expand Down Expand Up @@ -1092,6 +1103,13 @@ fun debugState(context: Context) {
LocalCache.observablesByKindAndAuthor.size,
)

Log.d(
"STATE DUMP",
"Spam: " +
LocalCache.antiSpam.recentMessages.size() +
" / " + LocalCache.antiSpam.spamMessages.size(),
)

Log.d(
"STATE DUMP",
"Memory used by Events: " +
Expand Down

0 comments on commit b80008d

Please sign in to comment.