tillrohrmann commented on a change in pull request #10785: [FLINK-15375][core] 
Improve MemorySize to print / parse with better readability.
URL: https://github.com/apache/flink/pull/10785#discussion_r367995904
 
 

 ##########
 File path: 
flink-core/src/main/java/org/apache/flink/configuration/MemorySize.java
 ##########
 @@ -158,6 +162,38 @@ private String formatToString() {
                        highestIntegerUnit.getUnits()[1]);
        }
 
+       public String toHumanReadableString() {
+               if (humanReadableStr == null) {
+                       humanReadableStr = formatToHumanReadableString();
+               }
+
+               return humanReadableStr;
+       }
+
+       private String formatToHumanReadableString() {
+               MemoryUnit highestUnit = IntStream.range(0, 
ORDERED_UNITS.size())
+                       .sequential()
+                       .filter(idx -> bytes > 
ORDERED_UNITS.get(idx).getMultiplier())
+                       .boxed()
+                       .max(Comparator.naturalOrder())
+                       .map(idx -> ORDERED_UNITS.get(idx))
+                       .orElse(BYTES);
+
+               if (highestUnit == BYTES) {
+                       return String.format(
+                               "%d %s",
+                               bytes,
+                               BYTES.getUnits()[1]);
+               } else {
+                       double approximate = 1.0 * bytes / 
highestUnit.getMultiplier();
+                       return String.format(
+                               "%.3f%s (%d)",
 
 Review comment:
   Should we add `%.3f%s (%d bytes)`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to