zaaath commented on code in PR #2919:
URL: https://github.com/apache/cassandra/pull/2919#discussion_r1398486621
##########
src/java/org/apache/cassandra/utils/FBUtilities.java:
##########
@@ -865,6 +865,49 @@ public static String prettyPrintMemory(long size)
return prettyPrintMemory(size, "");
}
+ /**
+ * Formats a latency value in milliseconds for display, appending an "ms"
suffix.
+ * The formatted output is rounded to three decimal places.
+ * For example, "5000.000 ms", "100.000 ms", "0.050 ms", "0.000 ms", "NaN
ms".
+ * @param latency Latency in milliseconds to print.
+ */
+ public static String prettyPrintLatency(double latency)
+ {
+ return String.format("%.3f ms", latency);
+ }
+
+ /**
+ * Formats a ratio value for display, rounds it to three decimal places.
+ * For example, "10.000", "1.000", "0.050", "0.001", "0.000", "NaN".
+ * @param ratioObj Ratio to print.
+ */
+ public static String prettyPrintRatio(Object ratioObj)
Review Comment:
prettyPrintRatio(Object ratioObj) signature could be changed to
prettyPrintRatio(Number ratio), but I can't completely eliminate the ifs. And
actually, I'd rather stick with prettyPrintRatio(Object ratioObj).
Here's why: String.format raises an exception when format specifiers don't
match the format arguments like in:
```
jshell> String.format("%.3f ms", (Number)123)
| Exception java.util.IllegalFormatConversionException: f !=
java.lang.Integer
```
And then there is also the "null" case.
So because sstableCompressionRatio and bloomFilterFalseRatio are untyped, we
have two options:
1. Branch type casting
2. Handle IllegalFormatConversionException
And the third option is to refactor StatsTable.sstableCompressionRatio and
StatsTable.bloomFilterFalseRatio to be typed as "double". I assume that the
third option is off-the-table since it might result in too many changes.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]