Mercurial > hg > truffle
diff truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/Debug.java @ 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 | dc83cc1f94f2 |
children | 9c1d40221bf9 |
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(); + } })); } }