From ef2a2c5624957d8a686d31eea3f14e0de8910f8c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 4 Sep 2022 14:01:07 +0100 Subject: [PATCH] logging the room import time taken --- .../main/kotlin/app/dapk/st/core/HeliumLogger.kt | 14 ++++++++++++++ .../matrix/crypto/internal/DefaultCryptoService.kt | 10 ++++------ .../dapk/st/matrix/crypto/internal/OlmCrypto.kt | 1 - 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/src/main/kotlin/app/dapk/st/core/HeliumLogger.kt b/core/src/main/kotlin/app/dapk/st/core/HeliumLogger.kt index 9327337..d1846b9 100644 --- a/core/src/main/kotlin/app/dapk/st/core/HeliumLogger.kt +++ b/core/src/main/kotlin/app/dapk/st/core/HeliumLogger.kt @@ -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 logP(area: String, block: suspend () -> T): T { log(AppLogTag.PERFORMANCE, "$area: took $timeTaken ms") } } + +fun Flow.logP(area: String): Flow { + var start = -1L + return this + .onStart { start = System.currentTimeMillis() } + .onCompletion { + val timeTaken = System.currentTimeMillis() - start + log(AppLogTag.PERFORMANCE, "$area: took $timeTaken ms") + } +} \ No newline at end of file diff --git a/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/DefaultCryptoService.kt b/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/DefaultCryptoService.kt index 6293bb9..f5a64fe 100644 --- a/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/DefaultCryptoService.kt +++ b/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/DefaultCryptoService.kt @@ -50,12 +50,10 @@ internal class DefaultCryptoService( } override suspend fun InputStream.importRoomKeys(password: String): Flow { - return logP("import room keys") { - with(roomKeyImporter) { - importRoomKeys(password) { - importRoomKeys(it) - } - } + return with(roomKeyImporter) { + importRoomKeys(password) { + importRoomKeys(it) + }.logP("import room keys") } } } diff --git a/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/OlmCrypto.kt b/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/OlmCrypto.kt index 39e95e5..d244cf6 100644 --- a/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/OlmCrypto.kt +++ b/matrix/services/crypto/src/main/kotlin/app/dapk/st/matrix/crypto/internal/OlmCrypto.kt @@ -14,7 +14,6 @@ internal class OlmCrypto( ) { suspend fun importRoomKeys(keys: List) { - logger.crypto("import room keys : ${keys.size}") olm.import(keys) }