@@ -185,23 +185,25 @@ Map<Collector, Map<String, Long>> buildSliceLevelBreakdown() {
185
185
}
186
186
final Map <String , Long > currentSliceLeafBreakdownMap = contexts .get (sliceLeaf ).toBreakdownMap ();
187
187
// get the count for current leaf timing type
188
+ final long sliceLeafTimingTypeCount = currentSliceLeafBreakdownMap .get (timingTypeCountKey );
188
189
currentSliceBreakdown .compute (
189
190
timingTypeCountKey ,
190
- (key , value ) -> (value == null )
191
- ? currentSliceLeafBreakdownMap .get (timingTypeCountKey )
192
- : value + currentSliceLeafBreakdownMap .get (timingTypeCountKey )
191
+ (key , value ) -> (value == null ) ? sliceLeafTimingTypeCount : value + sliceLeafTimingTypeCount
193
192
);
194
193
195
- // compute the sliceStartTime for timingType using min of startTime across slice leaves
196
- final long sliceLeafTimingTypeStartTime = currentSliceLeafBreakdownMap .get (timingTypeStartKey );
197
- if (sliceLeafTimingTypeStartTime == 0L && currentSliceBreakdown .get (timingTypeCountKey ) != 0L ) {
194
+ if (sliceLeafTimingTypeCount == 0L ) {
198
195
// In case where a slice with multiple leaves, it is possible that any one of the leaves has 0 invocations for a
199
- // specific breakdown type. For instance, let's consider a slice with three leaves: leaf A with a score count of 5,
200
- // 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
201
- // 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
202
- // doesn't represent an actual timing; rather, it indicates no invocations.
196
+ // specific breakdown type. We should skip the slice start/end time computation for any leaf with 0 invocations on a
197
+ // timing type, as 0 does not represent an actual timing.
198
+ // For example, a slice has 0 invocations for a breakdown type from its leading leaves. Another example, let's
199
+ // consider a slice with three leaves: leaf A with a score count of 5, leaf B with a score count of 0,
200
+ // and leaf C with a score count of 4. In this situation, we only compute the timing type slice start/end time based
201
+ // on leaf A and leaf C. This is because leaf B has a start time of zero.
203
202
continue ;
204
203
}
204
+
205
+ // compute the sliceStartTime for timingType using min of startTime across slice leaves
206
+ final long sliceLeafTimingTypeStartTime = currentSliceLeafBreakdownMap .get (timingTypeStartKey );
205
207
currentSliceBreakdown .compute (
206
208
timingTypeSliceStartTimeKey ,
207
209
(key , value ) -> (value == null ) ? sliceLeafTimingTypeStartTime : Math .min (value , sliceLeafTimingTypeStartTime )
@@ -216,6 +218,13 @@ Map<Collector, Map<String, Long>> buildSliceLevelBreakdown() {
216
218
(key , value ) -> (value == null ) ? sliceLeafTimingTypeEndTime : Math .max (value , sliceLeafTimingTypeEndTime )
217
219
);
218
220
}
221
+ // Only when we've checked all leaves in a slice and still find no invocations, then we should set the slice start/end time
222
+ // to the default 0L. This is because buildQueryBreakdownMap expects timingTypeSliceStartTimeKey and
223
+ // timingTypeSliceEndTimeKey in the slice level breakdowns.
224
+ if (currentSliceBreakdown .get (timingTypeCountKey ) != null && currentSliceBreakdown .get (timingTypeCountKey ) == 0L ) {
225
+ currentSliceBreakdown .put (timingTypeSliceStartTimeKey , 0L );
226
+ currentSliceBreakdown .put (timingTypeSliceEndTimeKey , 0L );
227
+ }
219
228
// compute sliceMaxEndTime as max of sliceEndTime across all timing types
220
229
sliceMaxEndTime = Math .max (sliceMaxEndTime , currentSliceBreakdown .getOrDefault (timingTypeSliceEndTimeKey , Long .MIN_VALUE ));
221
230
long currentSliceStartTime = currentSliceBreakdown .getOrDefault (timingTypeSliceStartTimeKey , Long .MAX_VALUE );
0 commit comments