Skip to content

Commit

Permalink
Fix build slice level breakdown (opensearch-project#11359) (opensearc…
Browse files Browse the repository at this point in the history
…h-project#11381)

(cherry picked from commit afa67df)

Signed-off-by: Ticheng Lin <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 568a46f commit e266f40
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 e266f40

Please sign in to comment.