private void calculateDuration(ProfileStackElement element) {
        if (this.detectedStacks.size() <= 1) {
            element.setDuration(0);
            return;
        }

        Collections.sort(this.detectedStacks);

        // calculate time windows duration
        ProfileStack currentTimeWindowStartStack = detectedStacks.get(0);
        ProfileStack currentTimeWindowEndTack = detectedStacks.get(0);
        long duration = 0;
        for (ListIterator<ProfileStack> it = detectedStacks.listIterator(1); it.hasNext(); ) {
            ProfileStack currentStack = it.next();

            // is continuity
            if (currentTimeWindowEndTack.getSequence() + 1 != currentStack.getSequence()) {
                duration += currentTimeWindowEndTack.getDumpTime() - currentTimeWindowStartStack.getDumpTime();
                currentTimeWindowStartStack = currentStack;
            }

            currentTimeWindowEndTack = currentStack;
        }

        // calculate last one time windows
        duration += currentTimeWindowEndTack.getDumpTime() - currentTimeWindowStartStack.getDumpTime();

        this.duration = Math.toIntExact(duration);
        element.setDuration(this.duration);
    }
calculate duration to {@link ProfileStackElement#getDuration()}
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/profiling/trace/analyze/ProfileStackNode.java