Mercurial > hg > truffle
annotate graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java @ 2648:d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
author | Peter Hofer <peter.hofer@jku.at> |
---|---|
date | Wed, 11 May 2011 14:45:32 +0200 |
parents | |
children | 6ab73784566a |
rev | line source |
---|---|
2648
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
1 /* |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
4 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
8 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
14 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
18 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
21 * questions. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
22 */ |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
23 package com.sun.c1x.debug; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
24 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
25 import java.io.*; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
26 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
27 import com.oracle.graal.graph.*; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
28 import com.oracle.graal.graph.vis.*; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
29 import com.sun.c1x.observer.*; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
30 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
31 /** |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
32 * Observes compilation events and uses {@link GraphvizPrinter} to produce a control flow graph in the DOT language |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
33 * which can be visualized with Graphviz. |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
34 * |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
35 * @author Peter Hofer |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
36 */ |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
37 public class GraphvizPrinterObserver implements CompilationObserver { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
38 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
39 private int n; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
40 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
41 public GraphvizPrinterObserver() { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
42 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
43 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
44 public void compilationStarted(CompilationEvent event) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
45 n = 0; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
46 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
47 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
48 public void compilationFinished(CompilationEvent event) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
49 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
50 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
51 public void compilationEvent(CompilationEvent event) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
52 if (event.getStartBlock() != null && !TTY.isSuppressed()) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
53 Graph graph = event.getStartBlock().graph(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
54 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
55 String name = event.getMethod().holder().name(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
56 name = name.substring(1, name.length() - 1).replace('/', '.'); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
57 name = name + "." + event.getMethod().name(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
58 try { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
59 FileOutputStream stream = new FileOutputStream(name + "_" + n + "_" + event.getLabel() + ".gv"); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
60 n++; |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
61 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
62 GraphvizPrinter printer = new GraphvizPrinter(stream); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
63 printer.begin(name); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
64 printer.print(graph, true); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
65 printer.end(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
66 |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
67 stream.close(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
68 } catch (IOException e) { |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
69 e.printStackTrace(); |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
70 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
71 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
72 } |
d456b679b6de
Add option PrintDOTGraphToFile to produce Graphviz graphs in the DOT language for compiled methods that match PrintFilter
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
73 } |