@@ -267,7 +267,7 @@ public void printInitializeEnd() {
267267 String gcName = Heap .getHeap ().getGC ().getName ();
268268 recordJsonMetric (GeneralInfo .GC , gcName );
269269 long maxHeapSize = SubstrateGCOptions .MaxHeapSize .getValue ();
270- String maxHeapValue = maxHeapSize == 0 ? "unlimited" : Utils .bytesToHuman (maxHeapSize );
270+ String maxHeapValue = maxHeapSize == 0 ? "unlimited" : ByteFormattingUtil .bytesToHuman (maxHeapSize );
271271 l ().a (" " ).doclink ("Garbage collector" , "#glossary-gc" ).a (": " ).a (gcName ).a (" (" ).doclink ("max heap size" , "#glossary-gc-max-heap-size" ).a (": " ).a (maxHeapValue ).a (")" ).println ();
272272 }
273273
@@ -414,16 +414,17 @@ public void printCreationEnd(int imageFileSize, int numHeapObjects, long imageHe
414414 stagePrinter .end (imageTimer .getTotalTime () + writeTimer .getTotalTime ());
415415 creationStageEndCompleted = true ;
416416 String format = "%9s (%5.2f%%) for " ;
417- l ().a (format , Utils .bytesToHuman (codeAreaSize ), codeAreaSize / (double ) imageFileSize * 100 )
417+ l ().a (format , ByteFormattingUtil .bytesToHuman (codeAreaSize ), codeAreaSize / (double ) imageFileSize * 100 )
418418 .doclink ("code area" , "#glossary-code-area" ).a (":%,10d compilation units" , numCompilations ).println ();
419419 EconomicMap <Pair <String , String >, ResourceStorageEntry > resources = Resources .singleton ().resources ();
420420 int numResources = resources .size ();
421421 recordJsonMetric (ImageDetailKey .IMAGE_HEAP_RESOURCE_COUNT , numResources );
422- l ().a (format , Utils .bytesToHuman (imageHeapSize ), imageHeapSize / (double ) imageFileSize * 100 )
422+ l ().a (format , ByteFormattingUtil .bytesToHuman (imageHeapSize ), imageHeapSize / (double ) imageFileSize * 100 )
423423 .doclink ("image heap" , "#glossary-image-heap" ).a (":%,9d objects and %,d resources" , numHeapObjects , numResources ).println ();
424424 if (debugInfoSize > 0 ) {
425425 recordJsonMetric (ImageDetailKey .DEBUG_INFO_SIZE , debugInfoSize ); // Optional metric
426- DirectPrinter l = l ().a (format , Utils .bytesToHuman (debugInfoSize ), debugInfoSize / (double ) imageFileSize * 100 )
426+ DirectPrinter l = l ().a (format , ByteFormattingUtil .bytesToHuman (debugInfoSize ), debugInfoSize / (double ) imageFileSize * 100 )
427+
427428 .doclink ("debug info" , "#glossary-debug-info" );
428429 if (debugInfoTimer != null ) {
429430 l .a (" generated in %.1fs" , Utils .millisToSeconds (debugInfoTimer .getTotalTime ()));
@@ -435,9 +436,9 @@ public void printCreationEnd(int imageFileSize, int numHeapObjects, long imageHe
435436 recordJsonMetric (ImageDetailKey .TOTAL_SIZE , imageFileSize );
436437 recordJsonMetric (ImageDetailKey .CODE_AREA_SIZE , codeAreaSize );
437438 recordJsonMetric (ImageDetailKey .NUM_COMP_UNITS , numCompilations );
438- l ().a (format , Utils .bytesToHuman (otherBytes ), otherBytes / (double ) imageFileSize * 100 )
439+ l ().a (format , ByteFormattingUtil .bytesToHuman (otherBytes ), otherBytes / (double ) imageFileSize * 100 )
439440 .doclink ("other data" , "#glossary-other-data" ).println ();
440- l ().a ("%9s in total" , Utils .bytesToHuman (imageFileSize )).println ();
441+ l ().a ("%9s in total" , ByteFormattingUtil .bytesToHuman (imageFileSize )).println ();
441442 printBreakdowns ();
442443 }
443444
@@ -568,7 +569,7 @@ private void printBreakdowns() {
568569 if (packagesBySize .hasNext ()) {
569570 Entry <String , Long > e = packagesBySize .next ();
570571 String className = Utils .truncateClassOrPackageName (e .getKey ());
571- codeSizePart = String .format ("%9s %s" , Utils .bytesToHuman (e .getValue ()), className );
572+ codeSizePart = String .format ("%9s %s" , ByteFormattingUtil .bytesToHuman (e .getValue ()), className );
572573 printedCodeBytes += e .getValue ();
573574 printedCodeItems ++;
574575 }
@@ -581,7 +582,7 @@ private void printBreakdowns() {
581582 if (!className .startsWith (BREAKDOWN_BYTE_ARRAY_PREFIX )) {
582583 className = Utils .truncateClassOrPackageName (className );
583584 }
584- heapSizePart = String .format ("%9s %s" , Utils .bytesToHuman (e .getValue ()), className );
585+ heapSizePart = String .format ("%9s %s" , ByteFormattingUtil .bytesToHuman (e .getValue ()), className );
585586 printedHeapBytes += e .getValue ();
586587 printedHeapItems ++;
587588 }
@@ -595,9 +596,10 @@ private void printBreakdowns() {
595596 int numHeapItems = heapBreakdown .size ();
596597 long totalCodeBytes = codeBreakdown .values ().stream ().collect (Collectors .summingLong (Long ::longValue ));
597598 long totalHeapBytes = heapBreakdown .values ().stream ().collect (Collectors .summingLong (Long ::longValue ));
598- p .l ().a (String .format ("%9s for %s more " , Utils .bytesToHuman (totalCodeBytes - printedCodeBytes ), numCodeItems - printedCodeItems )).doclink ("origins" , "#glossary-code-area-origins" )
599+
600+ p .l ().a (String .format ("%9s for %s more packages" , ByteFormattingUtil .bytesToHuman (totalCodeBytes - printedCodeBytes ), numCodeItems - printedCodeItems ))
599601 .jumpToMiddle ()
600- .a (String .format ("%9s for %s more object types" , Utils .bytesToHuman (totalHeapBytes - printedHeapBytes ), numHeapItems - printedHeapItems )).flushln ();
602+ .a (String .format ("%9s for %s more object types" , ByteFormattingUtil .bytesToHuman (totalHeapBytes - printedHeapBytes ), numHeapItems - printedHeapItems )).flushln ();
601603 }
602604
603605 public void printEpilog (Optional <String > optionalImageName , Optional <NativeImageGenerator > optionalGenerator , ImageClassLoader classLoader , Optional <Throwable > optionalError ,
@@ -702,11 +704,11 @@ private static Path reportImageBuildStatistics(String imageName, BigBang bb) {
702704 String description = "image build statistics" ;
703705 if (ImageBuildStatistics .Options .ImageBuildStatisticsFile .hasBeenSet (bb .getOptions ())) {
704706 final File file = new File (ImageBuildStatistics .Options .ImageBuildStatisticsFile .getValue (bb .getOptions ()));
705- return ReportUtils .report (description , file .getAbsoluteFile ().toPath (), statsReporter , false );
707+ return com . oracle . graal . pointsto . reports . ReportUtils .report (description , file .getAbsoluteFile ().toPath (), statsReporter , false );
706708 } else {
707- String name = "image_build_statistics_" + ReportUtils .extractImageName (imageName );
709+ String name = "image_build_statistics_" + com . oracle . graal . pointsto . reports . ReportUtils .extractImageName (imageName );
708710 String path = SubstrateOptions .Path .getValue () + File .separatorChar + "reports" ;
709- return ReportUtils .report (description , path , name , "json" , statsReporter , false );
711+ return com . oracle . graal . pointsto . reports . ReportUtils .report (description , path , name , "json" , statsReporter , false );
710712 }
711713 }
712714
@@ -721,7 +723,7 @@ private void printResourceStatistics() {
721723 .doclink ("GCs" , "#glossary-garbage-collections" );
722724 long peakRSS = ProgressReporterCHelper .getPeakRSS ();
723725 if (peakRSS >= 0 ) {
724- p .a (" | " ).doclink ("Peak RSS" , "#glossary-peak-rss" ).a (": " ).a ("%.2fGB" , Utils .bytesToGiB (peakRSS ));
726+ p .a (" | " ).doclink ("Peak RSS" , "#glossary-peak-rss" ).a (": " ).a ("%.2fGB" , ByteFormattingUtil .bytesToGiB (peakRSS ));
725727 }
726728 recordJsonMetric (ResourceUsageKey .PEAK_RSS , (peakRSS >= 0 ? peakRSS : UNAVAILABLE_METRIC ));
727729 OperatingSystemMXBean osMXBean = ManagementFactory .getOperatingSystemMXBean ();
@@ -747,7 +749,7 @@ private void checkForExcessiveGarbageCollection() {
747749 .a (": %.1fs spent in %d GCs during the last stage, taking up %.2f%% of the time." ,
748750 Utils .millisToSeconds (gcTimeDeltaMillis ), currentGCStats .totalCount - lastGCStats .totalCount , ratio * 100 )
749751 .println ();
750- l ().a (" Please ensure more than %.2fGB of memory is available for Native Image" , Utils .bytesToGiB (ProgressReporterCHelper .getPeakRSS ())).println ();
752+ l ().a (" Please ensure more than %.2fGB of memory is available for Native Image" , ByteFormattingUtil .bytesToGiB (ProgressReporterCHelper .getPeakRSS ())).println ();
751753 l ().a (" to reduce GC overhead and improve image build time." ).println ();
752754 }
753755 lastGCStats = currentGCStats ;
@@ -770,40 +772,8 @@ private static Timer getTimer(TimerCollection.Registry type) {
770772 private static class Utils {
771773 private static final double MILLIS_TO_SECONDS = 1000d ;
772774 private static final double NANOS_TO_SECONDS = 1000d * 1000d * 1000d ;
773- private static final double BYTES_TO_KiB = 1024d ;
774- private static final double BYTES_TO_MiB = 1024d * 1024d ;
775- private static final double BYTES_TO_GiB = 1024d * 1024d * 1024d ;
776-
777775 private static final Field STRING_VALUE = ReflectionUtil .lookupField (String .class , "value" );
778776
779- private static String bytesToHuman (long bytes ) {
780- return bytesToHuman ("%4.2f" , bytes );
781- }
782-
783- private static String bytesToHuman (String format , long bytes ) {
784- if (bytes < BYTES_TO_KiB ) {
785- return String .format (format , (double ) bytes ) + "B" ;
786- } else if (bytes < BYTES_TO_MiB ) {
787- return String .format (format , bytesToKiB (bytes )) + "KB" ;
788- } else if (bytes < BYTES_TO_GiB ) {
789- return String .format (format , bytesToMiB (bytes )) + "MB" ;
790- } else {
791- return String .format (format , bytesToGiB (bytes )) + "GB" ;
792- }
793- }
794-
795- private static double bytesToKiB (long bytes ) {
796- return bytes / BYTES_TO_KiB ;
797- }
798-
799- private static double bytesToGiB (long bytes ) {
800- return bytes / BYTES_TO_GiB ;
801- }
802-
803- private static double bytesToMiB (long bytes ) {
804- return bytes / BYTES_TO_MiB ;
805- }
806-
807777 private static double millisToSeconds (double millis ) {
808778 return millis / MILLIS_TO_SECONDS ;
809779 }
@@ -821,7 +791,7 @@ private static int getInternalByteArrayLength(String string) {
821791 }
822792
823793 private static double getUsedMemory () {
824- return bytesToGiB (Runtime .getRuntime ().totalMemory () - Runtime .getRuntime ().freeMemory ());
794+ return ByteFormattingUtil . bytesToGiB (Runtime .getRuntime ().totalMemory () - Runtime .getRuntime ().freeMemory ());
825795 }
826796
827797 private static String stringFilledWith (int size , String fill ) {
@@ -862,6 +832,10 @@ private static String truncateClassOrPackageName(String classOrPackageName) {
862832 }
863833 }
864834
835+ private static void resetANSIMode () {
836+ NativeImageSystemIOWrappers .singleton ().getOut ().print (ANSI .RESET );
837+ }
838+
865839 private static class GCStats {
866840 private final long totalCount ;
867841 private final long totalTimeMillis ;
0 commit comments