Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java @ 2674:6ab73784566a
* BlockBegin.predecessors changed to List<BlockEnd>
* Node: add input/successor with given back edge index, allows for explicit ordering of predecessors/usages
* Graphviz: PDF output, option to omit FrameStates
* runscimark.sh: forward additional options to JVM
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 13 May 2011 15:18:41 +0200 |
parents | d456b679b6de |
children | 4149feada801 |
comparison
equal
deleted
inserted
replaced
2673:98447ab8bd83 | 2674:6ab73784566a |
---|---|
24 | 24 |
25 import java.io.*; | 25 import java.io.*; |
26 | 26 |
27 import com.oracle.graal.graph.*; | 27 import com.oracle.graal.graph.*; |
28 import com.oracle.graal.graph.vis.*; | 28 import com.oracle.graal.graph.vis.*; |
29 import com.sun.c1x.*; | |
29 import com.sun.c1x.observer.*; | 30 import com.sun.c1x.observer.*; |
31 import com.sun.c1x.value.*; | |
30 | 32 |
31 /** | 33 /** |
32 * Observes compilation events and uses {@link GraphvizPrinter} to produce a control flow graph in the DOT language | 34 * Observes compilation events and uses {@link GraphvizPrinter} to produce a control flow graph in the DOT language |
33 * which can be visualized with Graphviz. | 35 * which can be visualized with Graphviz. |
34 * | 36 * |
35 * @author Peter Hofer | 37 * @author Peter Hofer |
36 */ | 38 */ |
37 public class GraphvizPrinterObserver implements CompilationObserver { | 39 public class GraphvizPrinterObserver implements CompilationObserver { |
38 | 40 |
41 private final boolean pdf; | |
39 private int n; | 42 private int n; |
40 | 43 |
41 public GraphvizPrinterObserver() { | 44 public GraphvizPrinterObserver(boolean pdf) { |
45 this.pdf = pdf; | |
42 } | 46 } |
43 | 47 |
44 public void compilationStarted(CompilationEvent event) { | 48 public void compilationStarted(CompilationEvent event) { |
45 n = 0; | 49 n = 0; |
46 } | 50 } |
53 Graph graph = event.getStartBlock().graph(); | 57 Graph graph = event.getStartBlock().graph(); |
54 | 58 |
55 String name = event.getMethod().holder().name(); | 59 String name = event.getMethod().holder().name(); |
56 name = name.substring(1, name.length() - 1).replace('/', '.'); | 60 name = name.substring(1, name.length() - 1).replace('/', '.'); |
57 name = name + "." + event.getMethod().name(); | 61 name = name + "." + event.getMethod().name(); |
62 String filename = name + "_" + (n++) + "_" + event.getLabel(); | |
58 try { | 63 try { |
59 FileOutputStream stream = new FileOutputStream(name + "_" + n + "_" + event.getLabel() + ".gv"); | 64 if (pdf) { |
60 n++; | 65 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
66 GraphvizPrinter printer = new GraphvizPrinter(out); | |
67 if (C1XOptions.OmitDOTFrameStates) { | |
68 printer.addOmittedClass(FrameState.class); | |
69 } | |
70 printer.begin(name); | |
71 printer.print(graph, true); | |
72 printer.end(); | |
61 | 73 |
62 GraphvizPrinter printer = new GraphvizPrinter(stream); | 74 FileOutputStream output = new FileOutputStream(filename + ".pdf"); |
63 printer.begin(name); | 75 GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(out.toByteArray()), output, "pdf"); |
64 printer.print(graph, true); | 76 output.close(); |
65 printer.end(); | 77 } else { |
78 final FileOutputStream stream = new FileOutputStream(filename + ".gv"); | |
66 | 79 |
67 stream.close(); | 80 GraphvizPrinter printer = new GraphvizPrinter(stream); |
81 if (C1XOptions.OmitDOTFrameStates) { | |
82 printer.addOmittedClass(FrameState.class); | |
83 } | |
84 printer.begin(name); | |
85 printer.print(graph, true); | |
86 printer.end(); | |
87 | |
88 stream.close(); | |
89 } | |
68 } catch (IOException e) { | 90 } catch (IOException e) { |
69 e.printStackTrace(); | 91 e.printStackTrace(); |
70 } | 92 } |
71 } | 93 } |
72 } | 94 } |