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