@Override public void setMetrics(final MutableMetrics parentMetrics) { if (parentMetrics != null) { callbackCalled = true; parentMetrics.setCount("bogusCount", 100); } } }
@Override public Metrics createObject(final Map<String, Object> metricsData) { final MutableMetrics m = new MutableMetrics((String)metricsData.get(GraphSONTokens.ID), (String)metricsData.get(GraphSONTokens.NAME)); m.setDuration(Math.round((Double) metricsData.get(GraphSONTokens.DURATION) * 1000000), TimeUnit.NANOSECONDS); for (Map.Entry<String, Long> count : ((Map<String, Long>)metricsData.getOrDefault(GraphSONTokens.COUNTS, new HashMap<>(0))).entrySet()) { m.setCount(count.getKey(), count.getValue()); } for (Map.Entry<String, Long> count : ((Map<String, Long>) metricsData.getOrDefault(GraphSONTokens.ANNOTATIONS, new HashMap<>(0))).entrySet()) { m.setAnnotation(count.getKey(), count.getValue()); } for (MutableMetrics nested : (List<MutableMetrics>)metricsData.getOrDefault(GraphSONTokens.METRICS, new ArrayList<>(0))) { m.addNested(nested); } return m; } }
@Override public Metrics deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final Map<String, Object> metricsData = deserializationContext.readValue(jsonParser, Map.class); final MutableMetrics m = new MutableMetrics((String)metricsData.get(GraphSONTokens.ID), (String)metricsData.get(GraphSONTokens.NAME)); m.setDuration(Math.round((Double) metricsData.get(GraphSONTokens.DURATION) * 1000000), TimeUnit.NANOSECONDS); for (Map.Entry<String, Long> count : ((Map<String, Long>)metricsData.getOrDefault(GraphSONTokens.COUNTS, new LinkedHashMap<>(0))).entrySet()) { m.setCount(count.getKey(), count.getValue()); } for (Map.Entry<String, Long> count : ((Map<String, Long>) metricsData.getOrDefault(GraphSONTokens.ANNOTATIONS, new LinkedHashMap<>(0))).entrySet()) { m.setAnnotation(count.getKey(), count.getValue()); } for (MutableMetrics nested : (List<MutableMetrics>)metricsData.getOrDefault(GraphSONTokens.METRICS, new ArrayList<>(0))) { m.addNested(nested); } return m; }
private static DefaultTraversalMetrics createStaticTraversalMetrics() { // based on g.V().hasLabel("person").out().out().tree().profile().next() final List<MutableMetrics> traversalMutableMetrics = new ArrayList<>(); final MutableMetrics m7 = new MutableMetrics("7.0.0()", "TinkerGraphStep(vertex,[~label.eq(person)])"); m7.setDuration(100, TimeUnit.MILLISECONDS); m7.setCount("traverserCount", 4); m7.setCount("elementCount", 4); m7.setAnnotation("percentDur", 25.0d); traversalMutableMetrics.add(m7); final MutableMetrics m2 = new MutableMetrics("2.0.0()", "VertexStep(OUT,vertex)"); m2.setDuration(100, TimeUnit.MILLISECONDS); m2.setCount("traverserCount", 13); m2.setCount("elementCount", 13); m2.setAnnotation("percentDur", 25.0d); traversalMutableMetrics.add(m2); final MutableMetrics m3 = new MutableMetrics("3.0.0()", "VertexStep(OUT,vertex)"); m3.setDuration(100, TimeUnit.MILLISECONDS); m3.setCount("traverserCount", 7); m3.setCount("elementCount", 7); m3.setAnnotation("percentDur", 25.0d); traversalMutableMetrics.add(m3); final MutableMetrics m4 = new MutableMetrics("4.0.0()", "TreeStep"); m4.setDuration(100, TimeUnit.MILLISECONDS); m4.setCount("traverserCount", 1); m4.setCount("elementCount", 1); m4.setAnnotation("percentDur", 25.0d); traversalMutableMetrics.add(m4); return new DefaultTraversalMetrics(4000, traversalMutableMetrics); }
@Override public <I extends InputShim> Metrics read(final KryoShim<I, ?> kryo, final I input, final Class<Metrics> clazz) { final MutableMetrics m = new MutableMetrics(input.readString(), input.readString()); m.setDuration(Math.round(input.readDouble() * 1000000), TimeUnit.NANOSECONDS); final Map<String,Long> counts = (Map<String,Long>) kryo.readObject(input, HashMap.class); for (Map.Entry<String, Long> count : counts.entrySet()) { m.setCount(count.getKey(), count.getValue()); } final Map<String,Object> annotations = (Map<String,Object>) kryo.readObject(input, HashMap.class); for (Map.Entry<String, Object> count : annotations.entrySet()) { m.setAnnotation(count.getKey(), count.getValue()); } final List<MutableMetrics> nesteds = (List<MutableMetrics>) kryo.readObject(input, ArrayList.class); for (MutableMetrics nested : nesteds) { m.addNested(nested); } return m; } }
@Override public void workerIterationEnd(final Memory memory) { // store profile metrics in proper ProfileStep metrics if (this.profile) { List<ProfileStep> profileSteps = TraversalHelper.getStepsOfAssignableClassRecursively(ProfileStep.class, this.traversal.get()); // guess the profile step to store data int profileStepIndex = memory.getIteration(); // if we guess wrongly write timing into last step profileStepIndex = profileStepIndex >= profileSteps.size() ? profileSteps.size() - 1 : profileStepIndex; this.iterationMetrics.finish(0); // reset counts this.iterationMetrics.setCount(TraversalMetrics.TRAVERSER_COUNT_ID,0); if (null != MemoryTraversalSideEffects.getMemorySideEffectsPhase(this.traversal.get())) { this.traversal.get().getSideEffects().add(profileSteps.get(profileStepIndex).getId(), this.iterationMetrics); } this.iterationMetrics = null; } }
@Override public void setMetrics(final MutableMetrics parentMetrics) { if (parentMetrics != null) { callbackCalled = true; parentMetrics.setCount("bogusCount", 100); } } }
private void fillChildren(List<MutableMetrics> childMetrics, SearchResult result) { if (childMetrics.size() > 0) { MutableMetrics child = childMetrics.get(0); child.setCount(TraversalMetrics.ELEMENT_COUNT_ID, result.getTotal()); child.setDuration(Long.parseLong(result.getJsonObject().get("took").toString()), TimeUnit.MILLISECONDS); } }
private <E extends Element, S extends JdbcSchema<E>> void fillChildren(List<MutableMetrics> children, Map<S, Select> schemas) { List<org.javatuples.Pair<Long, Integer>> timing = TimingExecuterListener.timing.values().stream().collect(Collectors.toList()); List<Map.Entry<S, Select>> sqls = schemas.entrySet().stream().collect(Collectors.toList()); for (int i = 0; i < sqls.size(); i++) { org.javatuples.Pair<Long, Integer> timingCount = timing.get(i); if (i < children.size()) { MutableMetrics child = children.get(i); if (timingCount != null) { child.setCount(TraversalMetrics.ELEMENT_COUNT_ID, timingCount.getValue1()); child.setDuration(timingCount.getValue0(), TimeUnit.NANOSECONDS); } } timing.remove(sqls.get(i).getValue().getSQL()); } }
@Override public Metrics createObject(final Map<String, Object> metricsData) { final MutableMetrics m = new MutableMetrics((String)metricsData.get(GraphSONTokens.ID), (String)metricsData.get(GraphSONTokens.NAME)); m.setDuration(Math.round((Double) metricsData.get(GraphSONTokens.DURATION) * 1000000), TimeUnit.NANOSECONDS); for (Map.Entry<String, Long> count : ((Map<String, Long>)metricsData.getOrDefault(GraphSONTokens.COUNTS, new HashMap<>(0))).entrySet()) { m.setCount(count.getKey(), count.getValue()); } for (Map.Entry<String, Long> count : ((Map<String, Long>) metricsData.getOrDefault(GraphSONTokens.ANNOTATIONS, new HashMap<>(0))).entrySet()) { m.setAnnotation(count.getKey(), count.getValue()); } for (MutableMetrics nested : (List<MutableMetrics>)metricsData.getOrDefault(GraphSONTokens.METRICS, new ArrayList<>(0))) { m.addNested(nested); } return m; } }
public void stop(FillChildren fillChildren) { controllerMetrics.stop(); if (metrics.isPresent()) { fillChildren.fillChildren(controllerMetrics.getNested().stream().map(m -> ((MutableMetrics) m)).collect(Collectors.toList())); controllerMetrics.setCount(TraversalMetrics.ELEMENT_COUNT_ID, controllerMetrics.getNested().stream() .mapToLong(n -> n.getCount(TraversalMetrics.ELEMENT_COUNT_ID)).sum()); } } }
@Override public Metrics deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final Map<String, Object> metricsData = deserializationContext.readValue(jsonParser, Map.class); final MutableMetrics m = new MutableMetrics((String)metricsData.get(GraphSONTokens.ID), (String)metricsData.get(GraphSONTokens.NAME)); m.setDuration(Math.round((Double) metricsData.get(GraphSONTokens.DURATION) * 1000000), TimeUnit.NANOSECONDS); for (Map.Entry<String, Long> count : ((Map<String, Long>)metricsData.getOrDefault(GraphSONTokens.COUNTS, new LinkedHashMap<>(0))).entrySet()) { m.setCount(count.getKey(), count.getValue()); } for (Map.Entry<String, Long> count : ((Map<String, Long>) metricsData.getOrDefault(GraphSONTokens.ANNOTATIONS, new LinkedHashMap<>(0))).entrySet()) { m.setAnnotation(count.getKey(), count.getValue()); } for (MutableMetrics nested : (List<MutableMetrics>)metricsData.getOrDefault(GraphSONTokens.METRICS, new ArrayList<>(0))) { m.addNested(nested); } return m; }
@Override public <I extends InputShim> Metrics read(final KryoShim<I, ?> kryo, final I input, final Class<Metrics> clazz) { final MutableMetrics m = new MutableMetrics(input.readString(), input.readString()); m.setDuration(Math.round(input.readDouble() * 1000000), TimeUnit.NANOSECONDS); final Map<String,Long> counts = (Map<String,Long>) kryo.readObject(input, HashMap.class); for (Map.Entry<String, Long> count : counts.entrySet()) { m.setCount(count.getKey(), count.getValue()); } final Map<String,Object> annotations = (Map<String,Object>) kryo.readObject(input, HashMap.class); for (Map.Entry<String, Object> count : annotations.entrySet()) { m.setAnnotation(count.getKey(), count.getValue()); } final List<MutableMetrics> nesteds = (List<MutableMetrics>) kryo.readObject(input, ArrayList.class); for (MutableMetrics nested : nesteds) { m.addNested(nested); } return m; } }
@Override public void workerIterationEnd(final Memory memory) { // store profile metrics in proper ProfileStep metrics if (this.profile) { List<ProfileStep> profileSteps = TraversalHelper.getStepsOfAssignableClassRecursively(ProfileStep.class, this.traversal.get()); // guess the profile step to store data int profileStepIndex = memory.getIteration(); // if we guess wrongly write timing into last step profileStepIndex = profileStepIndex >= profileSteps.size() ? profileSteps.size() - 1 : profileStepIndex; this.iterationMetrics.finish(0); // reset counts this.iterationMetrics.setCount(TraversalMetrics.TRAVERSER_COUNT_ID,0); if (null != MemoryTraversalSideEffects.getMemorySideEffectsPhase(this.traversal.get())) { this.traversal.get().getSideEffects().add(profileSteps.get(profileStepIndex).getId(), this.iterationMetrics); } this.iterationMetrics = null; } }