Skip to content

Commit f03a696

Browse files
committed
Do not print location info in Top 10 printing
1 parent 354cdcd commit f03a696

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static HeapBreakdownEntry of(String prefix, String name, String htmlAncho
225225
return new HeapBreakdownEntryFixed(new LinkyHeapObjectKindName(prefix, name, htmlAnchor));
226226
}
227227

228-
public abstract HeapBreakdownLabel getLabel(boolean truncate);
228+
public abstract HeapBreakdownLabel getLabel(int maxLength);
229229

230230
public long getByteSize() {
231231
return byteSize;
@@ -259,7 +259,7 @@ static class HeapBreakdownEntryFixed extends HeapBreakdownEntry {
259259
}
260260

261261
@Override
262-
public HeapBreakdownLabel getLabel(boolean unused) {
262+
public HeapBreakdownLabel getLabel(int unused) {
263263
return label;
264264
}
265265
}
@@ -273,10 +273,12 @@ static class HeapBreakdownEntryForClass extends HeapBreakdownEntry {
273273
}
274274

275275
@Override
276-
public HeapBreakdownLabel getLabel(boolean truncate) {
277-
if (truncate) {
278-
return new SimpleHeapObjectKindName(ProgressReporterUtils.moduleNamePrefix(clazz.getModule()) +
279-
ProgressReporterUtils.truncateFQN(clazz.getTypeName(), 0.29));
276+
public HeapBreakdownLabel getLabel(int maxLength) {
277+
if (maxLength >= 0) {
278+
String moduleNamePrefix = ProgressReporterUtils.moduleNamePrefix(clazz.getModule());
279+
int maxLengthClassName = maxLength - moduleNamePrefix.length();
280+
String truncatedClassName = ProgressReporterUtils.truncateFQN(clazz.getTypeName(), maxLengthClassName);
281+
return new SimpleHeapObjectKindName(moduleNamePrefix + truncatedClassName);
280282
} else {
281283
return new SimpleHeapObjectKindName(clazz.getTypeName());
282284
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,23 +684,24 @@ private void printBreakdowns() {
684684
Iterator<HeapBreakdownProvider.HeapBreakdownEntry> typesBySizeInHeap = heapBreakdown.getSortedBreakdownEntries().iterator();
685685
for (int i = 0; i < MAX_NUM_BREAKDOWN; i++) {
686686
String codeSizePart = "";
687-
/* <- 10% for module name -><- remainder for class FQN -><- 10% for location -> */
687+
/* <- 12% for module name -><- remainder for package FQN -> */
688688
if (packagesBySize.hasNext()) {
689689
Entry<ProgressReporterUtils.BreakDownClassifier, Long> entry = packagesBySize.next();
690-
String sizeStr = String.format("%9s ", ByteFormattingUtil.bytesToHuman(entry.getValue()));
690+
String sizeStr = getBreakdownSizeString(entry.getValue());
691691
String entryStr = entry.getKey().renderToString(p.middle() - sizeStr.length());
692692
codeSizePart = sizeStr + entryStr;
693693
printedCodeBytes += entry.getValue();
694694
printedCodeItems++;
695695
}
696696

697697
String heapSizePart = "";
698-
/* <- 10% for module name -><- 29% for class FQN -> */
698+
/* <- 12% for module name -><- remainder for class FQN -> */
699699
if (typesBySizeInHeap.hasNext()) {
700700
HeapBreakdownProvider.HeapBreakdownEntry e = typesBySizeInHeap.next();
701-
String labelString = e.getLabel(true).renderToString(linkStrategy);
702701
long byteSize = e.byteSize;
703-
heapSizePart = String.format("%9s %s", ByteFormattingUtil.bytesToHuman(byteSize), labelString);
702+
String sizeStr = getBreakdownSizeString(byteSize);
703+
String labelStr = e.getLabel(CHARACTERS_PER_LINE - p.middle() - sizeStr.length()).renderToString(linkStrategy);
704+
heapSizePart = sizeStr + labelStr;
704705
printedHeapBytes += byteSize;
705706
printedHeapItems++;
706707
}
@@ -720,6 +721,10 @@ private void printBreakdowns() {
720721
.flushln();
721722
}
722723

724+
private static String getBreakdownSizeString(long sizeInBytes) {
725+
return String.format("%9s ", ByteFormattingUtil.bytesToHuman(sizeInBytes));
726+
}
727+
723728
private void printRecommendations() {
724729
if (!SubstrateOptions.BuildOutputRecommendations.getValue()) {
725730
return;

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package com.oracle.svm.hosted;
2727

28+
import java.net.URL;
2829
import java.security.CodeSource;
2930

3031
final class ProgressReporterUtils {
@@ -53,15 +54,6 @@ static double toPercentage(long part, long total) {
5354
return part / (double) total * 100;
5455
}
5556

56-
private static String truncateName(String name, double maxLineRatio) {
57-
int length = name.length();
58-
int maxLength = maxLength(maxLineRatio);
59-
if (length <= maxLength) {
60-
return name;
61-
}
62-
return TRUNCATION_PLACEHOLDER + name.substring(length - maxLength + TRUNCATION_PLACEHOLDER.length(), length);
63-
}
64-
6557
static String truncateFQN(String fqn, double maxLineRatio) {
6658
return truncateFQN(fqn, maxLength(maxLineRatio));
6759
}
@@ -70,7 +62,7 @@ static int maxLength(double maxLineRatio) {
7062
return (int) Math.floor(ProgressReporter.CHARACTERS_PER_LINE * maxLineRatio);
7163
}
7264

73-
private static String truncateFQN(String fqn, int maxLength) {
65+
static String truncateFQN(String fqn, int maxLength) {
7466
int classNameLength = fqn.length();
7567
if (classNameLength <= maxLength) {
7668
return fqn;
@@ -103,8 +95,11 @@ private static String truncateFQN(String fqn, int maxLength) {
10395
}
10496

10597
static String moduleNamePrefix(Module javaModule) {
106-
String moduleName = javaModule.isNamed() ? javaModule.getName() : "";
107-
return truncateFQN(mapToNativeImageRuntime(moduleName), 0.10) + "/";
98+
if (!javaModule.isNamed()) {
99+
return "";
100+
}
101+
String moduleName = javaModule.getName();
102+
return truncateFQN(mapToNativeImageRuntime(moduleName), 0.12) + "/";
108103
}
109104

110105
private static String mapToNativeImageRuntime(String moduleName) {
@@ -122,21 +117,21 @@ static BreakDownClassifier of(Class<?> clazz) {
122117

123118
private static String sourcePath(Class<?> clazz) {
124119
CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
125-
if (codeSource != null && codeSource.getLocation() != null) {
126-
String path = codeSource.getLocation().getPath();
127-
// Use String API to determine basename of path to handle both / and \.
128-
return path.substring(Math.max(path.lastIndexOf('/') + 1, path.lastIndexOf('\\') + 1));
120+
if (codeSource != null) {
121+
URL sourceLocation = codeSource.getLocation();
122+
if (sourceLocation != null && !"jrt".equals(sourceLocation.getProtocol())) {
123+
return sourceLocation.getPath();
124+
}
129125
}
130126
return null;
131127
}
132128

133129
public String renderToString(int maxLength) {
134-
String locationSuffix = location == null ? "" : " (" + truncateName(location, 0.10) + ")";
135130
String packageName = javaPackage == null ? "null" : javaPackage.getName();
136131
String moduleNamePrefix = moduleNamePrefix(javaModule);
137132
// Give remainder of space to package-part
138-
int maxLengthPackage = maxLength - moduleNamePrefix.length() - locationSuffix.length();
139-
return moduleNamePrefix + truncateFQN(packageName, maxLengthPackage) + locationSuffix;
133+
int maxLengthPackage = maxLength - moduleNamePrefix.length();
134+
return moduleNamePrefix + truncateFQN(packageName, maxLengthPackage);
140135
}
141136

142137
public String[] elements() {

0 commit comments

Comments
 (0)