From ba601cc929c1c3c47bf415e8454583d768f5564a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Henning?= <stu114708@informatik.uni-kiel.de> Date: Mon, 20 Jun 2016 17:47:32 +0200 Subject: [PATCH] worked on ConfigurationFactory for dot export --- ...otDependencyGraphConfigurationFactory.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/src/main/java/kieker/analysis/dev/dependencygraphs/DotDependencyGraphConfigurationFactory.java b/src/main/java/kieker/analysis/dev/dependencygraphs/DotDependencyGraphConfigurationFactory.java index 1428e27f..ba16cdf9 100644 --- a/src/main/java/kieker/analysis/dev/dependencygraphs/DotDependencyGraphConfigurationFactory.java +++ b/src/main/java/kieker/analysis/dev/dependencygraphs/DotDependencyGraphConfigurationFactory.java @@ -1,7 +1,17 @@ package kieker.analysis.dev.dependencygraphs; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +import kieker.analysis.util.graph.Vertex; import kieker.analysis.util.graph.export.dot.DotExportConfiguration; +import kieker.analysis.util.graph.util.dot.attributes.DotClusterAttribute; +import kieker.analysis.util.graph.util.dot.attributes.DotEdgeAttribute; import kieker.analysis.util.graph.util.dot.attributes.DotGraphAttribute; +import kieker.analysis.util.graph.util.dot.attributes.DotNodeAttribute; public class DotDependencyGraphConfigurationFactory { @@ -10,6 +20,8 @@ public class DotDependencyGraphConfigurationFactory { configuration.addGraphAttribute(DotGraphAttribute.RANKDIR, g -> "LR"); + configuration.addNodeAttribute(DotNodeAttribute.LABEL, new VertexLabelMapper("<<assembly component>>")); + return configuration; } @@ -18,6 +30,9 @@ public class DotDependencyGraphConfigurationFactory { configuration.addGraphAttribute(DotGraphAttribute.RANKDIR, g -> "LR"); + configuration.addClusterAttribute(DotClusterAttribute.LABEL, new ClusterLabelMapper("<<assembly component>>")); + configuration.addNodeAttribute(DotNodeAttribute.LABEL, new VertexLabelMapper()); + return configuration; } @@ -25,6 +40,10 @@ public class DotDependencyGraphConfigurationFactory { DotExportConfiguration configuration = new DotExportConfiguration(); configuration.addGraphAttribute(DotGraphAttribute.RANKDIR, g -> "LR"); + configuration.addEdgeAttribute(DotEdgeAttribute.LABEL, (e -> e.getProperty("calls").toString())); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box3d"); + configuration.addNodeAttribute(DotNodeAttribute.LABEL, new VertexLabelMapper("<<execution container>>")); return configuration; } @@ -33,6 +52,11 @@ public class DotDependencyGraphConfigurationFactory { DotExportConfiguration configuration = new DotExportConfiguration(); configuration.addGraphAttribute(DotGraphAttribute.RANKDIR, g -> "LR"); + configuration.addEdgeAttribute(DotEdgeAttribute.LABEL, (e -> e.getProperty("calls").toString())); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box"); + configuration.addClusterAttribute(DotClusterAttribute.LABEL, new ClusterLabelMapper("<<execution container>>")); + configuration.addNodeAttribute(DotNodeAttribute.LABEL, new VertexLabelMapper("<<deployment component>>")); return configuration; } @@ -41,8 +65,83 @@ public class DotDependencyGraphConfigurationFactory { DotExportConfiguration configuration = new DotExportConfiguration(); configuration.addGraphAttribute(DotGraphAttribute.RANKDIR, g -> "LR"); + configuration.addEdgeAttribute(DotEdgeAttribute.LABEL, (e -> e.getProperty("calls").toString())); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "oval"); + configuration.addClusterAttribute(DotClusterAttribute.LABEL, new ClusterLabelMapper("<<execution container>>", "<<deployment component>>")); + configuration.addNodeAttribute(DotNodeAttribute.LABEL, new VertexLabelMapper()); return configuration; } + private class VertexLabelMapper implements Function<Vertex, String> { + + private final String annotation; + + public VertexLabelMapper() { + this.annotation = ""; + } + + public VertexLabelMapper(final String annotation) { + this.annotation = annotation; + } + + @Override + public String apply(final Vertex vertex) { + final StringBuilder statistics = new StringBuilder(); + statistics.append(this.annotation); + statistics.append("\\n"); + statistics.append(vertex.getProperty("Name").toString()); + statistics.append("\\n"); + statistics.append(generateStatistics(vertex)); + return statistics.toString(); + } + + private String generateStatistics(final Vertex vertex) { + final String temporalUnit = "xs"; // TODO temp + final List<String> statisticStrings = new ArrayList<>(5); + if (vertex.getProperty("MinDuration") != null) { + statisticStrings.add("min: " + vertex.getProperty("MinDuration").toString() + temporalUnit); + } + if (vertex.getProperty("MaxDuration") != null) { + statisticStrings.add("max: " + vertex.getProperty("MaxDuration").toString() + temporalUnit); + } + if (vertex.getProperty("TotalDuration") != null) { + statisticStrings.add("total: " + vertex.getProperty("TotalDuration").toString() + temporalUnit); + } + if (vertex.getProperty("MeanDuration") != null) { + statisticStrings.add("avg: " + vertex.getProperty("MeanDuration").toString() + temporalUnit); + } + if (vertex.getProperty("MedianDuration") != null) { + statisticStrings.add("med: " + vertex.getProperty("MedianDuration").toString() + temporalUnit); + } + + // If there are more than 3 statistics elements add a line break after the 3rd last + if (statisticStrings.size() > 3) { + final int thirdLast = statisticStrings.size() - 3; + statisticStrings.set(thirdLast, statisticStrings.get(thirdLast).concat("\\n")); + } + + return statisticStrings.stream().collect(Collectors.joining(", ")); + } + + } + + private class ClusterLabelMapper implements Function<Vertex, String> { + + private final List<String> annotations; + + public ClusterLabelMapper(final String... annotations) { + this.annotations = Arrays.asList(annotations); + } + + @Override + public String apply(final Vertex vertex) { + + // TODO Get "level" of this vertex + return this.annotations.get(0) + "\\n" + vertex.getProperty("Name").toString(); + } + + } + } -- GitLab