Skip to content
Snippets Groups Projects
Commit a654a607 authored by Sören Henning's avatar Sören Henning
Browse files

Update graph labels

parent b12521ed
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
...@@ -10,13 +10,22 @@ import kieker.analysis.traceanalysisdomain.AbstractOperationCall; ...@@ -10,13 +10,22 @@ import kieker.analysis.traceanalysisdomain.AbstractOperationCall;
public abstract class AbstractTraceToGraphTransformer<C extends AbstractOperationCall<C>> extends OperationCallVisitor<C> { public abstract class AbstractTraceToGraphTransformer<C extends AbstractOperationCall<C>> extends OperationCallVisitor<C> {
protected final Graph graph; protected final Graph graph;
private final C rootOperationCall;
public AbstractTraceToGraphTransformer() { public AbstractTraceToGraphTransformer() {
this(null);
}
public AbstractTraceToGraphTransformer(final C rootOperartionCall) {
super(); super();
this.graph = new TinkerGraph(); this.graph = new TinkerGraph();
this.rootOperationCall = rootOperartionCall;
} }
public Graph getGraph() { public Graph getGraph() {
addRootVertex();
return graph; return graph;
} }
...@@ -31,6 +40,24 @@ public abstract class AbstractTraceToGraphTransformer<C extends AbstractOperatio ...@@ -31,6 +40,24 @@ public abstract class AbstractTraceToGraphTransformer<C extends AbstractOperatio
} }
private void addRootVertex() {
if (rootOperationCall == null) {
return;
}
final Vertex realRootVertex = graph.getVertex(rootOperationCall.hashCode());
if (realRootVertex == null) {
return;
}
final Vertex rootVertex = graph.addVertex("Entry");
rootVertex.setProperty("label", "'Entry'");
graph.addEdge(null, rootVertex, realRootVertex, "1.");
}
protected abstract Vertex addVertex(C operationCall); protected abstract Vertex addVertex(C operationCall);
protected abstract Edge addEdge(C operationCall, C parentOperationCall); protected abstract Edge addEdge(C operationCall, C parentOperationCall);
... ...
......
...@@ -4,15 +4,37 @@ import com.tinkerpop.blueprints.Edge; ...@@ -4,15 +4,37 @@ import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import kieker.analysis.traceanalysisdomain.AggregatedOperationCall; import kieker.analysis.traceanalysisdomain.AggregatedOperationCall;
import kieker.analysis.util.NameConverter;
public class AggrTraceToGraphTransformer extends AbstractTraceToGraphTransformer<AggregatedOperationCall> { public class AggrTraceToGraphTransformer extends AbstractTraceToGraphTransformer<AggregatedOperationCall> {
public AggrTraceToGraphTransformer() {
super();
}
public AggrTraceToGraphTransformer(final AggregatedOperationCall rootOperartionCall) {
super(rootOperartionCall);
}
@Override @Override
protected Vertex addVertex(final AggregatedOperationCall operationCall) { protected Vertex addVertex(final AggregatedOperationCall operationCall) {
Vertex vertex = graph.addVertex(operationCall.hashCode()); Vertex vertex = graph.addVertex(operationCall.hashCode());
vertex.setProperty("label", operationCall.getOperation()); String name = operationCall.getOperation();
String stackDepth = String.valueOf(operationCall.getStackDepth() + 1);
String component = operationCall.getComponent();
String container = operationCall.getContainer();
Boolean shortNames = true; // TODO hard coded
if (shortNames) {
name = NameConverter.toShortOperationName(name);
}
String label = container + "::\\n" + "@" + stackDepth + ":" + component + "\\n" + name;
vertex.setProperty("label", label);
return vertex; return vertex;
} }
...@@ -27,8 +49,7 @@ public class AggrTraceToGraphTransformer extends AbstractTraceToGraphTransformer ...@@ -27,8 +49,7 @@ public class AggrTraceToGraphTransformer extends AbstractTraceToGraphTransformer
return null; return null;
} }
// TODO Add label return graph.addEdge(null, parentVertex, thisVertex, String.valueOf(operationCall.getOrderIndex() + 1) + '.');
return graph.addEdge(null, parentVertex, thisVertex, String.valueOf(operationCall.getOrderIndex()) + '.');
} }
} }
...@@ -10,7 +10,7 @@ public class AggrTraceTraverserStage extends AbstractTransformation<AggregatedTr ...@@ -10,7 +10,7 @@ public class AggrTraceTraverserStage extends AbstractTransformation<AggregatedTr
@Override @Override
protected void execute(final AggregatedTrace trace) { protected void execute(final AggregatedTrace trace) {
AggrTraceToGraphTransformer aggrTrace2Blueprint = new AggrTraceToGraphTransformer(); AggrTraceToGraphTransformer aggrTrace2Blueprint = new AggrTraceToGraphTransformer(trace.getRootOperationCall());
TraceTraverser<AggregatedTrace, AggregatedOperationCall> traverser = new TraceTraverser<>(aggrTrace2Blueprint); TraceTraverser<AggregatedTrace, AggregatedOperationCall> traverser = new TraceTraverser<>(aggrTrace2Blueprint);
... ...
......
...@@ -4,14 +4,36 @@ import com.tinkerpop.blueprints.Edge; ...@@ -4,14 +4,36 @@ import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import kieker.analysis.traceanalysisdomain.OperationCall; import kieker.analysis.traceanalysisdomain.OperationCall;
import kieker.analysis.util.NameConverter;
public class TraceToGraphTransformer extends AbstractTraceToGraphTransformer<OperationCall> { public class TraceToGraphTransformer extends AbstractTraceToGraphTransformer<OperationCall> {
public TraceToGraphTransformer() {
super();
}
public TraceToGraphTransformer(final OperationCall rootOperartionCall) {
super(rootOperartionCall);
}
@Override @Override
protected Vertex addVertex(final OperationCall operationCall) { protected Vertex addVertex(final OperationCall operationCall) {
Vertex vertex = graph.addVertex(operationCall.hashCode()); Vertex vertex = graph.addVertex(operationCall.hashCode());
vertex.setProperty("label", operationCall.getOperation()); String name = operationCall.getOperation();
String stackDepth = String.valueOf(operationCall.getStackDepth() + 1);
String component = operationCall.getComponent();
String container = operationCall.getContainer();
Boolean shortNames = true; // TODO hard coded
if (shortNames) {
name = NameConverter.toShortOperationName(name);
}
String label = container + "::\\n" + "@" + stackDepth + ":" + component + "\\n" + name;
vertex.setProperty("label", label);
return vertex; return vertex;
} }
...@@ -26,8 +48,7 @@ public class TraceToGraphTransformer extends AbstractTraceToGraphTransformer<Ope ...@@ -26,8 +48,7 @@ public class TraceToGraphTransformer extends AbstractTraceToGraphTransformer<Ope
return null; return null;
} }
// TODO Add label return graph.addEdge(null, parentVertex, thisVertex, String.valueOf(operationCall.getOrderIndex() + 1) + '.');
return graph.addEdge(null, parentVertex, thisVertex, String.valueOf(operationCall.getOrderIndex()) + '.');
} }
} }
...@@ -10,7 +10,7 @@ public class TraceTraverserStage extends AbstractTransformation<Trace, NamedGrap ...@@ -10,7 +10,7 @@ public class TraceTraverserStage extends AbstractTransformation<Trace, NamedGrap
@Override @Override
protected void execute(final Trace trace) { protected void execute(final Trace trace) {
TraceToGraphTransformer traceToGraph = new TraceToGraphTransformer(); TraceToGraphTransformer traceToGraph = new TraceToGraphTransformer(trace.getRootOperationCall());
TraceTraverser<Trace, OperationCall> traverser = new TraceTraverser<>(traceToGraph); TraceTraverser<Trace, OperationCall> traverser = new TraceTraverser<>(traceToGraph);
... ...
......
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.util;
import java.util.HashMap;
import java.util.Map;
/**
* @author Nils Christian Ehmke
*
* @param <I>
* The type of the keys.
* @param <O>
* The type of the values.
*/
public final class Mapper<I, O> extends HashMap<I, O> {
private static final long serialVersionUID = 1L;
private O defaultValue;
public To map(final I key) {
return new To(key);
}
public To mapPerDefault() {
return new To();
}
public O resolve(final I key) {
if (super.containsKey(key)) {
return super.get(key);
} else {
return this.defaultValue;
}
}
public I invertedResolve(final O value) {
return super.entrySet().parallelStream().filter(entry -> value.equals(entry.getValue())).map(Map.Entry::getKey).findFirst().orElse(null);
}
/**
* @author Nils Christian Ehmke
*/
public final class To {
private final I key;
private final boolean keyAvailable;
protected To(final I key) {
this.key = key;
this.keyAvailable = true;
}
protected To() {
this.key = null;
this.keyAvailable = false;
}
public void to(final O value) {
if (this.keyAvailable) {
Mapper.super.put(this.key, value);
} else {
Mapper.this.defaultValue = value;
}
}
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.util;
import java.util.concurrent.TimeUnit;
/**
* @author Nils Christian Ehmke
*/
public final class NameConverter {
private static Mapper<TimeUnit, String> shortTimeUnitMapper = new Mapper<>();
private NameConverter() {}
static {
initializeMapper();
}
private static void initializeMapper() {
NameConverter.shortTimeUnitMapper.map(TimeUnit.NANOSECONDS).to("ns");
NameConverter.shortTimeUnitMapper.map(TimeUnit.MICROSECONDS).to("us");
NameConverter.shortTimeUnitMapper.map(TimeUnit.MILLISECONDS).to("ms");
NameConverter.shortTimeUnitMapper.map(TimeUnit.SECONDS).to("s");
NameConverter.shortTimeUnitMapper.map(TimeUnit.MINUTES).to("m");
NameConverter.shortTimeUnitMapper.map(TimeUnit.HOURS).to("h");
NameConverter.shortTimeUnitMapper.map(TimeUnit.DAYS).to("d");
NameConverter.shortTimeUnitMapper.mapPerDefault().to("");
}
public static String toShortTimeUnit(final TimeUnit timeUnit) {
return NameConverter.shortTimeUnitMapper.resolve(timeUnit);
}
public static String toShortComponentName(final String componentName) {
final int lastPointPos = componentName.lastIndexOf('.');
return componentName.substring(lastPointPos + 1);
}
public static String toShortOperationName(final String operationName) {
final String result = operationName.replaceAll("\\(.*\\)", "(...)");
final int lastPointPos = result.lastIndexOf('.', result.length() - 5);
return result.substring(lastPointPos + 1);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment