Log free memory before starting a task

This commit is contained in:
Benoit Marty 2021-02-03 15:37:46 +01:00 committed by Benoit Marty
parent 39e66555f4
commit 8e2161bd9e

View File

@ -22,9 +22,10 @@ internal suspend fun <T> logDuration(message: String,
block: suspend () -> T): T {
val runtime = Runtime.getRuntime()
runtime.gc()
val usedMemInMBStart = (runtime.totalMemory() - runtime.freeMemory()) / 1048576L
val freeMemoryInMb = runtime.freeMemory() / 1048576L
val usedMemInMBStart = runtime.totalMemory() / 1048576L - freeMemoryInMb
Timber.v("$message -- BEGIN")
Timber.v("$message -- BEGIN (free memory: $freeMemoryInMb MB)")
val start = System.currentTimeMillis()
val result = block()
val duration = System.currentTimeMillis() - start