You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/01/18 02:08:24 UTC

[GitHub] [flink] xintongsong commented on a change in pull request #10785: [FLINK-15375][core] Improve MemorySize to print / parse with better readability.

xintongsong 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_r368198923
 
 

 ##########
 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:
   I thought people could easily understand that the value in the parentheses are they exact bytes. But true, it would be better to explicitly add the unit.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services