org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphSONSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public TraversalMetrics deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    final Map<String, Object> traversalMetricsData = deserializationContext.readValue(jsonParser, Map.class);

    return new DefaultTraversalMetrics(
            Math.round((Double) traversalMetricsData.get(GraphSONTokens.DURATION) * 1000000),
            (List<MutableMetrics>) traversalMetricsData.get(GraphSONTokens.METRICS)
    );
}
 
Example #2
Source File: Model.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #3
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void deserializersTestsMetrics() {
    final TinkerGraph tg = TinkerFactory.createModern();

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b").
            out("knows").out("created").as("c").
            has("name", "ripple").values("name").as("d").
            identity().as("e").profile().next();

    final MutableMetrics m = new MutableMetrics(tm.getMetrics(0));
    // making sure nested metrics are included in serde
    m.addNested(new MutableMetrics(tm.getMetrics(1)));

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, m);
        final String json = out.toString();

        final Metrics metricsRead = (Metrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        // toString should be enough to compare Metrics
        assertTrue(m.toString().equals(metricsRead.toString()));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
Example #4
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void setMetrics(final MutableMetrics parentMetrics) {
    if (parentMetrics != null) {
        callbackCalled = true;
        parentMetrics.setCount("bogusCount", 100);
    }
}
 
Example #5
Source File: TraversalVertexProgram.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void workerIterationStart(final Memory memory) {
    // start collecting profile metrics
    if (this.profile) {
        this.iterationMetrics = new MutableMetrics("iteration" + memory.getIteration(), "Worker Iteration " + memory.getIteration());
        this.iterationMetrics.start();
    }
}
 
Example #6
Source File: ProfileStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #7
Source File: MetricsSerializer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
protected Metrics readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException {
    // 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;
}
 
Example #8
Source File: GraphSONSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public TraversalMetrics createObject(final Map<String, Object> traversalMetricsData) {
    return new DefaultTraversalMetrics(
            Math.round((Double) traversalMetricsData.get(GraphSONTokens.DURATION) * 1000000),
            (List<MutableMetrics>) traversalMetricsData.get(GraphSONTokens.METRICS)
    );
}
 
Example #9
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Test
public void deserializersTestsMetrics() {
    final TinkerGraph tg = TinkerFactory.createModern();

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b").
            out("knows").out("created").as("c").
            has("name", "ripple").values("name").as("d").
            identity().as("e").profile().next();

    final MutableMetrics m = new MutableMetrics(tm.getMetrics(0));
    // making sure nested metrics are included in serde
    m.addNested(new MutableMetrics(tm.getMetrics(1)));

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, m);
        final String json = out.toString();

        final Metrics metricsRead = (Metrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        // toString should be enough to compare Metrics
        assertTrue(m.toString().equals(metricsRead.toString()));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
Example #10
Source File: GryoSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public <I extends InputShim> TraversalMetrics read(final KryoShim<I, ?> kryo, final I input, final Class<TraversalMetrics> clazz) {
    final double duration = input.readDouble();
    final int size = input.readInt();

    final List<MutableMetrics> orderedMetrics = new ArrayList<>();
    for (int ix = 0; ix < size; ix++) {
        orderedMetrics.add(kryo.readObject(input, MutableMetrics.class));
    }

    return new DefaultTraversalMetrics(Math.round(duration * 1000000), orderedMetrics);
}
 
Example #11
Source File: TypeSerializerFailureTests.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "Value={0}")
public static Collection input() {
    final Bytecode.Binding b = new Bytecode.Binding(null, "b");

    final ReferenceVertex vertex = new ReferenceVertex("a vertex", null);

    final Bytecode bytecode = new Bytecode();
    bytecode.addStep(null);

    final BulkSet<Object> bulkSet = new BulkSet<>();
    bulkSet.add(vertex, 1L);

    final MutableMetrics metrics = new MutableMetrics("a metric", null);

    final Tree<Vertex> tree = new Tree<>();
    tree.put(vertex, null);

    // Provide instances that are malformed for serialization to fail
    return Arrays.asList(
            b,
            vertex,
            Collections.singletonMap("one", b),
            bulkSet,
            bytecode,
            Collections.singletonList(vertex),
            new ReferenceEdge("an edge", null, vertex, vertex),
            Lambda.supplier(null),
            metrics,
            new DefaultTraversalMetrics(1L, Collections.singletonList(metrics)),
            new DefaultRemoteTraverser<>(new Object(), 1L),
            tree,
            new ReferenceVertexProperty<>("a prop", null, "value"),
            new InvalidPath()
    );
}
 
Example #12
Source File: TP3ProfileWrapper.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: TP3ProfileWrapper.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: ProfileStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public MutableMetrics getMetrics() {
    return metrics;
}
 
Example #15
Source File: TP3ProfileWrapper.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
public TP3ProfileWrapper(MutableMetrics metrics) {
    this.metrics = metrics;
}
 
Example #16
Source File: JanusGraphVertexStep.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void setMetrics(MutableMetrics metrics) {
    queryProfiler = new TP3ProfileWrapper(metrics);
}
 
Example #17
Source File: MutableMetricsSupplier.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public MutableMetrics get() {
    return new MutableMetrics(this.stepId, this.stepString);
}
 
Example #18
Source File: JanusGraphPropertiesStep.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void setMetrics(MutableMetrics metrics) {
    queryProfiler = new TP3ProfileWrapper(metrics);
}
 
Example #19
Source File: ProfileStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public MutableMetrics apply(final MutableMetrics metricsA, final MutableMetrics metricsB) {
    metricsA.aggregate(metricsB);
    return metricsA;
}
 
Example #20
Source File: ProfileStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public MemoryComputeKey<MutableMetrics> getMemoryComputeKey() {
    return MemoryComputeKey.of(this.getId(), ProfileBiOperator.instance(), false, true);
}
 
Example #21
Source File: JanusGraphEdgeVertexStep.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void setMetrics(MutableMetrics metrics) {
    queryProfiler = new TP3ProfileWrapper(metrics);
}
 
Example #22
Source File: TitanVertexStep.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public void setMetrics(MutableMetrics metrics) {
    queryProfiler = new TP3ProfileWrapper(metrics);
}
 
Example #23
Source File: TraversalMetricsSerializer.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
protected TraversalMetrics readValue(Buffer buffer, GraphBinaryReader context) throws IOException {
    Long durationNanos = context.readValue(buffer, Long.class, false);
    final List<MutableMetrics> metrics = new ArrayList<>(collectionSerializer.readValue(buffer, context));
    return new DefaultTraversalMetrics(durationNanos, metrics);
}
 
Example #24
Source File: JanusGraphStep.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void setMetrics(MutableMetrics metrics) {
    queryProfiler = new TP3ProfileWrapper(metrics);
}
 
Example #25
Source File: TP3ProfileWrapper.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public TP3ProfileWrapper(MutableMetrics metrics) {
    this.metrics = metrics;
}
 
Example #26
Source File: TitanGraphStep.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public void setMetrics(MutableMetrics metrics) {
    queryProfiler = new TP3ProfileWrapper(metrics);
}
 
Example #27
Source File: TitanPropertiesStep.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public void setMetrics(MutableMetrics metrics) {
    queryProfiler = new TP3ProfileWrapper(metrics);
}
 
Example #28
Source File: Profiling.java    From tinkerpop with Apache License 2.0 votes vote down vote up
public void setMetrics(final MutableMetrics metrics);