private void addTopLevelMetrics(final Traversal.Admin traversal, final boolean onGraphComputer) {
        this.totalStepDuration = 0;

        final List<ProfileStep> profileSteps = TraversalHelper.getStepsOfClass(ProfileStep.class, traversal);
        final List<Pair<Integer, MutableMetrics>> tempMetrics = new ArrayList<>(profileSteps.size());

        for (int ii = 0; ii < profileSteps.size(); ii++) {
            // The index is necessary to ensure that step order is preserved after a merge.
            final ProfileStep<?> step = profileSteps.get(ii);
            final MutableMetrics stepMetrics = onGraphComputer ? traversal.getSideEffects().get(step.getId()) : step.getMetrics().get();

            this.totalStepDuration += stepMetrics.getDuration(MutableMetrics.SOURCE_UNIT);
            tempMetrics.add(Pair.with(ii, stepMetrics.clone()));
        }

        tempMetrics.forEach(m -> {
            final double dur = m.getValue1().getDuration(TimeUnit.NANOSECONDS) * 100.d / this.totalStepDuration;
            m.getValue1().setAnnotation(PERCENT_DURATION_KEY, dur);
        });

        tempMetrics.forEach(p -> {
            this.stepIndexedMetrics.put(p.getValue1().getId(), p.getValue1().getImmutableClone());
            this.positionIndexedMetrics.put(p.getValue0(), p.getValue1().getImmutableClone());
        });
    }
Extracts metrics from the provided {@link Traversal} and computes metrics. Calling this method finalizes the
metrics such that their values can no longer be modified.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalMetrics.java