Skip to content

Commit 5480c91

Browse files
rpdomeCopilot
andauthored
Update common4j/src/main/com/microsoft/identity/common/java/opentelemetry/DefaultBenchmarkSpanPrinter.kt
Co-authored-by: Copilot <[email protected]>
1 parent 60adf3f commit 5480c91

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

common4j/src/main/com/microsoft/identity/common/java/opentelemetry/DefaultBenchmarkSpanPrinter.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,17 @@ class DefaultBenchmarkSpanPrinter(
304304

305305
val result = mutableListOf<StatisticalStatusData>()
306306

307+
// Precompute the number of occurrences for each status name
308+
val occurrenceCountsByName = statusOccurrencesMap.keys
309+
.groupBy { it.statusName }
310+
.mapValues { it.value.size }
311+
307312
for ((occurrence, timingPairs) in statusOccurrencesMap) {
308313
val timeSincePreviousValues = timingPairs.map { it.first }
309314
val timeSinceStartValues = timingPairs.map { it.second }
310315

311316
// Create display name with occurrence number if there are multiple occurrences
312-
val displayName = if (statusOccurrencesMap.keys.count { it.statusName == occurrence.statusName } > 1) {
317+
val displayName = if ((occurrenceCountsByName[occurrence.statusName] ?: 1) > 1) {
313318
"${occurrence.statusName} [${occurrence.occurrenceIndex}]"
314319
} else {
315320
occurrence.statusName

0 commit comments

Comments
 (0)