@Override public QueryProfiler addNested(String groupName) { //Flatten out AND/OR nesting if (groupName.equals(AND_QUERY) || groupName.equals(OR_QUERY)) return this; int nextId = (subMetricCounter++); MutableMetrics nested = new MutableMetrics(metrics.getId()+"."+groupName+"_"+nextId,groupName); metrics.addNested(nested); return new TP3ProfileWrapper(nested); }
@Override public QueryProfiler addNested(String groupName) { //Flatten out AND/OR nesting if (groupName.equals(AND_QUERY) || groupName.equals(OR_QUERY)) return this; int nextId = (subMetricCounter++); MutableMetrics nested = new MutableMetrics(metrics.getId()+"."+groupName+"_"+nextId,groupName); metrics.addNested(nested); return new TP3ProfileWrapper(nested); }
@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; }
/** * Create a {@code MutableMetrics} from an immutable one. */ public MutableMetrics(final Metrics other) { this.id = other.getId(); this.name = other.getName(); this.annotations.putAll(other.getAnnotations()); this.durationNs = other.getDuration(TimeUnit.NANOSECONDS); other.getCounts().forEach((key, count) -> this.counts.put(key, new AtomicLong(count))); other.getNested().forEach(nested -> this.addNested(new MutableMetrics(nested))); }
@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; } }
parentMetrics.addNested(metrics);
final TraversalMetrics tm = createStaticTraversalMetrics(); final MutableMetrics metrics = new MutableMetrics(tm.getMetrics("7.0.0()")); metrics.addNested(new MutableMetrics(tm.getMetrics("3.0.0()"))); addGraphProcessEntry(metrics, "Metrics", "", noTypeGraphSONPlusGryo3_3_0); addGraphProcessEntry(P.gt(0), "P", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
@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 public QueryProfiler addNested(String groupName) { //Flatten out AND/OR nesting if (groupName.equals(AND_QUERY) || groupName.equals(OR_QUERY)) return this; int nextId = (subMetricCounter++); MutableMetrics nested = new MutableMetrics(metrics.getId()+"."+groupName+"_"+nextId,groupName); metrics.addNested(nested); return new TP3ProfileWrapper(nested); }
public MetricsRunner(SimpleController controller, UniQuery query, Collection<ElementSchema> schemas) { if (query.getStepDescriptor() != null) { this.metrics = query.getStepDescriptor().getMetrics(); this.controllerMetrics = new MutableMetrics(query.getStepDescriptor().getId() + controller.toString(), controller.toString()); } else { this.metrics = Optional.empty(); this.controllerMetrics = new MutableMetrics(controller.toString(), controller.toString()); } metrics.ifPresent(metric -> metric.addNested(controllerMetrics)); controllerMetrics.start(); List<MutableMetrics> childMetrics = schemas.stream().map((schema) -> new MutableMetrics(controllerMetrics.getId() + schema.toString(), schema.toString())).collect(Collectors.toList()); childMetrics.forEach(controllerMetrics::addNested); }
/** * Create a {@code MutableMetrics} from an immutable one. */ public MutableMetrics(final Metrics other) { this.id = other.getId(); this.name = other.getName(); this.annotations.putAll(other.getAnnotations()); this.durationNs = other.getDuration(TimeUnit.NANOSECONDS); other.getCounts().forEach((key, count) -> this.counts.put(key, new AtomicLong(count))); other.getNested().forEach(nested -> this.addNested(new MutableMetrics(nested))); }
@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; } }
parentMetrics.addNested(metrics);