annotate graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/internal/DebugHistogramAsciiPrinter.java @ 21794:483b357016a6

Use export target explicitly in mx_graal.py when building JDK (JBS:GRAAL-52)
author Stefan Anzinger <stefan.anzinger@oracle.com>
date Mon, 08 Jun 2015 20:30:39 +0200
parents b1530a6cce8c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 */
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 15954
diff changeset
23 package com.oracle.jvmci.debug.internal;
11551
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
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 15954
diff changeset
28 import com.oracle.jvmci.debug.*;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 15954
diff changeset
29 import com.oracle.jvmci.debug.DebugHistogram.CountedValue;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 15954
diff changeset
30 import com.oracle.jvmci.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;
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
40 public static final int DefaultScale = 1;
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
42 private final PrintStream os;
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
43 private final int limit;
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
44 private final int nameSize;
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
45 private final int barSize;
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
46 private final int scale;
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 public DebugHistogramAsciiPrinter(PrintStream os) {
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
49 this(os, Integer.MAX_VALUE, DefaultNameSize, DefaultBarSize, DefaultScale);
11551
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
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 /**
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 * @param os where to print
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 * @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
55 * @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
56 * @param barSize the width of the value frequency column
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
57 * @param scale a factor by which every result is divided
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 */
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
59 public DebugHistogramAsciiPrinter(PrintStream os, int limit, int nameSize, int barSize, int scale) {
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 this.os = os;
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 this.limit = limit;
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 this.nameSize = nameSize;
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 this.barSize = barSize;
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
64 this.scale = scale;
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 }
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 public void print(DebugHistogram histogram) {
14573
e3888db8b8a1 Backed out changeset: 1d35a2b84553
Doug Simon <doug.simon@oracle.com>
parents: 14572
diff changeset
68 List<CountedValue> list = histogram.getValues();
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 if (list.isEmpty()) {
14573
e3888db8b8a1 Backed out changeset: 1d35a2b84553
Doug Simon <doug.simon@oracle.com>
parents: 14572
diff changeset
70 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
71 return;
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 }
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 // Sum up the total number of elements.
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
75 long total = list.stream().mapToLong(CountedValue::getCount).sum();
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 // Print header.
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
78 os.printf("%s has %d unique elements and %d total elements:%n", histogram.getName(), list.size(), total / scale);
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
80 long max = list.get(0).getCount() / scale;
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 final int lineSize = nameSize + NumberSize + barSize + 10;
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 printLine(os, '-', lineSize);
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 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
84 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
85 CountedValue cv = list.get(i);
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14991
diff changeset
86 long value = cv.getCount() / scale;
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 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
88 Arrays.fill(bar, '=');
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 String objectString = String.valueOf(cv.getValue());
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 if (objectString.length() > nameSize) {
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 objectString = objectString.substring(0, nameSize - 3) + "...";
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92 }
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 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
94 }
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 printLine(os, '-', lineSize);
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
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 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
99 char[] charArr = new char[lineSize];
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 Arrays.fill(charArr, c);
14157
8c4a3d9308a7 fixed FindBugs bugs
twisti
parents: 11551
diff changeset
101 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
102 }
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 }