Try to log RAM usage

This commit is contained in:
Benoit Marty 2021-01-26 13:45:17 +01:00 committed by Benoit Marty
parent c938795576
commit 39e66555f4

View file

@ -20,10 +20,18 @@ import timber.log.Timber
internal suspend fun <T> logDuration(message: String,
block: suspend () -> T): T {
val runtime = Runtime.getRuntime()
runtime.gc()
val usedMemInMBStart = (runtime.totalMemory() - runtime.freeMemory()) / 1048576L
Timber.v("$message -- BEGIN")
val start = System.currentTimeMillis()
val result = block()
val duration = System.currentTimeMillis() - start
Timber.v("$message -- END duration: $duration ms")
runtime.gc()
val usedMemInMBEnd = (runtime.totalMemory() - runtime.freeMemory()) / 1048576L
val usedMemInMBDiff = usedMemInMBEnd - usedMemInMBStart
Timber.v("$message -- END duration: $duration ms RAM usage: $usedMemInMBDiff MB")
return result
}