mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Improve logging around memory usage.
This commit is contained in:
committed by
Clark Chen
parent
500ae0c72e
commit
5ca025544e
@@ -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() {
|
||||
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user