@@ -656,17 +656,14 @@ private static String sourcePath(Class<?> clazz) {
656
656
return null ;
657
657
}
658
658
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 ;
668
666
}
669
-
670
667
}
671
668
672
669
static String moduleNamePrefix (Module javaModule ) {
@@ -676,7 +673,7 @@ static String moduleNamePrefix(Module javaModule) {
676
673
if (javaModule .equals (DynamicHub .class .getModule ())) {
677
674
return "VM " ;
678
675
}
679
- return Utils .truncateFQN (javaModule .getName (), 0.16 ) + "/" ;
676
+ return Utils .truncateFQN (javaModule .getName (), 0.10 ) + "/" ;
680
677
}
681
678
682
679
private void printBreakdowns () {
@@ -706,16 +703,18 @@ private void printBreakdowns() {
706
703
long printedHeapItems = 0 ;
707
704
for (int i = 0 ; i < MAX_NUM_BREAKDOWN ; i ++) {
708
705
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 -> */
710
707
if (packagesBySize .hasNext ()) {
711
708
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 ;
713
712
printedCodeBytes += entry .getValue ();
714
713
printedCodeItems ++;
715
714
}
716
715
717
716
String heapSizePart = "" ;
718
- /* <- 16 % for module name -><- 32 % for class FQN -> */
717
+ /* <- 10 % for module name -><- 29 % for class FQN -> */
719
718
if (typesBySizeInHeap .hasNext ()) {
720
719
HeapBreakdownProvider .HeapBreakdownEntry e = typesBySizeInHeap .next ();
721
720
String labelString = e .label .renderToString (linkStrategy );
@@ -988,15 +987,19 @@ private static double toPercentage(long part, long total) {
988
987
989
988
private static String truncateName (String name , double maxLineRatio ) {
990
989
int length = name .length ();
991
- int maxLength = ( int ) ( CHARACTERS_PER_LINE * maxLineRatio );
990
+ int maxLength = maxLength ( maxLineRatio );
992
991
if (length <= maxLength ) {
993
992
return name ;
994
993
}
995
994
return TRUNCATION_PLACEHOLDER + name .substring (length - maxLength + TRUNCATION_PLACEHOLDER .length (), length );
996
995
}
997
996
998
997
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 );
1000
1003
}
1001
1004
1002
1005
private static String truncateFQN (String fqn , int maxLength ) {
@@ -1429,12 +1432,16 @@ public TwoColumnPrinter a(String value) {
1429
1432
}
1430
1433
1431
1434
TwoColumnPrinter jumpToMiddle () {
1432
- int remaining = ( CHARACTERS_PER_LINE / 2 ) - getCurrentTextLength ();
1435
+ int remaining = middle ( ) - getCurrentTextLength ();
1433
1436
assert remaining >= 0 : "Column text too wide" ;
1434
1437
a (Utils .stringFilledWith (remaining , " " ));
1435
- assert getCurrentTextLength () == CHARACTERS_PER_LINE / 2 ;
1438
+ assert getCurrentTextLength () == middle () ;
1436
1439
return this ;
1437
1440
}
1441
+
1442
+ private int middle () {
1443
+ return CHARACTERS_PER_LINE / 2 ;
1444
+ }
1438
1445
}
1439
1446
1440
1447
public final class CenteredTextPrinter extends LinePrinter <CenteredTextPrinter > {
0 commit comments