Mercurial > hg > truffle
annotate graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramAsciiPrinter.java @ 14991:64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 06 Apr 2014 17:46:24 +0200 |
parents | e3888db8b8a1 |
children | cda2a7d1dcff |
rev | line source |
---|---|
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.debug.internal; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import java.util.*; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.debug.*; |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14573
diff
changeset
|
29 import com.oracle.graal.debug.DebugHistogram.CountedValue; |
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14573
diff
changeset
|
30 import com.oracle.graal.debug.DebugHistogram.Printer; |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 * Renders a textual representation of a histogram to a given print stream. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 */ |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 public class DebugHistogramAsciiPrinter implements Printer { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 public static final int NumberSize = 10; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 public static final int DefaultNameSize = 50; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 public static final int DefaultBarSize = 100; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 private PrintStream os; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 private int limit; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 private int nameSize; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 private int barSize; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 public DebugHistogramAsciiPrinter(PrintStream os) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 this(os, Integer.MAX_VALUE, DefaultNameSize, DefaultBarSize); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 * @param os where to print |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 * @param limit limits printing to the {@code limit} most frequent values |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 * @param nameSize the width of the value names column |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 * @param barSize the width of the value frequency column |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 */ |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 public DebugHistogramAsciiPrinter(PrintStream os, int limit, int nameSize, int barSize) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 this.os = os; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 this.limit = limit; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 this.nameSize = nameSize; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 this.barSize = barSize; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 public void print(DebugHistogram histogram) { |
14573
e3888db8b8a1
Backed out changeset: 1d35a2b84553
Doug Simon <doug.simon@oracle.com>
parents:
14572
diff
changeset
|
64 List<CountedValue> list = histogram.getValues(); |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 if (list.isEmpty()) { |
14573
e3888db8b8a1
Backed out changeset: 1d35a2b84553
Doug Simon <doug.simon@oracle.com>
parents:
14572
diff
changeset
|
66 os.printf("%s is empty.%n", histogram.getName()); |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 return; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 // Sum up the total number of elements. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 int total = 0; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 for (CountedValue cv : list) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 total += cv.getCount(); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 // Print header. |
14573
e3888db8b8a1
Backed out changeset: 1d35a2b84553
Doug Simon <doug.simon@oracle.com>
parents:
14572
diff
changeset
|
77 os.printf("%s has %d unique elements and %d total elements:%n", histogram.getName(), list.size(), total); |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 int max = list.get(0).getCount(); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 final int lineSize = nameSize + NumberSize + barSize + 10; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 printLine(os, '-', lineSize); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 String formatString = "| %-" + nameSize + "s | %-" + NumberSize + "d | %-" + barSize + "s |\n"; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 for (int i = 0; i < list.size() && i < limit; ++i) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 CountedValue cv = list.get(i); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 int value = cv.getCount(); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 char[] bar = new char[(int) (((double) value / (double) max) * barSize)]; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 Arrays.fill(bar, '='); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 String objectString = String.valueOf(cv.getValue()); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 if (objectString.length() > nameSize) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 objectString = objectString.substring(0, nameSize - 3) + "..."; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 os.printf(formatString, objectString, value, new String(bar)); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 printLine(os, '-', lineSize); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 private static void printLine(PrintStream printStream, char c, int lineSize) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 char[] charArr = new char[lineSize]; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 Arrays.fill(charArr, c); |
14157 | 100 printStream.printf("%s%n", new String(charArr)); |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 } |