Skip to content

Commit

Permalink
Fix build slice level breakdown (opensearch-project#11359)
Browse files Browse the repository at this point in the history
Signed-off-by: Ticheng Lin <[email protected]>
  • Loading branch information
ticheng-aws authored and fahadshamiinsta committed Dec 4, 2023
1 parent 69ec2f6 commit 2ca2e4d
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,29 @@ Map<Collector, Map<String, Long>> buildSliceLevelBreakdown() {
: value + currentSliceLeafBreakdownMap.get(timingTypeCountKey)
);

// compute the sliceEndTime for timingType using max of endTime across slice leaves
final long sliceLeafTimingTypeEndTime = currentSliceLeafBreakdownMap.get(timingTypeStartKey)
+ currentSliceLeafBreakdownMap.get(timingType.toString());
currentSliceBreakdown.compute(
timingTypeSliceEndTimeKey,
(key, value) -> (value == null) ? sliceLeafTimingTypeEndTime : Math.max(value, sliceLeafTimingTypeEndTime)
);

// compute the sliceStartTime for timingType using min of startTime across slice leaves
final long sliceLeafTimingTypeStartTime = currentSliceLeafBreakdownMap.get(timingTypeStartKey);
if (sliceLeafTimingTypeStartTime == 0L && currentSliceBreakdown.get(timingTypeCountKey) != 0L) {
// In case where a slice with multiple leaves, it is possible that any one of the leaves has 0 invocations for a
// specific breakdown type. For instance, let's consider a slice with three leaves: leaf A with a score count of 5,
// leaf B with a score count of 0, and leaf C with a score count of 4. In this situation, we only compute the timing
// type slice start/end time based on leaf A and leaf C. This is because leaf B has a start time of zero. And it
// doesn't represent an actual timing; rather, it indicates no invocations.
continue;
}
currentSliceBreakdown.compute(
timingTypeSliceStartTimeKey,
(key, value) -> (value == null) ? sliceLeafTimingTypeStartTime : Math.min(value, sliceLeafTimingTypeStartTime)
);

// compute the sliceEndTime for timingType using max of endTime across slice leaves
final long sliceLeafTimingTypeEndTime = sliceLeafTimingTypeStartTime + currentSliceLeafBreakdownMap.get(
timingType.toString()
);
currentSliceBreakdown.compute(
timingTypeSliceEndTimeKey,
(key, value) -> (value == null) ? sliceLeafTimingTypeEndTime : Math.max(value, sliceLeafTimingTypeEndTime)
);
}
// compute sliceMaxEndTime as max of sliceEndTime across all timing types
sliceMaxEndTime = Math.max(sliceMaxEndTime, currentSliceBreakdown.getOrDefault(timingTypeSliceEndTimeKey, Long.MIN_VALUE));
Expand Down

0 comments on commit 2ca2e4d

Please sign in to comment.