Improve LocalMetrics logging.
This commit is contained in:
parent
5a005fb809
commit
6f30aec4f2
2 changed files with 26 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
package org.thoughtcrime.securesms.database.model
|
||||
|
||||
import org.signal.core.util.roundedString
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.time.Duration.Companion.nanoseconds
|
||||
import kotlin.time.DurationUnit
|
||||
|
||||
data class LocalMetricsEvent(
|
||||
val createdAt: Long,
|
||||
|
@ -10,6 +13,15 @@ data class LocalMetricsEvent(
|
|||
val timeunit: TimeUnit
|
||||
) {
|
||||
override fun toString(): String {
|
||||
return "[$eventName] total: ${splits.sumOf { timeunit.convert(it.duration, TimeUnit.NANOSECONDS) }} | ${splits.map { it.toString() }.joinToString(", ")}"
|
||||
return "[$eventName] total: ${splits.sumOf { it.duration }.fractionalMillis(timeunit)} | ${splits.map { it.toString() }.joinToString(", ")}"
|
||||
}
|
||||
|
||||
private fun Long.fractionalMillis(timeunit: TimeUnit): String {
|
||||
val places = when (timeunit) {
|
||||
TimeUnit.MICROSECONDS -> 3
|
||||
TimeUnit.NANOSECONDS -> 6
|
||||
else -> 0
|
||||
}
|
||||
return this.nanoseconds.toDouble(DurationUnit.MILLISECONDS).roundedString(places)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package org.thoughtcrime.securesms.database.model
|
||||
|
||||
import org.signal.core.util.roundedString
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.time.Duration.Companion.nanoseconds
|
||||
import kotlin.time.DurationUnit
|
||||
|
||||
data class LocalMetricsSplit(
|
||||
val name: String,
|
||||
|
@ -8,6 +11,15 @@ data class LocalMetricsSplit(
|
|||
val timeunit: TimeUnit = TimeUnit.MILLISECONDS
|
||||
) {
|
||||
override fun toString(): String {
|
||||
return "$name: ${timeunit.convert(duration, TimeUnit.NANOSECONDS)}"
|
||||
return "$name: ${duration.fractionalMillis(timeunit)}"
|
||||
}
|
||||
|
||||
private fun Long.fractionalMillis(timeunit: TimeUnit): String {
|
||||
val places = when (timeunit) {
|
||||
TimeUnit.MICROSECONDS -> 3
|
||||
TimeUnit.NANOSECONDS -> 6
|
||||
else -> 0
|
||||
}
|
||||
return this.nanoseconds.toDouble(DurationUnit.MILLISECONDS).roundedString(places)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue