@Test public void nullValue() { double duration = InvocationTreeUtil.calculateSpanExclusiveDuration(null); assertThat(duration, is(Double.NaN)); } }
@Test public void successfulAtRoot() { double duration = InvocationTreeUtil.calculateSpanExclusiveDuration(tree); assertThat(duration, is(130D)); }
@Test public void successfulInTree() { InvocationTreeElement treeElement = InvocationTreeUtil.lookupTreeElement(InvocationTreeUtil.buildLookupMap(tree), span02); double duration = InvocationTreeUtil.calculateSpanExclusiveDuration(treeElement); assertThat(duration, is(100D)); }
/** * Returns exclusive duration as a percentage relative to its parents. Note: This method works * only with {@link InvocationTreeElement} of type {@link TreeElementType#SPAN}. * * @param element * the {@link InvocationTreeElement} to calculate the exclusive percentage for * @return Returns exclusive duration. */ public static double calculateSpanExclusivePercentage(InvocationTreeElement element) { if (element == null) { return Double.NaN; } InvocationTreeElement topElement = element; while ((topElement.getParent() != null) && !isConsideredAsync(topElement)) { topElement = topElement.getParent(); } if (topElement.isSpan()) { return InvocationTreeUtil.calculateSpanExclusiveDuration(element) / ((Span) topElement.getDataElement()).getDuration(); } return 0D; }
case EXCLUSIVE: StyledString exclusive = new StyledString(); exclusive.append(NumberFormatter.formatDouble(InvocationTreeUtil.calculateSpanExclusiveDuration(ite), timeDecimalPlaces)); exclusive.append(" (", StyledString.COUNTER_STYLER); int percentage = Math.round((float) InvocationTreeUtil.calculateSpanExclusivePercentage(ite) * 100);