Skip to content

Commit 2874950

Browse files
committed
GH-351 ItemValueFormatter.DEFAULT_BYTES_PER_SEC added and used instead of javascript implementation
1 parent 4aebef5 commit 2874950

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

plugins/tracer/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ AutoUpdate-Show-In-Client: false
33
OpenIDE-Module: org.graalvm.visualvm.modules.tracer/2
44
OpenIDE-Module-Install: org/graalvm/visualvm/modules/tracer/impl/TracerViewProvider.class
55
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/modules/tracer/impl/Bundle.properties
6-
OpenIDE-Module-Specification-Version: 2.0
6+
OpenIDE-Module-Specification-Version: 2.1

plugins/tracer/src/org/graalvm/visualvm/modules/tracer/ItemValueFormatter.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public String getUnits(int format) {
8282
* Uses Number.getPercentInstance().toString().
8383
*/
8484
public static final ItemValueFormatter DEFAULT_PERCENT = new Percent();
85+
/**
86+
* Predefined formatter for bytes/sec values. Uses B/s (Bytes/sec) for tooltip,
87+
* details table and export, uses kB/s for units (min/max values).
88+
* Uses Number.getInstance().toString().
89+
*/
90+
public static final ItemValueFormatter DEFAULT_BYTES_PER_SEC = new BytesSec();
8591

8692

8793
/**
@@ -184,6 +190,43 @@ public String getUnits(int format) {
184190

185191
}
186192

193+
/**
194+
* Predefined formatter for bytes/sec values. Uses B/s (Bytes/sec) for tooltip,
195+
* details table and export, uses kB/s for units (min/max values).
196+
* Uses Number.getInstance().toString().
197+
*/
198+
private static final class BytesSec extends ItemValueFormatter {
199+
200+
private static final NumberFormat FORMAT = NumberFormat.getInstance();
201+
202+
203+
public String formatValue(long value, int format) {
204+
switch (format) {
205+
case FORMAT_TOOLTIP:
206+
case FORMAT_DETAILS:
207+
case FORMAT_EXPORT:
208+
return FORMAT.format(value);
209+
case FORMAT_UNITS:
210+
String est = value == 0 ? "" : "~";
211+
return est + FORMAT.format(Math.round(value / 1024.0));
212+
default:
213+
return null;
214+
}
215+
}
216+
217+
public String getUnits(int format) {
218+
switch (format) {
219+
case FORMAT_TOOLTIP:
220+
case FORMAT_DETAILS:
221+
case FORMAT_EXPORT:
222+
return "B/s";
223+
case FORMAT_UNITS:
224+
return "kB/s";
225+
default:
226+
return null;
227+
}
228+
}
229+
}
187230

188231
/**
189232
* Predefined formatter for percent values with custom factor.

plugins/tracerjvm/nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<compile-dependency/>
1313
<run-dependency>
1414
<release-version>2</release-version>
15-
<specification-version>2.0</specification-version>
15+
<specification-version>2.1</specification-version>
1616
</run-dependency>
1717
</dependency>
1818
<dependency>

plugins/tracerjvm/src/org/graalvm/visualvm/modules/tracer/jvm/resources/platform_mx.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ try {
3737
var btraceDeployer = btraceDeployerClass ? btraceDeployerClass.instance() : undefined;
3838

3939

40-
var Format_KBPS = {
41-
formatValue: function (value, format) {
42-
return (value / 1024).toFixed(2);
43-
},
44-
getUnits: function (format) {
45-
return "kB/s"
46-
}
47-
}
48-
4940
function getGCRunProvider(on) {
5041
return function(timestamp) {
5142
if (this.delta == undefined) {
@@ -310,15 +301,15 @@ VisualVM.Tracer.addPackages([{
310301
value: mbeanAttribute("btrace:name=JavaIOStats", "fileReadRate"),
311302
presenter: {
312303
lineColor: Color.GREEN,
313-
format: Format_KBPS
304+
format: ItemValueFormatter.DEFAULT_BYTES_PER_SEC
314305
}
315306
},
316307
{
317308
name: "Writing rate",
318309
value: mbeanAttribute("btrace:name=JavaIOStats", "fileWriteRate"),
319310
presenter: {
320311
lineColor: Color.RED,
321-
format: Format_KBPS
312+
format: ItemValueFormatter.DEFAULT_BYTES_PER_SEC
322313
}
323314
}
324315
]
@@ -341,15 +332,15 @@ VisualVM.Tracer.addPackages([{
341332
value: mbeanAttribute("btrace:name=JavaIOStats", "nioReadRate"),
342333
presenter: {
343334
lineColor: Color.GREEN,
344-
format: Format_KBPS
335+
format: ItemValueFormatter.DEFAULT_BYTES_PER_SEC
345336
}
346337
},
347338
{
348339
name: "Writing rate",
349340
value: mbeanAttribute("btrace:name=JavaIOStats", "nioWriteRate"),
350341
presenter: {
351342
lineColor: Color.RED,
352-
format: Format_KBPS
343+
format: ItemValueFormatter.DEFAULT_BYTES_PER_SEC
353344
}
354345
}
355346
]

0 commit comments

Comments
 (0)