@@ -342,19 +342,22 @@ public Map<String, Long> buildQueryBreakdownMap(
342342 (key , value ) -> (value == null ) ? sliceBreakdownTypeCount : sliceBreakdownTypeCount + value
343343 );
344344
345- // query start/end time for a TimingType is min/max of start/end time across slices for that TimingType
346- queryTimingTypeEndTime = Math .max (
347- queryTimingTypeEndTime ,
348- sliceBreakdown .getValue ().getOrDefault (sliceEndTimeForTimingType , Long .MIN_VALUE )
349- );
350- queryTimingTypeStartTime = Math .min (
351- queryTimingTypeStartTime ,
352- sliceBreakdown .getValue ().getOrDefault (sliceStartTimeForTimingType , Long .MAX_VALUE )
353- );
354- queryTimingTypeCount += sliceBreakdownTypeCount ;
345+ // only modify the start/end time of the TimingType if the slice used the timer
346+ if (sliceBreakdownTypeCount > 0L ) {
347+ // query start/end time for a TimingType is min/max of start/end time across slices for that TimingType
348+ queryTimingTypeEndTime = Math .max (
349+ queryTimingTypeEndTime ,
350+ sliceBreakdown .getValue ().getOrDefault (sliceEndTimeForTimingType , Long .MIN_VALUE )
351+ );
352+ queryTimingTypeStartTime = Math .min (
353+ queryTimingTypeStartTime ,
354+ sliceBreakdown .getValue ().getOrDefault (sliceStartTimeForTimingType , Long .MAX_VALUE )
355+ );
356+ queryTimingTypeCount += sliceBreakdownTypeCount ;
357+ }
355358 }
356359
357- if (queryTimingTypeStartTime == Long .MAX_VALUE || queryTimingTypeEndTime == Long .MIN_VALUE ) {
360+ if (queryTimingTypeCount > 0L && ( queryTimingTypeStartTime == Long .MAX_VALUE || queryTimingTypeEndTime == Long .MIN_VALUE ) ) {
358361 throw new OpenSearchException (
359362 "Unexpected timing type ["
360363 + timingTypeKey
@@ -365,7 +368,7 @@ public Map<String, Long> buildQueryBreakdownMap(
365368 + "] computed across slices for profile results"
366369 );
367370 }
368- queryBreakdownMap .put (timingTypeKey , queryTimingTypeEndTime - queryTimingTypeStartTime );
371+ queryBreakdownMap .put (timingTypeKey , ( queryTimingTypeCount > 0L ) ? queryTimingTypeEndTime - queryTimingTypeStartTime : 0L );
369372 queryBreakdownMap .put (timingTypeCountKey , queryTimingTypeCount );
370373 queryBreakdownMap .compute (avgBreakdownTypeTime , (key , value ) -> (value == null ) ? 0L : value / sliceLevelBreakdowns .size ());
371374 queryBreakdownMap .compute (avgBreakdownTypeCount , (key , value ) -> (value == null ) ? 0L : value / sliceLevelBreakdowns .size ());
0 commit comments