8309959: JFR: Display N/A for missing data amount

Reviewed-by: mgronlun, stuefe
This commit is contained in:
Erik Gahlin 2023-06-14 12:05:27 +00:00
parent 4c18b9e1fa
commit 9872a14192
2 changed files with 12 additions and 8 deletions

View File

@ -121,11 +121,13 @@ public final class Utils {
}
}
// handle Long.MIN_VALUE as a special case since its absolute value is negative
private static String formatDataAmount(String formatter, long amount) {
int exp = (amount == Long.MIN_VALUE) ? 6 : (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unitPrefix = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unitPrefix);
if (amount == Long.MIN_VALUE) {
return "N/A";
}
int exp = (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unit = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unit);
}
public static String formatBytesCompact(long bytes) {

View File

@ -146,11 +146,13 @@ public final class ValueFormatter {
return name;
}
// handle Long.MIN_VALUE as a special case since its absolute value is negative
private static String formatDataAmount(String formatter, long amount) {
int exp = (amount == Long.MIN_VALUE) ? 6 : (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unitPrefix = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unitPrefix);
if (amount == Long.MIN_VALUE) {
return "N/A";
}
int exp = (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unit = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unit);
}
public static String formatBytesCompact(long bytes) {