Skip to content

Commit 3028b13

Browse files
committed
Make truncation-settings based on ProgressReporter#CHARACTERS_PER_LINE
1 parent 782d0f5 commit 3028b13

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HeapBreakdownProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public static class HeapBreakdownEntry {
216216

217217
public HeapBreakdownEntry(HostedClass hostedClass) {
218218
this(ProgressReporter.moduleNamePrefix(hostedClass.getJavaClass().getModule()) +
219-
ProgressReporter.Utils.truncateFQN(hostedClass.toJavaName(true), 40));
219+
ProgressReporter.Utils.truncateFQN(hostedClass.toJavaName(true), 0.32));
220220
}
221221

222222
public HeapBreakdownEntry(String name) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,13 @@ private static String sourcePath(Class<?> clazz) {
658658

659659
@Override
660660
public String toString() {
661-
String locationSuffix = location == null ? "" : " (" + Utils.truncateName(location, 14) + ")";
662-
return moduleNamePrefix(javaModule) + Utils.truncateFQN(javaPackage.getName(), 22) + locationSuffix;
661+
String locationSuffix = location == null ? "" : " (" + Utils.truncateName(location, 0.12) + ")";
662+
double packageNameRatio = 0.19;
663+
if (!javaModule.isNamed()) {
664+
/* Give extra package name space if module not shown */
665+
packageNameRatio += 0.13;
666+
}
667+
return moduleNamePrefix(javaModule) + Utils.truncateFQN(javaPackage.getName(), packageNameRatio) + locationSuffix;
663668
}
664669

665670
}
@@ -671,7 +676,7 @@ static String moduleNamePrefix(Module javaModule) {
671676
if (javaModule.equals(DynamicHub.class.getModule())) {
672677
return "VM ";
673678
}
674-
return Utils.truncateFQN(javaModule.getName(), 19) + "/";
679+
return Utils.truncateFQN(javaModule.getName(), 0.16) + "/";
675680
}
676681

677682
private void printBreakdowns() {
@@ -701,6 +706,7 @@ private void printBreakdowns() {
701706
long printedHeapItems = 0;
702707
for (int i = 0; i < MAX_NUM_BREAKDOWN; i++) {
703708
String codeSizePart = "";
709+
/* <- 16% for module name -><- 19% or 32% for class FQN -><- 12% for location -> */
704710
if (packagesBySize.hasNext()) {
705711
Entry<BreakDownClassifier, Long> entry = packagesBySize.next();
706712
codeSizePart = String.format("%9s %s", ByteFormattingUtil.bytesToHuman(entry.getValue()), entry.getKey());
@@ -709,15 +715,12 @@ private void printBreakdowns() {
709715
}
710716

711717
String heapSizePart = "";
718+
/* <- 16% for module name -><- 32% for class FQN -> */
712719
if (typesBySizeInHeap.hasNext()) {
713720
HeapBreakdownProvider.HeapBreakdownEntry e = typesBySizeInHeap.next();
714-
String className = e.label.renderToString(linkStrategy);
715-
// Do not truncate special breakdown items, they can contain links.
716-
if (e.label instanceof HeapBreakdownProvider.SimpleHeapObjectKindName) {
717-
className = Utils.truncateFQN(className);
718-
}
721+
String labelString = e.label.renderToString(linkStrategy);
719722
long byteSize = e.byteSize;
720-
heapSizePart = String.format("%9s %s", ByteFormattingUtil.bytesToHuman(byteSize), className);
723+
heapSizePart = String.format("%9s %s", ByteFormattingUtil.bytesToHuman(byteSize), labelString);
721724
printedHeapBytes += byteSize;
722725
printedHeapItems++;
723726
}
@@ -983,19 +986,20 @@ private static double toPercentage(long part, long total) {
983986
return part / (double) total * 100;
984987
}
985988

986-
private static String truncateName(String name, int maxLength) {
989+
private static String truncateName(String name, double maxLineRatio) {
987990
int length = name.length();
991+
int maxLength = (int) (CHARACTERS_PER_LINE * maxLineRatio);
988992
if (length <= maxLength) {
989993
return name;
990994
}
991995
return TRUNCATION_PLACEHOLDER + name.substring(length - maxLength + TRUNCATION_PLACEHOLDER.length(), length);
992996
}
993997

994-
private static String truncateFQN(String fqn) {
995-
return truncateFQN(fqn, CHARACTERS_PER_LINE / 2 - 10);
998+
static String truncateFQN(String fqn, double maxLineRatio) {
999+
return truncateFQN(fqn, (int) (CHARACTERS_PER_LINE * maxLineRatio));
9961000
}
9971001

998-
static String truncateFQN(String fqn, int maxLength) {
1002+
private static String truncateFQN(String fqn, int maxLength) {
9991003
int classNameLength = fqn.length();
10001004
if (classNameLength <= maxLength) {
10011005
return fqn;

0 commit comments

Comments
 (0)