/** * This is only a convenient constructor needed for GraphSON deserialization. */ public DefaultTraversalMetrics(final long totalStepDurationNs, final List<MutableMetrics> orderedMetrics) { totalStepDuration = totalStepDurationNs; int ix = 0; for (final MutableMetrics metric : orderedMetrics) { stepIndexedMetrics.put(metric.getId(), metric.getImmutableClone()); positionIndexedMetrics.put(ix++, metric.getImmutableClone()); } }
/** * Gets a copy of the metrics that is immutable. Once this clone is made, the {@link MutableMetrics} can no * longer be modified themselves. This prevents custom steps that implement {@link Profiling} from adding to * the metrics after the traversal is complete. */ public synchronized ImmutableMetrics getImmutableClone() { finalized = true; final ImmutableMetrics clone = new ImmutableMetrics(); copyMembers(clone); this.nested.values().forEach(nested -> clone.nested.put(nested.id, ((MutableMetrics) nested).getImmutableClone())); return clone; }
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(); 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()); }); }
/** * This is only a convenient constructor needed for GraphSON deserialization. */ public DefaultTraversalMetrics(final long totalStepDurationNs, final List<MutableMetrics> orderedMetrics) { totalStepDuration = totalStepDurationNs; int ix = 0; for (final MutableMetrics metric : orderedMetrics) { stepIndexedMetrics.put(metric.getId(), metric.getImmutableClone()); positionIndexedMetrics.put(ix++, metric.getImmutableClone()); } }
/** * Gets a copy of the metrics that is immutable. Once this clone is made, the {@link MutableMetrics} can no * longer be modified themselves. This prevents custom steps that implement {@link Profiling} from adding to * the metrics after the traversal is complete. */ public synchronized ImmutableMetrics getImmutableClone() { finalized = true; final ImmutableMetrics clone = new ImmutableMetrics(); copyMembers(clone); this.nested.values().forEach(nested -> clone.nested.put(nested.id, ((MutableMetrics) nested).getImmutableClone())); return clone; }
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(); 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()); }); }