changeset 1379:d9597f5532cc

7901847: safepoints profiler breaks when system locale has "," as decimal separator
author shade
date Tue, 29 Nov 2016 15:53:41 +0100
parents bb860b8d1eb6
children 33924b860fd0
files jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java jmh-core/src/test/java/org/openjdk/jmh/profile/SafepointsProfilerTest.java
diffstat 2 files changed, 35 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java	Tue Nov 22 21:17:27 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java	Tue Nov 29 15:53:41 2016 +0100
@@ -33,6 +33,7 @@
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
+import java.text.NumberFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
@@ -119,7 +120,7 @@
     }
 
     static long parseNs(String str) {
-        return (long) (Double.parseDouble(str) * TimeUnit.SECONDS.toNanos(1));
+        return (long) (Double.parseDouble(str.replace(',', '.')) * TimeUnit.SECONDS.toNanos(1));
     }
 
     @Override
--- a/jmh-core/src/test/java/org/openjdk/jmh/profile/SafepointsProfilerTest.java	Tue Nov 22 21:17:27 2016 +0100
+++ b/jmh-core/src/test/java/org/openjdk/jmh/profile/SafepointsProfilerTest.java	Tue Nov 29 15:53:41 2016 +0100
@@ -30,7 +30,7 @@
 public class SafepointsProfilerTest {
 
     @Test
-    public void parseJDK7u77() {
+    public void parseJDK7u77_Point() {
         SafepointsProfiler.ParsedData data = SafepointsProfiler.parse(
                 "1.095: Total time for which application threads were stopped: 0.0014010 seconds");
         Assert.assertNotNull(data);
@@ -40,7 +40,17 @@
     }
 
     @Test
-    public void parseJDK8u101() {
+    public void parseJDK7u77_Comma() {
+        SafepointsProfiler.ParsedData data = SafepointsProfiler.parse(
+                "1,095: Total time for which application threads were stopped: 0,0014010 seconds");
+        Assert.assertNotNull(data);
+        Assert.assertEquals(1_095_000_000L, data.timestamp);
+        Assert.assertEquals(    1_401_000L, data.stopTime);
+        Assert.assertEquals(Long.MIN_VALUE, data.ttspTime);
+    }
+
+    @Test
+    public void parseJDK8u101_Dot() {
         SafepointsProfiler.ParsedData data = SafepointsProfiler.parse(
                 "5.042: Total time for which application threads were stopped: 0.0028944 seconds, Stopping threads took: 0.0028351 seconds");
         Assert.assertNotNull(data);
@@ -50,7 +60,17 @@
     }
 
     @Test
-    public void parseJDK9b140() {
+    public void parseJDK8u101_Comma() {
+        SafepointsProfiler.ParsedData data = SafepointsProfiler.parse(
+                "5,042: Total time for which application threads were stopped: 0,0028944 seconds, Stopping threads took: 0,0028351 seconds");
+        Assert.assertNotNull(data);
+        Assert.assertEquals(5_042_000_000L, data.timestamp);
+        Assert.assertEquals(    2_894_400L, data.stopTime);
+        Assert.assertEquals(    2_835_100L, data.ttspTime);
+    }
+
+    @Test
+    public void parseJDK9b140_Dot() {
         SafepointsProfiler.ParsedData data = SafepointsProfiler.parse(
                 "[71.633s][info][safepoint] Total time for which application threads were stopped: 0.0359611 seconds, Stopping threads took: 0.0000516 seconds");
         Assert.assertNotNull(data);
@@ -59,4 +79,14 @@
         Assert.assertEquals(        51_600L, data.ttspTime);
     }
 
+    @Test
+    public void parseJDK9b140_Comma() {
+        SafepointsProfiler.ParsedData data = SafepointsProfiler.parse(
+                "[71,633s][info][safepoint] Total time for which application threads were stopped: 0,0359611 seconds, Stopping threads took: 0,0000516 seconds");
+        Assert.assertNotNull(data);
+        Assert.assertEquals(71_633_000_000L, data.timestamp);
+        Assert.assertEquals(    35_961_100L, data.stopTime);
+        Assert.assertEquals(        51_600L, data.ttspTime);
+    }
+
 }