/** * Returns the root element of the tree where the given element belongs to. * * @param element * the {@link InvocationTreeElement} to find the root for * @return the root {@link InvocationTreeElement} of the current tree */ public static InvocationTreeElement getRoot(InvocationTreeElement element) { if (element == null) { return null; } while (element.getParent() != null) { element = element.getParent(); } return element; }
/** * Returns whether the given {@link InvocationTreeElement} is a child of a span or the parent is * a span respectively. * * @param element * the element to check * @return <code>true</code> when the parent is a span */ public static boolean isChildOfSpan(InvocationTreeElement element) { if (element == null) { throw new IllegalArgumentException("The given InvocationTreeElement must not be null."); } return (element.getParent() != null) && element.getParent().isSpan(); }
/** * 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; }