logging the room import time taken

This commit is contained in:
Adam Brown 2022-09-04 14:01:07 +01:00
parent 38dec9c802
commit ef2a2c5624
3 changed files with 18 additions and 7 deletions

View File

@ -1,5 +1,9 @@
package app.dapk.st.core
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
enum class AppLogTag(val key: String) {
NOTIFICATION("notification"),
PERFORMANCE("performance"),
@ -26,3 +30,13 @@ suspend fun <T> logP(area: String, block: suspend () -> T): T {
log(AppLogTag.PERFORMANCE, "$area: took $timeTaken ms")
}
}
fun <T> Flow<T>.logP(area: String): Flow<T> {
var start = -1L
return this
.onStart { start = System.currentTimeMillis() }
.onCompletion {
val timeTaken = System.currentTimeMillis() - start
log(AppLogTag.PERFORMANCE, "$area: took $timeTaken ms")
}
}

View File

@ -50,12 +50,10 @@ internal class DefaultCryptoService(
}
override suspend fun InputStream.importRoomKeys(password: String): Flow<ImportResult> {
return logP("import room keys") {
with(roomKeyImporter) {
importRoomKeys(password) {
importRoomKeys(it)
}
}
return with(roomKeyImporter) {
importRoomKeys(password) {
importRoomKeys(it)
}.logP("import room keys")
}
}
}

View File

@ -14,7 +14,6 @@ internal class OlmCrypto(
) {
suspend fun importRoomKeys(keys: List<SharedRoomKey>) {
logger.crypto("import room keys : ${keys.size}")
olm.import(keys)
}