提交 ef6664a9 编写于 作者: E egahlin

8212232: Wrong metadata for the configuration of the cutoff for old object sample events

Reviewed-by: mgronlun
上级 b31dfb75
......@@ -65,6 +65,8 @@ import jdk.jfr.internal.settings.ThresholdSetting;
public final class Utils {
private static final String INFINITY = "infinity";
private static Boolean SAVE_GENERATED;
public static final String EVENTS_PACKAGE_NAME = "jdk.jfr.events";
......@@ -117,7 +119,6 @@ public final class Utils {
if (dValue == null) {
return "0";
}
long value = dValue.toNanos();
TimespanUnit result = TimespanUnit.NANOSECONDS;
for (TimespanUnit unit : TimespanUnit.values()) {
......@@ -131,6 +132,13 @@ public final class Utils {
return String.format("%d%s%s", value, separation, result.text);
}
public static long parseTimespanWithInfinity(String s) {
if (INFINITY.equals(s)) {
return Long.MAX_VALUE;
}
return parseTimespan(s);
}
public static long parseTimespan(String s) {
if (s.endsWith("ns")) {
return Long.parseLong(s.substring(0, s.length() - 2).trim());
......
......@@ -28,11 +28,11 @@ package jdk.jfr.internal.settings;
import java.util.Objects;
import java.util.Set;
import jdk.jfr.BooleanFlag;
import jdk.jfr.Description;
import jdk.jfr.Label;
import jdk.jfr.MetadataDefinition;
import jdk.jfr.Name;
import jdk.jfr.Timespan;
import jdk.jfr.internal.Control;
import jdk.jfr.internal.PlatformEventType;
import jdk.jfr.internal.Type;
......@@ -42,7 +42,7 @@ import jdk.jfr.internal.Utils;
@Label("Cutoff")
@Description("Limit running time of event")
@Name(Type.SETTINGS_PREFIX + "Cutoff")
@BooleanFlag
@Timespan
public final class CutoffSetting extends Control {
private final static long typeId = Type.getTypeId(CutoffSetting.class);
......@@ -59,7 +59,7 @@ public final class CutoffSetting extends Control {
long max = 0;
String text = "0 ns";
for (String value : values) {
long l = parseValue(value);
long l = Utils.parseTimespanWithInfinity(value);
if (l > max) {
text = value;
max = l;
......@@ -70,15 +70,11 @@ public final class CutoffSetting extends Control {
@Override
public void setValue(String value) {
long l = parseValue(value);
long l = Utils.parseTimespanWithInfinity(value);
this.value = value;
eventType.setCutoff(l);
}
private long parseValue(String value) {
return isInfinity(value) ? Long.MAX_VALUE : Utils.parseTimespan(value);
}
@Override
public String getValue() {
return value;
......@@ -88,16 +84,12 @@ public final class CutoffSetting extends Control {
return CutoffSetting.typeId == typeId;
}
private static boolean isInfinity(String s) {
return s.equals("infinity");
}
public static long parseValueSafe(String value) {
if (value == null) {
return 0L;
}
try {
return isInfinity(value) ? Long.MAX_VALUE : Utils.parseTimespan(value);
return Utils.parseTimespanWithInfinity(value);
} catch (NumberFormatException nfe) {
return 0L;
}
......
......@@ -58,10 +58,11 @@ public final class PeriodSetting extends Control {
@Override
public String combine(Set<String> values) {
long min = Long.MAX_VALUE;
boolean beginChunk = false;
boolean endChunk = false;
String text = EVERY_CHUNK;
Long min = null;
String text = null;
for (String value : values) {
switch (value) {
case EVERY_CHUNK:
......@@ -75,14 +76,21 @@ public final class PeriodSetting extends Control {
endChunk = true;
break;
default:
long l = Utils.parseTimespan(value);
if (l < min) {
long l = Utils.parseTimespanWithInfinity(value);
// Always accept first specified value
if (min == null) {
text = value;
min = l;
} else {
if (l < min) {
text = value;
min = l;
}
}
}
}
if (min != Long.MAX_VALUE) {
// A specified interval trumps *_CHUNK
if (min != null) {
return text;
}
if (beginChunk && !endChunk) {
......@@ -91,7 +99,7 @@ public final class PeriodSetting extends Control {
if (!beginChunk && endChunk) {
return END_CHUNK;
}
return text;
return EVERY_CHUNK; // also default
}
@Override
......@@ -107,7 +115,12 @@ public final class PeriodSetting extends Control {
eventType.setPeriod(0, false, true);
break;
default:
eventType.setPeriod(Utils.parseTimespan(value) / 1_000_000, false, false);
long nanos = Utils.parseTimespanWithInfinity(value);
if (nanos != Long.MAX_VALUE) {
eventType.setPeriod(nanos / 1_000_000, false, false);
} else {
eventType.setPeriod(Long.MAX_VALUE, false, false);
}
}
this.value = value;
}
......
......@@ -54,21 +54,27 @@ public final class ThresholdSetting extends Control {
@Override
public String combine(Set<String> values) {
long min = Long.MAX_VALUE;
String text = "0 ns";
Long min = null;
String text = null;
for (String value : values) {
long l = Utils.parseTimespan(value);
if (l < min) {
text = value;
long l = Utils.parseTimespanWithInfinity(value);
// always accept first value
if (min == null) {
min = l;
text = value;
} else {
if (l < min) {
text = value;
min = l;
}
}
}
return text;
return text == null ? "0 ns" : text;
}
@Override
public void setValue(String value) {
long l = Utils.parseTimespan(value);
long l = Utils.parseTimespanWithInfinity(value);
this.value = value;
eventType.setThreshold(l);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册