Source:
private void buildChildrenEntries(ICallStackElement element, CallGraph object, @Nullable TimeGraphEntry parent) { FlameGraphGroupEntry currentEntry = new FlameGraphGroupEntry(element.getName(), 0L, 0L); if (parent != null) { parent.addChild(currentEntry); } else { fFlameGraphEntries.add(currentEntry); } for (ICallStackElement child : element.getChildren()) { buildChildrenEntries(child, object, currentEntry); } if (!(element.isLeaf())) { return; } List<FlamegraphDepthEntry> childrenEntries = new ArrayList<>(); List<TimeGraphEntry> extraEntries = new ArrayList<>(); Deque<Long> timestampStack = new ArrayDeque<>(); timestampStack.push(0L); Collection<AggregatedCallSite> cct = object.getCallingContextTree(element); long totalLength = 0L; for (AggregatedCallSite acs : cct) { if (acs instanceof AggregatedCalledFunction) { currentEntry.setEntryType(EntryType.INSTRUMENTED); } totalLength += acs.getLength(); } long total = totalLength; currentEntry.setTotal(total); cct.stream() .sorted(Comparator.comparingLong(AggregatedCallSite::getLength)) .forEach(rootFunction -> { setData(rootFunction, childrenEntries, timestampStack, total); setExtraData(rootFunction, extraEntries, timestampStack, total); long thispercent = (long) (((double) rootFunction.getLength() / (double) total) * 10000); long currentThreadDuration = timestampStack.pop() + thispercent; timestampStack.push(currentThreadDuration); }); childrenEntries.forEach(child -> { currentEntry.addChild(child); }); extraEntries.forEach(child -> { currentEntry.addChild(child); }); currentEntry.updateEndTime(timestampStack.pop()); return; }

Target:
private void buildChildrenEntries(ICallStackElement element, CallGraph object, @Nullable TimeGraphEntry parent) { FlameGraphGroupEntry currentEntry = new FlameGraphGroupEntry(element.getName(), 0L, 0L); if (parent != null) { parent.addChild(currentEntry); } else { fFlameGraphEntries.add(currentEntry); } for (ICallStackElement child : element.getChildren()) { buildChildrenEntries(child, object, currentEntry); } if (!(element.isLeaf())) { return; } List<FlamegraphDepthEntry> childrenEntries = new ArrayList<>(); List<TimeGraphEntry> extraEntries = new ArrayList<>(); Deque<Long> timestampStack = new ArrayDeque<>(); timestampStack.push(0L); Collection<AggregatedCallSite> cct = object.getCallingContextTree(element); long totalLength = 0L; for (AggregatedCallSite acs : cct) { if (acs instanceof AggregatedCalledFunction) { currentEntry.setEntryType(EntryType.INSTRUMENTED); } totalLength += acs.getLength(); } long total = totalLength; currentEntry.setTotal(total); cct.stream() .sorted(Comparator.comparingLong(AggregatedCallSite::getLength)) .forEach(rootFunction -> { setData(rootFunction, childrenEntries, timestampStack, total); setExtraData(rootFunction, extraEntries, timestampStack, total); long thispercent = (long) (((double) rootFunction.getLength() / (double) total) * LongToPercentFormat.MAX_PERCENT_VALUE); long currentThreadDuration = timestampStack.pop() + thispercent; timestampStack.push(currentThreadDuration); }); childrenEntries.forEach(child -> { currentEntry.addChild(child); }); extraEntries.forEach(child -> { currentEntry.addChild(child); }); currentEntry.updateEndTime(timestampStack.pop()); return; }