# HG changeset patch # User Thomas Wuerthinger # Date 1365869264 -7200 # Node ID 3495149b9531d8a1b91b9f9422d30bbf9825a576 # Parent e7541d478e38e98e41cd089771fb297dd020e937 Added support for trimming the name of objects in the histogram and a corresponding test case. diff -r e7541d478e38 -r 3495149b9531 graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java --- a/graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java Sat Apr 13 17:55:43 2013 +0200 +++ b/graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java Sat Apr 13 18:07:44 2013 +0200 @@ -83,4 +83,18 @@ "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------", lines[4]); } + + @Test + public void testTooLongValueString() { + DebugHistogram histogram = Debug.createHistogram("TestHistogram"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + histogram.add("MyCustomValue"); + histogram.print(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10); + String[] lines = outputStream.toString().split("\n"); + Assert.assertEquals(4, lines.length); + Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]); + Assert.assertEquals("----------------------------------------", lines[1]); + Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]); + Assert.assertEquals("----------------------------------------", lines[3]); + } } diff -r e7541d478e38 -r 3495149b9531 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramImpl.java Sat Apr 13 17:55:43 2013 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramImpl.java Sat Apr 13 18:07:44 2013 +0200 @@ -93,7 +93,11 @@ int value = map.get(o); char[] bar = new char[(int) (((double) value / (double) max) * barSize)]; Arrays.fill(bar, '='); - os.printf(formatString, o, value, new String(bar)); + String objectString = o.toString(); + if (objectString.length() > nameSize) { + objectString = objectString.substring(0, nameSize - 3) + "..."; + } + os.printf(formatString, objectString, value, new String(bar)); } printLine(os, '-', lineSize); }