changeset 9104:3495149b9531

Added support for trimming the name of objects in the histogram and a corresponding test case.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 13 Apr 2013 18:07:44 +0200
parents e7541d478e38
children 368ed6c6a02b
files graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramImpl.java
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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]);
+    }
 }
--- 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);
     }