RFR: 5721: Reintroduce the Percentage column

Dmitry Popov github.com+7112604+dmnm at openjdk.java.net
Sat Dec 21 17:23:48 UTC 2019


On Sat, 21 Dec 2019 07:50:37 GMT, Dmitry Popov <github.com+7112604+dmnm at openjdk.org> wrote:

>> application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/views/stacktrace/StacktraceView.java line 738:
>> 
>>> 737: 			int totalCount = getRootFork(frame.getBranch().getParentFork()).getItemsInFork();
>>> 738: 			return String.format("%.2f%%", (itemCount / (float) totalCount) * 100F);
>>> 739: 		}
>> 
>> You should use the unit toolkit we have for displaying the percentage, i.e. use UnitLookup.PERCENT_UNITY.quantity to get a value, and then format it as a string using .displayUsing and pass in an appropriate formatting hint. For this I'd say that running 
>> 
>>> UnitLookup.PERCENT_UNITY.quantity(itemCount / (float) totalCount).displayUsing(IDisplayable.AUTO)
>> 
>>  will work fine, but feel free to try some alternatives.
> 
> Hi Henrik,
> 
> Thanks for the comment. Let me explain why I've chosen `String.format()` there. I thought about using unit toolkit but I tried to reintroduce Percentage column the same way as it worked before, i.e. with unit up-to 2 decimal point. UnitLookup.PERCENT_UNITY, which is used in tool tip, displays the percentage in up to 5 decimal points format, like 0.00689 %. I think it's not so useful for the column percentage representation, but it's open for discussion.

How it looks with `String.format()` (always has 2 decimal points):
![Screenshot1](https://user-images.githubusercontent.com/7112604/71311286-3e916400-242f-11ea-8937-9e0b1bef761b.png)

How it looks with `UnitLookup.PERCENT_UNITY.quantity` (from 0 to 5 decimal points and a whitespace before % sign):
![Screenshot2](https://user-images.githubusercontent.com/7112604/71311368-a8117280-242f-11ea-9d71-4fa8a71e22ec.png)

-------------

PR: https://git.openjdk.java.net/jmc/pull/12


More information about the jmc-dev mailing list