/** * Returns exclusive duration of the Span contained in the given {@link InvocationTreeElement}. * Note: This method works only with {@link InvocationTreeElement} of type * {@link TreeElementType#SPAN}. * * @param element * the {@link InvocationTreeElement} to calculate the exclusive duration for * @return Returns exclusive duration. */ public static double calculateSpanExclusiveDuration(InvocationTreeElement element) { if (element == null) { return Double.NaN; } if (!element.isSpan()) { return 0D; } double childrenDuration = element.getChildren().stream().mapToDouble(InvocationTreeUtil::calculateSpanParentRelativeDuration).sum(); double exclusiveDuration = ((Span) element.getDataElement()).getDuration() - childrenDuration; return Math.max(exclusiveDuration, 0D); }
/** * Returns the relative duration of the span contained in the given element. If the element is * an asynchronous span, the method will return <code>0</code> because we cannot specify a * relative duration of an asynchronous span relative to its parent. * <p> * If the element is not of type {@link TreeElementType#SPAN} the sum of all direct child spans * are calculated. This means that when the child spans are not direct children in the tree but * are connected via several invocation sequence to the parent span we handle them as well. * * @param element * the element to calculate the duration * @return the relative duration of the span or the sum of all direct child spans */ private static double calculateSpanParentRelativeDuration(InvocationTreeElement element) { if (element.isSpan()) { if (InvocationTreeUtil.isConsideredAsync(element)) { return 0D; } else { return ((Span) element.getDataElement()).getDuration(); } } // This case is only necessary in full trees which do not consist of span elements only but // multiple spans are connected together over several invocation sequences. In a tree // consisting only of span elements, this case can never happen. double nestedDuration = element.getChildren().stream().mapToDouble(InvocationTreeUtil::calculateSpanParentRelativeDuration).sum(); return nestedDuration; }
/** * Returns styled text for {@link Span} based on the column. * * @param span * span * @param enumId * column * @return string */ public StyledString getStyledTextForColumn(Span span, Column enumId) { switch (enumId) { case ELEMENT: return TextFormatter.getSpanDetailsFull(span, cachedDataService); case DURATION: return new StyledString(NumberFormatter.formatDouble(span.getDuration())); default: return new StyledString(); } }
/** * 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; }
return new StyledString(NumberFormatter.formatTimeWithMillis(span.getTimeStamp())); case DURATION: StyledString durationString = new StyledString(NumberFormatter.formatDouble(span.getDuration(), timeDecimalPlaces)); if (InvocationTreeUtil.isConsideredAsync(ite)) { durationString.append(TextFormatter.getWarningSign());
/** * Calculates the duration starting from this invocation sequence data element. Includes span * duration as last resource if the span ident exists on the data. * * @param data * the <code>InvocationSequenceData</code> object. * @param spanService * Span service providing the additional span information if needed. * @return the duration starting from this invocation sequence data element. */ public static double calculateDuration(InvocationSequenceData data, ISpanService spanService) { if (InvocationSequenceDataHelper.hasTimerData(data)) { return data.getTimerData().getDuration(); } else if (InvocationSequenceDataHelper.hasSQLData(data)) { return data.getSqlStatementData().getDuration(); } else if ((null != spanService) && hasSpanIdent(data)) { Span span = spanService.get(data.getSpanIdent()); if ((span != null) && !References.FOLLOWS_FROM.equals(span.getReferenceType())) { return span.getDuration(); } } if (InvocationSequenceDataHelper.isRootElementInSequence(data)) { return data.getDuration(); } return -1.0d; }
table.addContentRow("Duration (ms):", null, new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatDouble(span.getDuration(), 3)) });
/** * Returns the styled text for a specific column. * * @param data * The data object to extract the information from. * @param enumId * The enumeration ID. * @return The styled string containing the information from the data object. */ private StyledString getStyledTextForColumn(Span data, Column enumId) { switch (enumId) { case TIME: return new StyledString(NumberFormatter.formatTimeWithMillis(data.getTimeStamp())); case DURATION: return new StyledString(NumberFormatter.formatDouble(data.getDuration(), timeDecimalPlaces)); case PROPAGATION: return TextFormatter.getPropagationStyled(data.getPropagationType()); case DETAILS: return TextFormatter.getSpanDetailsShort(data, cachedDataService); case ORIGIN: return TextFormatter.getSpanOriginStyled(data, cachedDataService.getPlatformIdentForId(data.getPlatformIdent())); case TRACE_ID: return new StyledString(Long.toHexString(data.getSpanIdent().getTraceId())); default: return new StyledString("error"); } } }