changeset 22356:364bab1763c9

add option for dumping shapes to a DOT file
author Andreas Woess <andreas.woess@oracle.com>
date Tue, 10 Nov 2015 19:59:29 +0100
parents ef3c3b62e0fc
children 9c1d40221bf9
files truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/GraphvizShapeVisitor.java
diffstat 3 files changed, 38 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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<ShapeImpl> 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();
+                }
             }));
         }
     }
--- 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);
--- 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<? extends Transition, ? extends Shape> transitions) {
         if (!drawn.add(shape)) {
-            return null;
+            return this;
         }
 
         String prefix = "s";