@@ -658,8 +658,13 @@ private static String sourcePath(Class<?> clazz) {
658
658
659
659
@ Override
660
660
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 ;
663
668
}
664
669
665
670
}
@@ -671,7 +676,7 @@ static String moduleNamePrefix(Module javaModule) {
671
676
if (javaModule .equals (DynamicHub .class .getModule ())) {
672
677
return "VM " ;
673
678
}
674
- return Utils .truncateFQN (javaModule .getName (), 19 ) + "/" ;
679
+ return Utils .truncateFQN (javaModule .getName (), 0.16 ) + "/" ;
675
680
}
676
681
677
682
private void printBreakdowns () {
@@ -701,6 +706,7 @@ private void printBreakdowns() {
701
706
long printedHeapItems = 0 ;
702
707
for (int i = 0 ; i < MAX_NUM_BREAKDOWN ; i ++) {
703
708
String codeSizePart = "" ;
709
+ /* <- 16% for module name -><- 19% or 32% for class FQN -><- 12% for location -> */
704
710
if (packagesBySize .hasNext ()) {
705
711
Entry <BreakDownClassifier , Long > entry = packagesBySize .next ();
706
712
codeSizePart = String .format ("%9s %s" , ByteFormattingUtil .bytesToHuman (entry .getValue ()), entry .getKey ());
@@ -709,15 +715,12 @@ private void printBreakdowns() {
709
715
}
710
716
711
717
String heapSizePart = "" ;
718
+ /* <- 16% for module name -><- 32% for class FQN -> */
712
719
if (typesBySizeInHeap .hasNext ()) {
713
720
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 );
719
722
long byteSize = e .byteSize ;
720
- heapSizePart = String .format ("%9s %s" , ByteFormattingUtil .bytesToHuman (byteSize ), className );
723
+ heapSizePart = String .format ("%9s %s" , ByteFormattingUtil .bytesToHuman (byteSize ), labelString );
721
724
printedHeapBytes += byteSize ;
722
725
printedHeapItems ++;
723
726
}
@@ -983,19 +986,20 @@ private static double toPercentage(long part, long total) {
983
986
return part / (double ) total * 100 ;
984
987
}
985
988
986
- private static String truncateName (String name , int maxLength ) {
989
+ private static String truncateName (String name , double maxLineRatio ) {
987
990
int length = name .length ();
991
+ int maxLength = (int ) (CHARACTERS_PER_LINE * maxLineRatio );
988
992
if (length <= maxLength ) {
989
993
return name ;
990
994
}
991
995
return TRUNCATION_PLACEHOLDER + name .substring (length - maxLength + TRUNCATION_PLACEHOLDER .length (), length );
992
996
}
993
997
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 ) );
996
1000
}
997
1001
998
- static String truncateFQN (String fqn , int maxLength ) {
1002
+ private static String truncateFQN (String fqn , int maxLength ) {
999
1003
int classNameLength = fqn .length ();
1000
1004
if (classNameLength <= maxLength ) {
1001
1005
return fqn ;
0 commit comments