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