mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
Do not log RAM usage in release
This commit is contained in:
parent
218be86c68
commit
440d01c552
1 changed files with 24 additions and 11 deletions
|
@ -16,23 +16,36 @@
|
|||
|
||||
package org.matrix.android.sdk.internal.util
|
||||
|
||||
import org.matrix.android.sdk.BuildConfig
|
||||
import timber.log.Timber
|
||||
|
||||
internal suspend fun <T> logDuration(message: String,
|
||||
block: suspend () -> T): T {
|
||||
val runtime = Runtime.getRuntime()
|
||||
runtime.gc()
|
||||
val freeMemoryInMb = runtime.freeMemory() / 1048576L
|
||||
val usedMemInMBStart = runtime.totalMemory() / 1048576L - freeMemoryInMb
|
||||
|
||||
Timber.v("$message -- BEGIN (free memory: $freeMemoryInMb MB)")
|
||||
Timber.v("$message -- BEGIN")
|
||||
val start = System.currentTimeMillis()
|
||||
val result = block()
|
||||
val result = logRamUsage(message) {
|
||||
block()
|
||||
}
|
||||
val duration = System.currentTimeMillis() - start
|
||||
runtime.gc()
|
||||
val usedMemInMBEnd = (runtime.totalMemory() - runtime.freeMemory()) / 1048576L
|
||||
val usedMemInMBDiff = usedMemInMBEnd - usedMemInMBStart
|
||||
Timber.v("$message -- END duration: $duration ms")
|
||||
|
||||
Timber.v("$message -- END duration: $duration ms RAM usage: $usedMemInMBDiff MB")
|
||||
return result
|
||||
}
|
||||
|
||||
internal suspend fun <T> logRamUsage(message: String, block: suspend () -> T): T {
|
||||
return if (BuildConfig.DEBUG) {
|
||||
val runtime = Runtime.getRuntime()
|
||||
runtime.gc()
|
||||
val freeMemoryInMb = runtime.freeMemory() / 1048576L
|
||||
val usedMemInMBStart = runtime.totalMemory() / 1048576L - freeMemoryInMb
|
||||
Timber.v("$message -- BEGIN (free memory: $freeMemoryInMb MB)")
|
||||
val result = block()
|
||||
runtime.gc()
|
||||
val usedMemInMBEnd = (runtime.totalMemory() - runtime.freeMemory()) / 1048576L
|
||||
val usedMemInMBDiff = usedMemInMBEnd - usedMemInMBStart
|
||||
Timber.v("$message -- END RAM usage: $usedMemInMBDiff MB")
|
||||
result
|
||||
} else {
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue