From 66a7b7fe4b94e01d0c8302e9a62f2912750eabec Mon Sep 17 00:00:00 2001 From: Ticheng Lin Date: Wed, 29 Nov 2023 13:00:37 -0800 Subject: [PATCH] Fix query profiler test basic with concurrent execution Signed-off-by: Ticheng Lin --- .../query/ConcurrentQueryProfileBreakdown.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/src/main/java/org/opensearch/search/profile/query/ConcurrentQueryProfileBreakdown.java b/server/src/main/java/org/opensearch/search/profile/query/ConcurrentQueryProfileBreakdown.java index ee893540c78d9..c000c026b6207 100644 --- a/server/src/main/java/org/opensearch/search/profile/query/ConcurrentQueryProfileBreakdown.java +++ b/server/src/main/java/org/opensearch/search/profile/query/ConcurrentQueryProfileBreakdown.java @@ -202,6 +202,11 @@ Map> buildSliceLevelBreakdown() { // doesn't represent an actual timing; rather, it indicates no invocations. continue; } + if (sliceLeafTimingTypeStartTime == 0L && currentSliceBreakdown.get(timingTypeCountKey) == 0L) { + // This is the case where a slice has 0 invocations for a breakdown type from its leading leaves. + // We should skip the slice start/end time computation since 0 does not represent an actual timing. + continue; + } currentSliceBreakdown.compute( timingTypeSliceStartTimeKey, (key, value) -> (value == null) ? sliceLeafTimingTypeStartTime : Math.min(value, sliceLeafTimingTypeStartTime) @@ -216,6 +221,12 @@ Map> buildSliceLevelBreakdown() { (key, value) -> (value == null) ? sliceLeafTimingTypeEndTime : Math.max(value, sliceLeafTimingTypeEndTime) ); } + // Only when we've checked all leaves in a slice and still find no invocations, then we should set the slice start/end time + // to the default 0L. + if (currentSliceBreakdown.get(timingTypeCountKey) == 0L) { + currentSliceBreakdown.put(timingTypeSliceStartTimeKey, 0L); + currentSliceBreakdown.put(timingTypeSliceEndTimeKey, 0L); + } // compute sliceMaxEndTime as max of sliceEndTime across all timing types sliceMaxEndTime = Math.max(sliceMaxEndTime, currentSliceBreakdown.getOrDefault(timingTypeSliceEndTimeKey, Long.MIN_VALUE)); long currentSliceStartTime = currentSliceBreakdown.getOrDefault(timingTypeSliceStartTimeKey, Long.MAX_VALUE);