Support weight for FUS metrics
If metric impact is different for different subprojects, corresponding metric could be reported with weight. Currently supported for numerical metrics with override policy AVERAGE.
This commit is contained in:
+6
-9
@@ -154,15 +154,12 @@ class BuildSessionLogger(
|
||||
closeTrackingFile()
|
||||
}
|
||||
|
||||
override fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String?) {
|
||||
metricsContainer.report(metric, value, subprojectName)
|
||||
}
|
||||
override fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String?, weight: Long?) =
|
||||
metricsContainer.report(metric, value, subprojectName, weight)
|
||||
|
||||
override fun report(metric: NumericalMetrics, value: Long, subprojectName: String?) {
|
||||
metricsContainer.report(metric, value, subprojectName)
|
||||
}
|
||||
override fun report(metric: NumericalMetrics, value: Long, subprojectName: String?, weight: Long?) =
|
||||
metricsContainer.report(metric, value, subprojectName, weight)
|
||||
|
||||
override fun report(metric: StringMetrics, value: String, subprojectName: String?) {
|
||||
metricsContainer.report(metric, value, subprojectName)
|
||||
}
|
||||
override fun report(metric: StringMetrics, value: String, subprojectName: String?, weight: Long?) =
|
||||
metricsContainer.report(metric, value, subprojectName, weight)
|
||||
}
|
||||
|
||||
+9
-6
@@ -104,31 +104,34 @@ class MetricsContainer : IStatisticsValuesConsumer {
|
||||
private fun getProjectHash(perProject: Boolean, subprojectName: String?) =
|
||||
if (subprojectName == null) null else processProjectName(subprojectName, perProject)
|
||||
|
||||
override fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String?) {
|
||||
override fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String?, weight: Long?): Boolean {
|
||||
val projectHash = getProjectHash(metric.perProject, subprojectName)
|
||||
synchronized(metricsLock) {
|
||||
val metricContainer = booleanMetrics[MetricDescriptor(metric.name, projectHash)] ?: metric.type.newMetricContainer()
|
||||
.also { booleanMetrics[MetricDescriptor(metric.name, projectHash)] = it }
|
||||
metricContainer.addValue(metric.anonymization.anonymize(value))
|
||||
metricContainer.addValue(metric.anonymization.anonymize(value), weight)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun report(metric: NumericalMetrics, value: Long, subprojectName: String?) {
|
||||
override fun report(metric: NumericalMetrics, value: Long, subprojectName: String?, weight: Long?): Boolean {
|
||||
val projectHash = getProjectHash(metric.perProject, subprojectName)
|
||||
synchronized(metricsLock) {
|
||||
val metricContainer = numericalMetrics[MetricDescriptor(metric.name, projectHash)] ?: metric.type.newMetricContainer()
|
||||
.also { numericalMetrics[MetricDescriptor(metric.name, projectHash)] = it }
|
||||
metricContainer.addValue(metric.anonymization.anonymize(value))
|
||||
metricContainer.addValue(metric.anonymization.anonymize(value), weight)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun report(metric: StringMetrics, value: String, subprojectName: String?) {
|
||||
override fun report(metric: StringMetrics, value: String, subprojectName: String?, weight: Long?): Boolean {
|
||||
val projectHash = getProjectHash(metric.perProject, subprojectName)
|
||||
synchronized(metricsLock) {
|
||||
val metricContainer = stringMetrics[MetricDescriptor(metric.name, projectHash)] ?: metric.type.newMetricContainer()
|
||||
.also { stringMetrics[MetricDescriptor(metric.name, projectHash)] = it }
|
||||
metricContainer.addValue(metric.anonymization.anonymize(value))
|
||||
metricContainer.addValue(metric.anonymization.anonymize(value), weight)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun flush(trackingFile: IRecordLogger?) {
|
||||
|
||||
+15
-13
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.statistics.metrics
|
||||
import java.util.*
|
||||
|
||||
interface IMetricContainer<T> {
|
||||
fun addValue(t: T)
|
||||
fun addValue(t: T, weight: Long? = null)
|
||||
|
||||
fun toStringRepresentation(): String
|
||||
|
||||
@@ -24,7 +24,7 @@ interface IMetricContainerFactory<T> {
|
||||
open class OverrideMetricContainer<T>() : IMetricContainer<T> {
|
||||
internal var myValue: T? = null
|
||||
|
||||
override fun addValue(t: T) {
|
||||
override fun addValue(t: T, weight: Long?) {
|
||||
myValue = t
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class OverrideVersionMetricContainer() : OverrideMetricContainer<String>() {
|
||||
myValue = v
|
||||
}
|
||||
|
||||
override fun addValue(t: String) {
|
||||
override fun addValue(t: String, weight: Long?) {
|
||||
if (myValue == null || myValue == "0.0.0") {
|
||||
myValue = t
|
||||
}
|
||||
@@ -56,22 +56,24 @@ class SumMetricContainer() : OverrideMetricContainer<Long>() {
|
||||
myValue = v
|
||||
}
|
||||
|
||||
override fun addValue(t: Long) {
|
||||
override fun addValue(t: Long, weight: Long?) {
|
||||
myValue = (myValue ?: 0) + t
|
||||
}
|
||||
}
|
||||
|
||||
class AverageMetricContainer() : IMetricContainer<Long> {
|
||||
private var count = 0
|
||||
private var myValue: Long? = null
|
||||
private var totalWeight = 0L
|
||||
private var totalSum: Long? = null
|
||||
|
||||
constructor(v: Long) : this() {
|
||||
myValue = v
|
||||
totalSum = v
|
||||
totalWeight = 1
|
||||
}
|
||||
|
||||
override fun addValue(t: Long) {
|
||||
myValue = (myValue ?: 0) + t
|
||||
count++
|
||||
override fun addValue(t: Long, weight: Long?) {
|
||||
val w = weight ?: 1
|
||||
totalSum = (totalSum ?: 0) + t * w
|
||||
totalWeight += w
|
||||
}
|
||||
|
||||
override fun toStringRepresentation(): String {
|
||||
@@ -79,7 +81,7 @@ class AverageMetricContainer() : IMetricContainer<Long> {
|
||||
}
|
||||
|
||||
override fun getValue(): Long? {
|
||||
return myValue?.div(count)
|
||||
return totalSum?.div(if (totalWeight > 0) totalWeight else 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +90,7 @@ class OrMetricContainer() : OverrideMetricContainer<Boolean>() {
|
||||
myValue = v
|
||||
}
|
||||
|
||||
override fun addValue(t: Boolean) {
|
||||
override fun addValue(t: Boolean, weight: Long?) {
|
||||
myValue = (myValue ?: false) || t
|
||||
}
|
||||
}
|
||||
@@ -104,7 +106,7 @@ class ConcatMetricContainer() : IMetricContainer<String> {
|
||||
myValues.addAll(values)
|
||||
}
|
||||
|
||||
override fun addValue(t: String) {
|
||||
override fun addValue(t: String, weight: Long?) {
|
||||
myValues.add(t.replace(SEPARATOR, ","))
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -18,9 +18,9 @@ interface AdditiveStatisticsValue<T> : ReportStatisticsValue<T> {
|
||||
}
|
||||
|
||||
interface IStatisticsValuesConsumer {
|
||||
fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String? = null)
|
||||
fun report(metric: BooleanMetrics, value: Boolean, subprojectName: String? = null, weight: Long? = null): Boolean
|
||||
|
||||
fun report(metric: NumericalMetrics, value: Long, subprojectName: String? = null)
|
||||
fun report(metric: NumericalMetrics, value: Long, subprojectName: String? = null, weight: Long? = null): Boolean
|
||||
|
||||
fun report(metric: StringMetrics, value: String, subprojectName: String? = null)
|
||||
fun report(metric: StringMetrics, value: String, subprojectName: String? = null, weight: Long? = null): Boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user