Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Test Menu options for Country selection and Measurement (EXPOSUREAPP-2229) #1086

Merged
merged 24 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f627704
Implement country filter (#2229)
mertsafter Aug 25, 2020
7d43226
Implement measure for Risk calculation and Key Retrieval (#2229)
mertsafter Aug 26, 2020
a3d5263
Some code cleanup for measureRiskLevelAndKeyRetrieval
mertsafter Aug 27, 2020
d7cae29
Some code cleanup (#2229)
mertsafter Aug 28, 2020
249afc5
Implement usage of AppConfig usage for country codes (#2229)
mertsafter Aug 28, 2020
6c8eff4
change CURRENT_COUNTRY val to var
mertsafter Aug 28, 2020
c941829
Suppress "LongMethod" warning (#2229)
mertsafter Aug 29, 2020
ce5ce76
Adjust unit tests to respect new country filter
mertsafter Aug 29, 2020
df93d01
Align with backend for app config country property name
mertsafter Aug 31, 2020
03a6219
Display total file size of keys in results (#2229)
mertsafter Aug 31, 2020
7b763cb
Fix linting issue
mertsafter Aug 31, 2020
38e26d9
Update strings.xml files
mertsafter Sep 1, 2020
468d09e
Do refactoring and some code clean up
mertsafter Sep 1, 2020
56745b1
Move RiskLevel and Key retrieval measurement in own class
mertsafter Sep 1, 2020
873b1d9
Move code in logical classes. Remove translation in test fragment
mertsafter Sep 2, 2020
0f6d565
Fix linting and Unit tests
mertsafter Sep 2, 2020
0409073
Remove 3hour boolean check from debug class.
d4rken Sep 2, 2020
a1a2e12
Refactor CountryWrapper and missing dates check.
d4rken Sep 2, 2020
a4c4f82
Fix linting and Unit tests
mertsafter Sep 2, 2020
085c084
Add Unit test for getMissingDates
mertsafter Sep 3, 2020
b76b418
Code cleanup
mertsafter Sep 3, 2020
daf4016
Hide keyboard on action
mertsafter Sep 3, 2020
c502491
Extend statistics for api submission
mertsafter Sep 3, 2020
3050ace
Set callback to null after invoked
mertsafter Sep 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package de.rki.coronawarnapp

import android.content.Context
import android.text.format.Formatter
import de.rki.coronawarnapp.exception.ExceptionCategory
import de.rki.coronawarnapp.exception.TransactionException
import de.rki.coronawarnapp.exception.reporting.report
import de.rki.coronawarnapp.transaction.RetrieveDiagnosisKeysTransaction
import de.rki.coronawarnapp.transaction.RiskLevelTransaction
import timber.log.Timber
import kotlin.system.measureTimeMillis

object RiskLevelAndKeyRetrievalBenchmark {
mertsafter marked this conversation as resolved.
Show resolved Hide resolved

/**
* Calls the RetrieveDiagnosisKeysTransaction and RiskLevelTransaction and measures them.
* Results are displayed using a label
* @param callCount defines how often the transactions should be called (each call will be
* measured separately)
*/
suspend fun start(
context: Context?,
countries: List<String>,
callCount: Int,
callback: (resultInfo: String) -> Unit
) {

var resultInfo = StringBuilder()
.append(
"MEASUREMENT Running for Countries:\n " +
"${countries?.joinToString(", ")}\n\n"
)
.append("Result: \n\n")
.append("#\t Combined \t Download \t Key Calc \t File # \t Files size\n")

callback(resultInfo.toString())

repeat(callCount) { index ->
var keyRetrievalError = ""
var keyFileCount: Int = -1
var keyFileDownloadDuration: Long = -1
var keyFilesSize: Long = -1

try {
measureDiagnosticKeyRetrieval(
"#$index",
countries
) { duration, keyCount, totalFileSize ->
mertsafter marked this conversation as resolved.
Show resolved Hide resolved
keyFileCount = keyCount
keyFileDownloadDuration = duration
keyFilesSize = totalFileSize
}
} catch (e: TransactionException) {
keyRetrievalError = e.message.toString()
}

var calculationDuration: Long = -1
var calculationError = ""

try {
measureKeyCalculation("#$index") {
mertsafter marked this conversation as resolved.
Show resolved Hide resolved
calculationDuration = it
}
} catch (e: TransactionException) {
calculationError = e.message.toString()
}

// build result entry for current iteration with all gathered data
resultInfo.append(
"${index + 1}. \t ${calculationDuration + keyFileDownloadDuration} ms \t\t " +
"$keyFileDownloadDuration ms " +
"\t\t $calculationDuration ms \t\t $keyFileCount \t\t " +
"${Formatter.formatFileSize(context, keyFilesSize)}\n"
)

if (keyRetrievalError.isNotEmpty()) {
resultInfo.append("Key Retrieval Error: $keyRetrievalError\n")
}

if (calculationError.isNotEmpty()) {
resultInfo.append("Calculation Error: $calculationError\n")
}

callback(resultInfo.toString())
}
}

private suspend fun measureKeyCalculation(label: String, finished: (duration: Long) -> Unit) {
try {
Timber.v("MEASURE [Risk Level Calculation] $label started")
// start risk level calculation and get duration
measureTimeMillis {
RiskLevelTransaction.start()
}.also {
Timber.v("MEASURE [Risk Level Calculation] $label finished")
finished(it)
}
} catch (e: TransactionException) {
e.report(ExceptionCategory.INTERNAL)
throw e
}
}

private suspend fun measureDiagnosticKeyRetrieval(
label: String,
countries: List<String>,
finished: (duration: Long, keyCount: Int, fileSize: Long) -> Unit
) {
var keyFileDownloadStart: Long = -1

try {
RetrieveDiagnosisKeysTransaction.onKeyFilesStarted = {
Timber.v("MEASURE [Diagnostic Key Files] $label started")
keyFileDownloadStart = System.currentTimeMillis()
}

RetrieveDiagnosisKeysTransaction.onKeyFilesFinished = { count, size ->
Timber.v("MEASURE [Diagnostic Key Files] $label finished")
val duration = System.currentTimeMillis() - keyFileDownloadStart
finished(duration, count, size)
}
// start diagnostic key transaction
RetrieveDiagnosisKeysTransaction.start(countries)
} catch (e: TransactionException) {
e.report(ExceptionCategory.INTERNAL)
throw e
}
}
}
Loading