Improve logging around memory usage.

This commit is contained in:
Greyson Parrelli
2023-07-07 14:41:23 -04:00
committed by Clark Chen
parent 500ae0c72e
commit 5ca025544e
6 changed files with 274 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ import com.google.android.gms.security.ProviderInstaller;
import org.conscrypt.Conscrypt;
import org.greenrobot.eventbus.EventBus;
import org.signal.aesgcmprovider.AesGcmProvider;
import org.signal.core.util.MemoryTracker;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.AndroidLogger;
import org.signal.core.util.logging.Log;
@@ -237,6 +238,7 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
KeyCachingService.onAppForegrounded(this);
ApplicationDependencies.getShakeToReport().enable();
checkBuildExpiration();
MemoryTracker.start();
long lastForegroundTime = SignalStore.misc().getLastForegroundTime();
long currentTime = System.currentTimeMillis();
@@ -260,6 +262,7 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
ApplicationDependencies.getFrameRateTracker().stop();
ApplicationDependencies.getShakeToReport().disable();
ApplicationDependencies.getDeadlockDetector().stop();
MemoryTracker.stop();
}
public PersistentLogger getPersistentLogger() {

View File

@@ -0,0 +1,56 @@
package org.thoughtcrime.securesms.logsubmit
import android.content.Context
import android.os.Build
import org.signal.core.util.MemoryTracker
import org.signal.core.util.bytes
import org.signal.core.util.kibiBytes
import org.signal.core.util.roundedString
class LogSectionMemory : LogSection {
override fun getTitle(): String = "MEMORY"
override fun getContent(context: Context): CharSequence {
val appMemory = MemoryTracker.getAppJvmHeapUsage()
val nativeMemory = MemoryTracker.getSystemNativeMemoryUsage(context)
var base = """
-- App JVM Heap
Used : ${appMemory.usedBytes.byteDisplay()}
Free : ${appMemory.freeBytes.byteDisplay()}
Current Total: ${appMemory.currentTotalBytes.byteDisplay()}
Max Possible : ${appMemory.maxPossibleBytes.byteDisplay()}
-- System Native Memory
Used : ${nativeMemory.usedBytes.byteDisplay()}
Free : ${nativeMemory.freeBytes.byteDisplay()}
Total : ${nativeMemory.totalBytes.byteDisplay()}
Low Memory Threshold: ${nativeMemory.lowMemoryThreshold.byteDisplay()}
Low Memory? : ${nativeMemory.lowMemory}
""".trimIndent()
if (Build.VERSION.SDK_INT >= 23) {
val detailedMemory = MemoryTracker.getDetailedMemoryStats()
base += "\n\n"
base += """
-- Detailed Memory (API 23+)
App JVM Heap Usage : ${detailedMemory.appJavaHeapUsageKb?.kbDisplay()}
App Native Heap Usage: ${detailedMemory.appNativeHeapUsageKb?.kbDisplay()}
Code Usage : ${detailedMemory.codeUsageKb?.kbDisplay()}
Graphics Usage : ${detailedMemory.graphicsUsageKb?.kbDisplay()}
Stack Usage : ${detailedMemory.stackUsageKb?.kbDisplay()}
Other Usage : ${detailedMemory.appOtherUsageKb?.kbDisplay()}
""".trimIndent()
}
return base
}
private fun Long.byteDisplay(): String {
return "$this bytes (${bytes.inMebiBytes.roundedString(2)} MiB)"
}
private fun Long.kbDisplay(): String {
return "$this KiB (${kibiBytes.inMebiBytes.roundedString(2)} MiB)"
}
}

View File

@@ -75,6 +75,7 @@ public class SubmitDebugLogRepository {
add(new LogSectionJobs());
add(new LogSectionConstraints());
add(new LogSectionCapabilities());
add(new LogSectionMemory());
add(new LogSectionLocalMetrics());
add(new LogSectionFeatureFlags());
add(new LogSectionPin());