Mercurial > hg > truffle
comparison 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 |
comparison
equal
deleted
inserted
replaced
22355:ef3c3b62e0fc | 22356:364bab1763c9 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.object; | 23 package com.oracle.truffle.object; |
24 | 24 |
25 import com.oracle.truffle.object.debug.JSONShapeVisitor; | 25 import java.io.File; |
26 import java.io.FileNotFoundException; | 26 import java.io.FileNotFoundException; |
27 import java.io.PrintWriter; | 27 import java.io.PrintWriter; |
28 import java.io.UnsupportedEncodingException; | 28 import java.io.UnsupportedEncodingException; |
29 import java.nio.file.Paths; | |
29 import java.util.Collection; | 30 import java.util.Collection; |
30 import java.util.concurrent.ConcurrentLinkedQueue; | 31 import java.util.concurrent.ConcurrentLinkedQueue; |
32 | |
33 import com.oracle.truffle.object.debug.GraphvizShapeVisitor; | |
34 import com.oracle.truffle.object.debug.JSONShapeVisitor; | |
31 | 35 |
32 class Debug { | 36 class Debug { |
33 private static Collection<ShapeImpl> allShapes; | 37 private static Collection<ShapeImpl> allShapes; |
34 | 38 |
35 static void registerShape(ShapeImpl newShape) { | 39 static void registerShape(ShapeImpl newShape) { |
42 } | 46 } |
43 | 47 |
44 if (ObjectStorageOptions.DumpShapes) { | 48 if (ObjectStorageOptions.DumpShapes) { |
45 Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { | 49 Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { |
46 public void run() { | 50 public void run() { |
47 try (PrintWriter out = new PrintWriter("shapes.json", "UTF-8")) { | 51 try { |
52 if (ObjectStorageOptions.DumpShapesDOT) { | |
53 dumpDOT(); | |
54 } | |
55 if (ObjectStorageOptions.DumpShapesJSON) { | |
56 dumpJSON(); | |
57 } | |
58 } catch (FileNotFoundException | UnsupportedEncodingException e) { | |
59 throw new RuntimeException(e); | |
60 } | |
61 } | |
62 | |
63 private void dumpDOT() throws FileNotFoundException, UnsupportedEncodingException { | |
64 try (PrintWriter out = new PrintWriter(getOutputFile("dot"), "UTF-8")) { | |
65 GraphvizShapeVisitor visitor = new GraphvizShapeVisitor(); | |
66 for (ShapeImpl shape : allShapes) { | |
67 shape.accept(visitor); | |
68 } | |
69 out.println(visitor); | |
70 } | |
71 } | |
72 | |
73 private void dumpJSON() throws FileNotFoundException, UnsupportedEncodingException { | |
74 try (PrintWriter out = new PrintWriter(getOutputFile("json"), "UTF-8")) { | |
48 out.println("{\"shapes\": ["); | 75 out.println("{\"shapes\": ["); |
49 boolean first = true; | 76 boolean first = true; |
50 for (ShapeImpl shape : allShapes) { | 77 for (ShapeImpl shape : allShapes) { |
51 if (!first) { | 78 if (!first) { |
52 out.println(","); | 79 out.println(","); |
56 } | 83 } |
57 if (!first) { | 84 if (!first) { |
58 out.println(); | 85 out.println(); |
59 } | 86 } |
60 out.println("]}"); | 87 out.println("]}"); |
61 } catch (FileNotFoundException | UnsupportedEncodingException e) { | |
62 throw new RuntimeException(e); | |
63 } | 88 } |
89 } | |
90 | |
91 private File getOutputFile(String extension) { | |
92 return Paths.get(ObjectStorageOptions.DumpShapesPath, "shapes." + extension).toFile(); | |
64 } | 93 } |
65 })); | 94 })); |
66 } | 95 } |
67 } | 96 } |
68 } | 97 } |