[metrics][performance-tests] Fix span matching logic in metrics collector

GitOrigin-RevId: 1bc20e3f95130c990ee813c4352fa1ebb2f9169a
This commit is contained in:
roman.ivanitskii
2025-01-28 18:49:08 +00:00
committed by intellij-monorepo-bot
parent 08396676d2
commit e3f02a4dae
@@ -5,6 +5,7 @@ package com.intellij.tools.ide.metrics.collector.telemetry
import com.intellij.openapi.diagnostic.logger
import com.intellij.tools.ide.metrics.collector.metrics.PerformanceMetrics.Metric
import java.nio.file.Path
import kotlin.math.min
const val TOTAL_TEST_TIMER_NAME: String = "test"
const val DEFAULT_SPAN_NAME: String = "performance_test"
@@ -40,9 +41,10 @@ fun getMetricsBasedOnDiffBetweenSpans(name: String, file: Path, fromSpanName: St
}
val metrics = mutableListOf<MetricWithAttributes>()
val sortedFromSpans = fromSpanMetrics.sortedByDescending { info -> info.startTimestamp }
val spanIds = sortedFromSpans.map { it.spanId }.toSet()
val spanIds = sortedFromSpans.map { it.spanId to it.parentSpanId }.flatMap { listOf(it.first, it.second) }.toSet()
val sortedToSpans = toSpanMetrics.sortedByDescending { info -> info.startTimestamp }.filter { spanIds.contains(it.parentSpanId) }
for (i in fromSpanMetrics.indices) {
val minSize = min(fromSpanMetrics.size, sortedToSpans.size)
for (i in 0.. minSize - 1) {
val currentToSpan = sortedToSpans[i]
val currentFromSpan = sortedFromSpans[i]
if (currentFromSpan.spanId != currentToSpan.parentSpanId) {