Skip to content

Commit 25a0779

Browse files
committed
Ensure remainder of size in 1st column goes to package label
1 parent 3028b13 commit 25a0779

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
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), 0.32));
219+
ProgressReporter.Utils.truncateFQN(hostedClass.toJavaName(true), 0.29));
220220
}
221221

222222
public HeapBreakdownEntry(String name) {

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -656,17 +656,14 @@ private static String sourcePath(Class<?> clazz) {
656656
return null;
657657
}
658658

659-
@Override
660-
public String toString() {
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;
659+
public String renderToString(int maxLength) {
660+
String locationSuffix = location == null ? "" : " (" + Utils.truncateName(location, 0.10) + ")";
661+
String packageName = javaPackage == null ? "null" : javaPackage.getName();
662+
String moduleNamePrefix = moduleNamePrefix(javaModule);
663+
// Give remainder of space to package-part
664+
int maxLengthPackage = maxLength - moduleNamePrefix.length() - locationSuffix.length();
665+
return moduleNamePrefix + Utils.truncateFQN(packageName, maxLengthPackage) + locationSuffix;
668666
}
669-
670667
}
671668

672669
static String moduleNamePrefix(Module javaModule) {
@@ -676,7 +673,7 @@ static String moduleNamePrefix(Module javaModule) {
676673
if (javaModule.equals(DynamicHub.class.getModule())) {
677674
return "VM ";
678675
}
679-
return Utils.truncateFQN(javaModule.getName(), 0.16) + "/";
676+
return Utils.truncateFQN(javaModule.getName(), 0.10) + "/";
680677
}
681678

682679
private void printBreakdowns() {
@@ -706,16 +703,18 @@ private void printBreakdowns() {
706703
long printedHeapItems = 0;
707704
for (int i = 0; i < MAX_NUM_BREAKDOWN; i++) {
708705
String codeSizePart = "";
709-
/* <- 16% for module name -><- 19% or 32% for class FQN -><- 12% for location -> */
706+
/* <- 10% for module name -><- remainder for class FQN -><- 10% for location -> */
710707
if (packagesBySize.hasNext()) {
711708
Entry<BreakDownClassifier, Long> entry = packagesBySize.next();
712-
codeSizePart = String.format("%9s %s", ByteFormattingUtil.bytesToHuman(entry.getValue()), entry.getKey());
709+
String sizeStr = String.format("%9s ", ByteFormattingUtil.bytesToHuman(entry.getValue()));
710+
String entryStr = entry.getKey().renderToString(p.middle() - sizeStr.length());
711+
codeSizePart = sizeStr + entryStr;
713712
printedCodeBytes += entry.getValue();
714713
printedCodeItems++;
715714
}
716715

717716
String heapSizePart = "";
718-
/* <- 16% for module name -><- 32% for class FQN -> */
717+
/* <- 10% for module name -><- 29% for class FQN -> */
719718
if (typesBySizeInHeap.hasNext()) {
720719
HeapBreakdownProvider.HeapBreakdownEntry e = typesBySizeInHeap.next();
721720
String labelString = e.label.renderToString(linkStrategy);
@@ -988,15 +987,19 @@ private static double toPercentage(long part, long total) {
988987

989988
private static String truncateName(String name, double maxLineRatio) {
990989
int length = name.length();
991-
int maxLength = (int) (CHARACTERS_PER_LINE * maxLineRatio);
990+
int maxLength = maxLength(maxLineRatio);
992991
if (length <= maxLength) {
993992
return name;
994993
}
995994
return TRUNCATION_PLACEHOLDER + name.substring(length - maxLength + TRUNCATION_PLACEHOLDER.length(), length);
996995
}
997996

998997
static String truncateFQN(String fqn, double maxLineRatio) {
999-
return truncateFQN(fqn, (int) (CHARACTERS_PER_LINE * maxLineRatio));
998+
return truncateFQN(fqn, maxLength(maxLineRatio));
999+
}
1000+
1001+
static int maxLength(double maxLineRatio) {
1002+
return (int) Math.floor(CHARACTERS_PER_LINE * maxLineRatio);
10001003
}
10011004

10021005
private static String truncateFQN(String fqn, int maxLength) {
@@ -1429,12 +1432,16 @@ public TwoColumnPrinter a(String value) {
14291432
}
14301433

14311434
TwoColumnPrinter jumpToMiddle() {
1432-
int remaining = (CHARACTERS_PER_LINE / 2) - getCurrentTextLength();
1435+
int remaining = middle() - getCurrentTextLength();
14331436
assert remaining >= 0 : "Column text too wide";
14341437
a(Utils.stringFilledWith(remaining, " "));
1435-
assert getCurrentTextLength() == CHARACTERS_PER_LINE / 2;
1438+
assert getCurrentTextLength() == middle();
14361439
return this;
14371440
}
1441+
1442+
private int middle() {
1443+
return CHARACTERS_PER_LINE / 2;
1444+
}
14381445
}
14391446

14401447
public final class CenteredTextPrinter extends LinePrinter<CenteredTextPrinter> {

0 commit comments

Comments
 (0)