# HG changeset patch # User Andreas Woess # Date 1447181969 -3600 # Node ID 364bab1763c9eae16c50e16bb553b9abdaa7376f # Parent ef3c3b62e0fcca12de20283ba0f3f958971301ab add option for dumping shapes to a DOT file diff -r ef3c3b62e0fc -r 364bab1763c9 truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java Tue Nov 10 20:13:14 2015 +0100 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java Tue Nov 10 19:59:29 2015 +0100 @@ -22,13 +22,17 @@ */ package com.oracle.truffle.object; -import com.oracle.truffle.object.debug.JSONShapeVisitor; +import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.nio.file.Paths; import java.util.Collection; import java.util.concurrent.ConcurrentLinkedQueue; +import com.oracle.truffle.object.debug.GraphvizShapeVisitor; +import com.oracle.truffle.object.debug.JSONShapeVisitor; + class Debug { private static Collection allShapes; @@ -44,7 +48,30 @@ if (ObjectStorageOptions.DumpShapes) { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { - try (PrintWriter out = new PrintWriter("shapes.json", "UTF-8")) { + try { + if (ObjectStorageOptions.DumpShapesDOT) { + dumpDOT(); + } + if (ObjectStorageOptions.DumpShapesJSON) { + dumpJSON(); + } + } catch (FileNotFoundException | UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + private void dumpDOT() throws FileNotFoundException, UnsupportedEncodingException { + try (PrintWriter out = new PrintWriter(getOutputFile("dot"), "UTF-8")) { + GraphvizShapeVisitor visitor = new GraphvizShapeVisitor(); + for (ShapeImpl shape : allShapes) { + shape.accept(visitor); + } + out.println(visitor); + } + } + + private void dumpJSON() throws FileNotFoundException, UnsupportedEncodingException { + try (PrintWriter out = new PrintWriter(getOutputFile("json"), "UTF-8")) { out.println("{\"shapes\": ["); boolean first = true; for (ShapeImpl shape : allShapes) { @@ -58,10 +85,12 @@ out.println(); } out.println("]}"); - } catch (FileNotFoundException | UnsupportedEncodingException e) { - throw new RuntimeException(e); } } + + private File getOutputFile(String extension) { + return Paths.get(ObjectStorageOptions.DumpShapesPath, "shapes." + extension).toFile(); + } })); } } diff -r ef3c3b62e0fc -r 364bab1763c9 truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java Tue Nov 10 20:13:14 2015 +0100 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java Tue Nov 10 19:59:29 2015 +0100 @@ -40,7 +40,10 @@ // Debug options (should be final) public static final boolean DebugCounters = booleanOption(OPTION_PREFIX + "DebugCounters", true); public static final boolean TraceReshape = booleanOption(OPTION_PREFIX + "TraceReshape", false); - public static final boolean DumpShapes = booleanOption(OPTION_PREFIX + "DumpShapes", false); + public static final boolean DumpShapesDOT = booleanOption(OPTION_PREFIX + "DumpShapesDOT", false); + public static final boolean DumpShapesJSON = booleanOption(OPTION_PREFIX + "DumpShapesJSON", false); + public static final boolean DumpShapes = DumpShapesDOT || DumpShapesJSON; + public static final String DumpShapesPath = System.getProperty(OPTION_PREFIX + "DumpShapesPath", ""); public static final boolean Profile = booleanOption(OPTION_PREFIX + "Profile", false); public static final int ProfileTopResults = Integer.getInteger(OPTION_PREFIX + "ProfileTopResults", -1); diff -r ef3c3b62e0fc -r 364bab1763c9 truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/GraphvizShapeVisitor.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/GraphvizShapeVisitor.java Tue Nov 10 20:13:14 2015 +0100 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/GraphvizShapeVisitor.java Tue Nov 10 19:59:29 2015 +0100 @@ -42,7 +42,7 @@ @Override public GraphvizShapeVisitor visitShape(Shape shape, Map transitions) { if (!drawn.add(shape)) { - return null; + return this; } String prefix = "s";