private void initializeIfNeeded() {
        if (null == this.metrics) {
            this.onGraphComputer = TraversalHelper.onGraphComputer(this.getTraversal());
            this.metrics = new MutableMetrics(this.getPreviousStep().getId(), this.getPreviousStep().toString());
            final Step<?, S> previousStep = this.getPreviousStep();

            // give metrics to the step being profiled so that it can add additional data to the metrics like
            // annotations
            if (previousStep instanceof Profiling)
                ((Profiling) previousStep).setMetrics(this.metrics);
        }
    }
Returns {@code Optional.empty()} if traversal is not iterated or if not locked after strategy application.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ProfileStep.java