Skip to content

Commit 6a69cb4

Browse files
committed
Fixed sorting of JFR | Browser values when using generic loader
1 parent 1c7a3dd commit 6a69cb4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

visualvm/jfr.generic/src/org/graalvm/visualvm/jfr/generic/model/impl/DisplayableSupport.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@
2424
*/
2525
package org.graalvm.visualvm.jfr.generic.model.impl;
2626

27+
import java.text.FieldPosition;
28+
import java.text.Format;
29+
import java.text.ParsePosition;
2730
import java.util.Iterator;
2831
import org.graalvm.visualvm.jfr.model.JFRDataDescriptor;
2932
import org.openjdk.jmc.common.item.IAccessorKey;
3033
import org.openjdk.jmc.common.item.IType;
34+
import org.openjdk.jmc.common.unit.ContentType;
35+
import org.openjdk.jmc.common.unit.IFormatter;
3136
import org.openjdk.jmc.common.unit.LinearKindOfQuantity;
3237
import org.openjdk.jmc.common.util.TypeHandling;
3338
import org.openjdk.jmc.flightrecorder.JfrAttributes;
@@ -82,11 +87,38 @@ private boolean isDisplayable(IAccessorKey key) {
8287
static JFRDataDescriptor getDataDescriptor(IAccessorKey key) {
8388
String dataName = TypeHandling.getValueString(key);
8489
String dataDescription = TypeHandling.getVerboseString(key);
85-
boolean isNumericData = key.getContentType() instanceof LinearKindOfQuantity;
86-
return new JFRDataDescriptor(dataName, dataDescription, null, null, isNumericData);
90+
ContentType contentType = key.getContentType();
91+
Format dataFormat = new DataFormat(contentType.getDefaultFormatter());
92+
boolean isNumericData = contentType instanceof LinearKindOfQuantity;
93+
return new JFRDataDescriptor(dataName, dataDescription, dataFormat, null, isNumericData);
8794
}
8895

8996

9097
private DisplayableSupport() {}
9198

99+
100+
private static class DataFormat extends Format {
101+
102+
private final IFormatter formatter;
103+
104+
105+
DataFormat(IFormatter formatter) {
106+
this.formatter = formatter;
107+
}
108+
109+
110+
@Override
111+
public StringBuffer format(Object o, StringBuffer b, FieldPosition p) {
112+
if (o == null) return b.append(""); // NOI18N
113+
if (o instanceof String) return b.append(o.toString());
114+
return b.append(formatter.format(o));
115+
}
116+
117+
@Override
118+
public Object parseObject(String source, ParsePosition pos) {
119+
throw new UnsupportedOperationException("Not supported."); // NOI18N
120+
}
121+
122+
}
123+
92124
}

visualvm/jfr.generic/src/org/graalvm/visualvm/jfr/generic/model/impl/JFRGenericEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ public List<Comparable> getDisplayableValues(boolean includeExperimental) {
262262
while (keys.hasNext()) {
263263
IAccessorKey key = keys.next();
264264
Object value = type.getAccessor(key).getMember(item);
265-
values.add(value == null ? "" : key.getContentType().getDefaultFormatter().format(value)); // NOI18N
265+
if (value instanceof Comparable) values.add((Comparable)value);
266+
else values.add(key.getContentType().getDefaultFormatter().format(value));
266267
}
267268
return values;
268269
}

0 commit comments

Comments
 (0)