8286688: JFR: Active Setting events should have the same timestamp
Reviewed-by: mgronlun
This commit is contained in:
parent
5bea46110c
commit
a25b9bc89b
@ -37,6 +37,11 @@ import jdk.jfr.internal.Type;
|
|||||||
@StackTrace(false)
|
@StackTrace(false)
|
||||||
public final class ActiveSettingEvent extends AbstractJDKEvent {
|
public final class ActiveSettingEvent extends AbstractJDKEvent {
|
||||||
|
|
||||||
|
public static final ActiveSettingEvent EVENT = new ActiveSettingEvent();
|
||||||
|
|
||||||
|
// The order of these fields must be the same as the parameters in
|
||||||
|
// commit(... , long, String, String)
|
||||||
|
|
||||||
@Label("Event Id")
|
@Label("Event Id")
|
||||||
public long id;
|
public long id;
|
||||||
|
|
||||||
@ -45,4 +50,8 @@ public final class ActiveSettingEvent extends AbstractJDKEvent {
|
|||||||
|
|
||||||
@Label("Setting Value")
|
@Label("Setting Value")
|
||||||
public String value;
|
public String value;
|
||||||
|
|
||||||
|
public static void commit(long startTime, long duration, long id, String name, String value) {
|
||||||
|
// Generated
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ public final class EventControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeActiveSettingEvent() {
|
void writeActiveSettingEvent(long timestamp) {
|
||||||
if (!type.isRegistered()) {
|
if (!type.isRegistered()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -289,11 +289,9 @@ public final class EventControl {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = nc.control.getDefaultValue();
|
value = nc.control.getDefaultValue();
|
||||||
}
|
}
|
||||||
ActiveSettingEvent event = new ActiveSettingEvent();
|
if (ActiveSettingEvent.EVENT.isEnabled()) {
|
||||||
event.id = type.getId();
|
ActiveSettingEvent.commit(timestamp, 0L, type.getId(), nc.name(), value);
|
||||||
event.name = nc.name;
|
}
|
||||||
event.value = value;
|
|
||||||
event.commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ public final class MetadataRepository {
|
|||||||
configuration.getPlatformEventType().setRegistered(true);
|
configuration.getPlatformEventType().setRegistered(true);
|
||||||
typeLibrary.addType(configuration.getPlatformEventType());
|
typeLibrary.addType(configuration.getPlatformEventType());
|
||||||
if (jvm.isRecording()) {
|
if (jvm.isRecording()) {
|
||||||
settingsManager.setEventControl(configuration.getEventControl(), true);
|
settingsManager.setEventControl(configuration.getEventControl(), true, JVM.counterTime());
|
||||||
settingsManager.updateRetransform(Collections.singletonList((eventClass)));
|
settingsManager.updateRetransform(Collections.singletonList((eventClass)));
|
||||||
}
|
}
|
||||||
setStaleMetadata();
|
setStaleMetadata();
|
||||||
|
@ -483,8 +483,9 @@ public final class PlatformRecorder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (activeSettingEvent.isEnabled()) {
|
if (activeSettingEvent.isEnabled()) {
|
||||||
|
long timestamp = JVM.counterTime();
|
||||||
for (EventControl ec : MetadataRepository.getInstance().getEventControls()) {
|
for (EventControl ec : MetadataRepository.getInstance().getEventControls()) {
|
||||||
ec.writeActiveSettingEvent();
|
ec.writeActiveSettingEvent(timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,8 +142,9 @@ final class SettingsManager {
|
|||||||
if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO)) {
|
if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO)) {
|
||||||
eventControls.sort(Comparator.comparing(x -> x.getEventType().getName()));
|
eventControls.sort(Comparator.comparing(x -> x.getEventType().getName()));
|
||||||
}
|
}
|
||||||
|
long timestamp = JVM.counterTime();
|
||||||
for (EventControl ec : eventControls) {
|
for (EventControl ec : eventControls) {
|
||||||
setEventControl(ec, writeSettingEvents);
|
setEventControl(ec, writeSettingEvents, timestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (JVM.getJVM().getAllowedToDoEventRetransforms()) {
|
if (JVM.getJVM().getAllowedToDoEventRetransforms()) {
|
||||||
@ -211,7 +212,7 @@ final class SettingsManager {
|
|||||||
return internals.values();
|
return internals.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEventControl(EventControl ec, boolean writeSettingEvents) {
|
void setEventControl(EventControl ec, boolean writeSettingEvents, long timestamp) {
|
||||||
InternalSetting is = getInternalSetting(ec);
|
InternalSetting is = getInternalSetting(ec);
|
||||||
boolean shouldLog = Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO);
|
boolean shouldLog = Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO);
|
||||||
if (shouldLog) {
|
if (shouldLog) {
|
||||||
@ -251,7 +252,7 @@ final class SettingsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (writeSettingEvents) {
|
if (writeSettingEvents) {
|
||||||
ec.writeActiveSettingEvent();
|
ec.writeActiveSettingEvent(timestamp);
|
||||||
}
|
}
|
||||||
if (shouldLog) {
|
if (shouldLog) {
|
||||||
Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "}");
|
Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "}");
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package jdk.jfr.event.runtime;
|
package jdk.jfr.event.runtime;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -85,8 +87,18 @@ public final class TestActiveSettingEvent {
|
|||||||
r.stop();
|
r.stop();
|
||||||
Map<String, RecordedEvent> settings = new HashMap<>();
|
Map<String, RecordedEvent> settings = new HashMap<>();
|
||||||
List<RecordedEvent> events = Events.fromRecording(r);
|
List<RecordedEvent> events = Events.fromRecording(r);
|
||||||
|
Instant timestamp = null;
|
||||||
for (RecordedEvent e : events) {
|
for (RecordedEvent e : events) {
|
||||||
if (e.getEventType().getName().equals(ACTIVE_SETTING_EVENT_NAME)) {
|
if (e.getEventType().getName().equals(ACTIVE_SETTING_EVENT_NAME)) {
|
||||||
|
if (!e.getDuration().equals(Duration.ZERO)) {
|
||||||
|
throw new Exception("Expected event to have zero duration");
|
||||||
|
}
|
||||||
|
if (timestamp == null) {
|
||||||
|
timestamp = e.getStartTime();
|
||||||
|
}
|
||||||
|
if (!e.getStartTime().equals(timestamp)) {
|
||||||
|
throw new Exception("Expected all events to have the same timestamp");
|
||||||
|
}
|
||||||
long id = e.getLong("id");
|
long id = e.getLong("id");
|
||||||
String name = e.getString("name");
|
String name = e.getString("name");
|
||||||
String value = e.getString("value");
|
String value = e.getString("value");
|
||||||
@ -193,6 +205,13 @@ public final class TestActiveSettingEvent {
|
|||||||
assertSetting(events, type, "threshold", "0 ns"); // initial value
|
assertSetting(events, type, "threshold", "0 ns"); // initial value
|
||||||
assertSetting(events, type, "enabled", "true");
|
assertSetting(events, type, "enabled", "true");
|
||||||
assertSetting(events, type, "threshold", "11 ns"); // changed value
|
assertSetting(events, type, "threshold", "11 ns"); // changed value
|
||||||
|
Set<Instant> timestamps = new HashSet<>();
|
||||||
|
for (RecordedEvent e : events) {
|
||||||
|
timestamps.add(e.getStartTime());
|
||||||
|
}
|
||||||
|
if (timestamps.size() != 2) {
|
||||||
|
throw new Exception("Expected two batches of Active Setting events, at Recording.start() and during Recording.setSetting(...)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user