Ejemplo n.º 1
0
  /**
   * This method converts the given tree completely into dot code.
   *
   * @param root The root of the tree.
   * @param ps The stream in which the dot code will be written.
   * @param includeWeights Determines whether to include weights or not.
   * @param includeEois Determines whether to include the execution order indices or not.
   * @param shortLabels Determines whether to use short labels or not.
   */
  private static void dotFromCallingTree(
      final AbstractCallTreeNode<?> root,
      final PrintStream ps,
      final boolean includeWeights,
      final boolean includeEois,
      final boolean shortLabels) {
    // preamble:
    ps.println("digraph G {");
    final StringBuilder edgestringBuilder = new StringBuilder();

    final Map<AbstractCallTreeNode<?>, Integer> nodeIds =
        new Hashtable<AbstractCallTreeNode<?>, Integer>(); // NOPMD (not synchronized)

    AbstractCallTreeFilter.dotEdgesFromSubTree(
        root, nodeIds, new AtomicInteger(0), ps, shortLabels);
    AbstractCallTreeFilter.dotVerticesFromSubTree(
        root,
        includeEois ? new AtomicInteger(1) : null,
        nodeIds,
        ps,
        includeWeights); // NOPMD NOCS (null)

    ps.println(edgestringBuilder.toString());
    ps.println("}");
  }
Ejemplo n.º 2
0
 /**
  * Traverse tree recursively and generate dot code for vertices.
  *
  * @param n The root node.
  * @param eoiCounter The counter for the execution order index.
  * @param nodeIds The map containing the node IDs.
  * @param ps The stream on which the generated code will be printed.
  * @param includeWeights Determines whether to include weights or not.
  */
 private static void dotVerticesFromSubTree(
     final AbstractCallTreeNode<?> n,
     final AtomicInteger eoiCounter,
     final Map<AbstractCallTreeNode<?>, Integer> nodeIds,
     final PrintStream ps,
     final boolean includeWeights) {
   final int thisId = nodeIds.get(n);
   for (final WeightedDirectedCallTreeEdge<?> child : n.getChildEdges()) {
     final StringBuilder strBuild = new StringBuilder(1024);
     final int childId = nodeIds.get(child.getTarget());
     strBuild
         .append('\n')
         .append(thisId)
         .append("->")
         .append(childId)
         .append("[style=solid,arrowhead=none");
     if (includeWeights) {
       strBuild.append(",label=\"").append(child.getTargetWeight().get()).append('"');
     } else if (eoiCounter != null) {
       strBuild.append(",label=\"").append(eoiCounter.getAndIncrement()).append(".\"");
     }
     strBuild.append(" ]");
     ps.println(strBuild.toString());
     AbstractCallTreeFilter.dotVerticesFromSubTree(
         child.getTarget(), eoiCounter, nodeIds, ps, includeWeights);
   }
 }