@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; }
@Override protected Metrics readValue(final ByteBuf buffer, final GraphBinaryReader context) throws SerializationException { // Consider using a custom implementation, like "DefaultMetrics" final MutableMetrics result = new MutableMetrics( context.readValue(buffer, String.class, false), context.readValue(buffer, String.class, false)); result.setDuration(context.readValue(buffer, Long.class, false), TimeUnit.NANOSECONDS); final Map<String, Long> counts = context.readValue(buffer, Map.class, false); counts.forEach(result::setCount); final Map<String, Object> annotations = context.readValue(buffer, Map.class, false); annotations.forEach(result::setAnnotation); final Collection<MutableMetrics> nestedMetrics = collectionSerializer.readValue(buffer, context); nestedMetrics.forEach(result::addNested); return result; }
@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; } }
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); }
metrics.setDuration(metrics.getDuration(TimeUnit.NANOSECONDS) - prevDur, TimeUnit.NANOSECONDS); prevDur = durBeforeAdjustment;
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; } }
@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 Metrics readValue(final ByteBuf buffer, final GraphBinaryReader context) throws SerializationException { // Consider using a custom implementation, like "DefaultMetrics" final MutableMetrics result = new MutableMetrics( context.readValue(buffer, String.class, false), context.readValue(buffer, String.class, false)); result.setDuration(context.readValue(buffer, Long.class, false), TimeUnit.NANOSECONDS); final Map<String, Long> counts = context.readValue(buffer, Map.class, false); counts.forEach(result::setCount); final Map<String, Object> annotations = context.readValue(buffer, Map.class, false); annotations.forEach(result::setAnnotation); final Collection<MutableMetrics> nestedMetrics = collectionSerializer.readValue(buffer, context); nestedMetrics.forEach(result::addNested); return result; }
@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; } }
metrics.setDuration(metrics.getDuration(TimeUnit.NANOSECONDS) - prevDur, TimeUnit.NANOSECONDS); prevDur = durBeforeAdjustment;