changeset 22357:9c1d40221bf9

add option for dumping shapes to IGV
author Andreas Woess <andreas.woess@oracle.com>
date Tue, 10 Nov 2015 19:59:37 +0100
parents 364bab1763c9
children a647534602a6
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/IGVShapeVisitor.java
diffstat 3 files changed, 101 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java	Tue Nov 10 19:59:29 2015 +0100
+++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java	Tue Nov 10 19:59:37 2015 +0100
@@ -30,7 +30,9 @@
 import java.util.Collection;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
+import com.oracle.truffle.api.nodes.GraphPrintVisitor;
 import com.oracle.truffle.object.debug.GraphvizShapeVisitor;
+import com.oracle.truffle.object.debug.IGVShapeVisitor;
 import com.oracle.truffle.object.debug.JSONShapeVisitor;
 
 class Debug {
@@ -55,6 +57,9 @@
                         if (ObjectStorageOptions.DumpShapesJSON) {
                             dumpJSON();
                         }
+                        if (ObjectStorageOptions.DumpShapesIGV) {
+                            dumpIGV();
+                        }
                     } catch (FileNotFoundException | UnsupportedEncodingException e) {
                         throw new RuntimeException(e);
                     }
@@ -88,6 +93,32 @@
                     }
                 }
 
+                private void dumpIGV() {
+                    GraphPrintVisitor printer = new GraphPrintVisitor();
+                    printer.beginGroup("shapes");
+                    IGVShapeVisitor visitor = new IGVShapeVisitor(printer);
+                    for (ShapeImpl shape : allShapes) {
+                        if (isRootShape(shape)) {
+                            printer.beginGraph(DebugShapeVisitor.getId(shape));
+                            shape.accept(visitor);
+                            printer.endGraph();
+                        }
+                    }
+                    printer.beginGraph("all shapes");
+                    for (ShapeImpl shape : allShapes) {
+                        if (isRootShape(shape)) {
+                            shape.accept(visitor);
+                        }
+                    }
+                    printer.endGraph();
+                    printer.endGroup();
+                    printer.printToNetwork(false);
+                }
+
+                private boolean isRootShape(ShapeImpl shape) {
+                    return shape.getParent() == null;
+                }
+
                 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 19:59:29 2015 +0100
+++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java	Tue Nov 10 19:59:37 2015 +0100
@@ -42,7 +42,8 @@
     public static final boolean TraceReshape = booleanOption(OPTION_PREFIX + "TraceReshape", 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 boolean DumpShapesIGV = booleanOption(OPTION_PREFIX + "DumpShapesIGV", false);
+    public static final boolean DumpShapes = DumpShapesDOT || DumpShapesJSON || DumpShapesIGV;
     public static final String DumpShapesPath = System.getProperty(OPTION_PREFIX + "DumpShapesPath", "");
 
     public static final boolean Profile = booleanOption(OPTION_PREFIX + "Profile", false);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/debug/IGVShapeVisitor.java	Tue Nov 10 19:59:37 2015 +0100
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.object.debug;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import com.oracle.truffle.api.nodes.GraphPrintVisitor;
+import com.oracle.truffle.api.nodes.GraphPrintVisitor.GraphPrintAdapter;
+import com.oracle.truffle.api.nodes.GraphPrintVisitor.GraphPrintHandler;
+import com.oracle.truffle.api.object.Shape;
+import com.oracle.truffle.object.DebugShapeVisitor;
+import com.oracle.truffle.object.ShapeImpl;
+import com.oracle.truffle.object.Transition;
+
+public class IGVShapeVisitor extends DebugShapeVisitor<IGVShapeVisitor> {
+    private final GraphPrintVisitor graphPrinter;
+
+    public IGVShapeVisitor(GraphPrintVisitor printer) {
+        this.graphPrinter = printer;
+    }
+
+    @Override
+    public IGVShapeVisitor visitShape(final Shape shape, final Map<? extends Transition, ? extends Shape> transitions) {
+        graphPrinter.visit(shape, new GraphPrintHandler() {
+            public void visit(Object node, GraphPrintAdapter printer) {
+                if (!printer.visited(node)) {
+                    Shape s = (Shape) node;
+                    printer.createElementForNode(s);
+                    String name = s.getLastProperty() == null ? "ROOT" : s.getLastProperty().toString();
+                    printer.setNodeProperty(s, "name", name);
+                    printer.setNodeProperty(s, "valid", s.isValid());
+                    printer.setNodeProperty(s, "identityHashCode", Integer.toHexString(System.identityHashCode(s)));
+                    printer.setNodeProperty(s, "objectType", s.getObjectType());
+
+                    for (Entry<? extends Transition, ? extends Shape> entry : transitions.entrySet()) {
+                        Shape dst = entry.getValue();
+                        ((ShapeImpl) dst).accept(IGVShapeVisitor.this);
+                        assert printer.visited(dst);
+                        printer.connectNodes(s, dst, entry.getKey().getShortName());
+                    }
+                }
+            }
+        });
+
+        return this;
+    }
+}