Skip to content

Commit

Permalink
[ide starter extended] AT-490 Use only Long in performance metrics (f…
Browse files Browse the repository at this point in the history
…loating point numbers might never be used)

GitOrigin-RevId: 897a8899ae51b1d498b4876870689d6e692a7859
  • Loading branch information
Nikita-Kudrin authored and intellij-monorepo-bot committed Aug 16, 2023
1 parent 3af7691 commit 1aa6c52
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ data class PerformanceMetrics(
val machineName: String,
val branchName: String,
val os: String,
val metrics: List<Metric<*>>
val metrics: List<Metric>
) {
sealed class MetricId<T : Number> {
sealed class MetricId {
abstract val name: String

/**
* Metric used to measure duration of events in ms
*/
data class Duration(override val name: String) : MetricId<Long>()
data class Duration(override val name: String) : MetricId()

/**
* Metric used to count the number of times an event has occurred
*/
data class Counter(override val name: String) : MetricId<Number>()
data class Counter(override val name: String) : MetricId()
}

data class Metric<T : Number>(val id: MetricId<T>, val value: T, val compareSetting: CompareSetting = CompareSetting.notComparing)
data class Metric(val id: MetricId, val value: Long, val compareSetting: CompareSetting = CompareSetting.notComparing)
}

fun PerformanceMetrics.Metric<*>.toJson() = ApplicationMetricDto(
fun PerformanceMetrics.Metric.toJson() = ApplicationMetricDto(
n = id.name,
d = if (id is PerformanceMetrics.MetricId.Duration) (this.value as? Number)?.toLong() else null,
c = if (id is PerformanceMetrics.MetricId.Counter) (this.value as? Number)?.toLong() else null
d = if (id is PerformanceMetrics.MetricId.Duration) this.value else null,
c = if (id is PerformanceMetrics.MetricId.Counter) this.value else null
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class PerformanceMetricsDto(
fun create(
projectName: String,
buildNumber: BuildNumber,
metrics: Collection<PerformanceMetrics.Metric<*>>
metrics: Collection<PerformanceMetrics.Metric>
) = PerformanceMetricsDto(
generated = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME),
project = projectName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,20 @@ data class IndexingMetrics(
"number of full rescannings" to numberOfFullRescanning.toString()
)

fun getListOfIndexingMetrics(): List<PerformanceMetrics.Metric<out Number>> {
fun getListOfIndexingMetrics(): List<PerformanceMetrics.Metric> {
val numberOfIndexedFiles = totalNumberOfIndexedFiles
val numberOfFilesFullyIndexedByExtensions = totalNumberOfFilesFullyIndexedByExtensions
return listOf(
PerformanceMetrics.Metric(metricIndexingTimeWithoutPauses, value = totalIndexingTimeWithoutPauses),
PerformanceMetrics.Metric(metricScanningTimeWithoutPauses, value = totalScanFilesTimeWithoutPauses),
PerformanceMetrics.Metric(metricPausedTimeInIndexingOrScanning, value = totalPausedTime),
PerformanceMetrics.Metric(metricDumbModeTimeWithPauses, value = totalDumbModeTimeWithPauses),
PerformanceMetrics.Metric(metricNumberOfIndexedFiles, value = numberOfIndexedFiles),
PerformanceMetrics.Metric(metricNumberOfFilesIndexedByExtensions, value = numberOfFilesFullyIndexedByExtensions),
PerformanceMetrics.Metric(metricNumberOfIndexedFiles, value = numberOfIndexedFiles.toLong()),
PerformanceMetrics.Metric(metricNumberOfFilesIndexedByExtensions, value = numberOfFilesFullyIndexedByExtensions.toLong()),
PerformanceMetrics.Metric(metricNumberOfFilesIndexedWithoutExtensions,
value = numberOfIndexedFiles - numberOfFilesFullyIndexedByExtensions),
PerformanceMetrics.Metric(metricNumberOfRunsOfScanning, value = totalNumberOfRunsOfScanning),
PerformanceMetrics.Metric(metricNumberOfRunsOfIndexing, value = totalNumberOfRunsOfIndexing)
value = (numberOfIndexedFiles - numberOfFilesFullyIndexedByExtensions).toLong()),
PerformanceMetrics.Metric(metricNumberOfRunsOfScanning, value = totalNumberOfRunsOfScanning.toLong()),
PerformanceMetrics.Metric(metricNumberOfRunsOfIndexing, value = totalNumberOfRunsOfIndexing.toLong())
) + getProcessingSpeedOfFileTypes(processingSpeedPerFileType) + getProcessingSpeedOfBaseLanguages(processingSpeedPerBaseLanguage)
}
}
Expand All @@ -230,20 +230,20 @@ fun extractIndexingMetrics(startResult: IDEStartResult): IndexingMetrics {
return IndexingMetrics(startResult, jsonIndexDiagnostics)
}

private fun getProcessingSpeedOfFileTypes(mapFileTypeToSpeed: Map<String, Int>): List<PerformanceMetrics.Metric<*>> {
val list = mutableListOf<PerformanceMetrics.Metric<*>>()
private fun getProcessingSpeedOfFileTypes(mapFileTypeToSpeed: Map<String, Int>): List<PerformanceMetrics.Metric> {
val list = mutableListOf<PerformanceMetrics.Metric>()
mapFileTypeToSpeed.forEach {
list.add(PerformanceMetrics.Metric("processingSpeed#${it.key}".createPerformanceMetricCounter(), value = it.value))
list.add(PerformanceMetrics.Metric("processingSpeed#${it.key}".createPerformanceMetricCounter(), value = it.value.toLong()))
}
return list
}

private fun getProcessingSpeedOfBaseLanguages(mapBaseLanguageToSpeed: Map<String, Int>): List<PerformanceMetrics.Metric<*>> =
private fun getProcessingSpeedOfBaseLanguages(mapBaseLanguageToSpeed: Map<String, Int>): List<PerformanceMetrics.Metric> =
mapBaseLanguageToSpeed.map {
PerformanceMetrics.Metric("processingSpeedOfBaseLanguage#${it.key}".createPerformanceMetricCounter(), value = it.value)
PerformanceMetrics.Metric("processingSpeedOfBaseLanguage#${it.key}".createPerformanceMetricCounter(), value = it.value.toLong())
}

data class ScanningStatistics(val numberOfScannedFiles: Int = 0, val numberOfSkippedFiles: Int = 0, val scanningTime: Long = 0) {
data class ScanningStatistics(val numberOfScannedFiles: Long = 0, val numberOfSkippedFiles: Long = 0, val scanningTime: Long = 0) {
fun merge(scanningStatistics: JsonScanningStatistics) : ScanningStatistics {
return ScanningStatistics(
numberOfScannedFiles = numberOfScannedFiles + scanningStatistics.numberOfScannedFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import kotlin.math.sqrt
const val TOTAL_TEST_TIMER_NAME: String = "test"
const val DEFAULT_SPAN_NAME: String = "performance_test"

data class MetricWithAttributes(val metric: Metric<*>,
val attributes: MutableList<Metric<*>> = mutableListOf())
data class MetricWithAttributes(val metric: Metric,
val attributes: MutableList<Metric> = mutableListOf())

@Suppress("unused")
fun getOpenTelemetry(startResult: IDEStartResult): PerformanceMetricsDto {
Expand Down Expand Up @@ -52,10 +52,10 @@ class SpanFilter(val filter: (String) -> Boolean) {
* 3a. If attribute ends with `#mean_value`, the mean value of mean values will be recorded
*/

fun getMetricsFromSpanAndChildren(file: File, filter: SpanFilter): List<Metric<*>>{
fun getMetricsFromSpanAndChildren(file: File, filter: SpanFilter): List<Metric>{
return combineMetrics(getSpansMetricsMap(file, filter))
}
fun getMetricsFromSpanAndChildren(startResult: IDEStartResult, filter: SpanFilter): List<Metric<*>> {
fun getMetricsFromSpanAndChildren(startResult: IDEStartResult, filter: SpanFilter): List<Metric> {
val opentelemetryFile = startResult.context.paths.logsDir.resolve(OPENTELEMETRY_FILE).toFile()
return getMetricsFromSpanAndChildren(opentelemetryFile, filter)
}
Expand Down Expand Up @@ -101,8 +101,8 @@ private fun getSpans(file: File): JsonNode {
return allSpans
}

private fun combineMetrics(metrics: Map<String, List<MetricWithAttributes>>): List<Metric<*>> {
val result = mutableListOf<Metric<*>>()
private fun combineMetrics(metrics: Map<String, List<MetricWithAttributes>>): List<Metric> {
val result = mutableListOf<Metric>()
metrics.forEach { entry ->
if (entry.value.size == 1) {
val metric = entry.value.first()
Expand Down Expand Up @@ -159,9 +159,9 @@ private fun <T : Number> standardDeviation(data: Collection<T>): Long {
return sqrt(data.map { (it.toDouble() - mean).pow(2) }.average()).toLong()
}

private fun getAttributes(spanName: String, metric: MetricWithAttributes): Collection<Metric<*>> {
private fun getAttributes(spanName: String, metric: MetricWithAttributes): Collection<Metric> {
return metric.attributes.map { attributeMetric ->
Metric(Counter("$spanName#" + attributeMetric.id.name), attributeMetric.value.toInt())
Metric(Counter("$spanName#" + attributeMetric.id.name), attributeMetric.value)
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ private fun populateAttributes(metric: MetricWithAttributes, span: JsonNode) {
span.get("tags")?.forEach { tag ->
val attributeName = tag.get("key").textValue()
tag.get("value").textValue().runCatching { toInt() }.onSuccess {
metric.attributes.add(Metric(Counter(attributeName), it))
metric.attributes.add(Metric(Counter(attributeName), it.toLong()))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fun String.createPerformanceMetricCounter(): PerformanceMetrics.MetricId.Counter

fun String.createPerformanceMetricDuration(): PerformanceMetrics.MetricId.Duration = PerformanceMetrics.MetricId.Duration(this)

fun findMetricValue(metrics: List<PerformanceMetrics.Metric<*>>, metric: PerformanceMetrics.MetricId.Duration): Number = try {
fun findMetricValue(metrics: List<PerformanceMetrics.Metric>, metric: PerformanceMetrics.MetricId.Duration): Number = try {
metrics.first { it.id.name == metric.name }.value
}
catch (e: NoSuchElementException) {
Expand Down

0 comments on commit 1aa6c52

Please sign in to comment.