Skip to content

Commit

Permalink
8291428: JFR: 'jfr print' displays incorrect timestamps during DST
Browse files Browse the repository at this point in the history
Reviewed-by: mgronlun
  • Loading branch information
egahlin committed Sep 30, 2022
1 parent 3b1bc21 commit 48674d4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public void addArrayAttribute(Element element, String name, Object value) {
static final String ATTRIBUTE_ID = "id";
static final String ATTRIBUTE_SIMPLE_TYPE = "simpleType";
static final String ATTRIBUTE_GMT_OFFSET = "gmtOffset";
static final String ATTRIBUTE_DST = "dst";
static final String ATTRIBUTE_LOCALE = "locale";
static final String ELEMENT_TYPE = "class";
static final String ELEMENT_SETTING = "setting";
Expand All @@ -205,6 +206,7 @@ public void addArrayAttribute(Element element, String name, Object value) {
final List<EventType> eventTypes = new ArrayList<>();
final Collection<Type> types = new ArrayList<>();
long gmtOffset;
long dst;
String locale;
Element root;
public long metadataId;
Expand Down Expand Up @@ -242,6 +244,10 @@ public int getGMTOffset() {
return (int) gmtOffset;
}

public int getDST() {
return (int) dst;
}

public String getLocale() {
return locale;
}
Expand All @@ -254,7 +260,9 @@ public static MetadataDescriptor read(RecordingInput input) throws IOException {
static void write(List<Type> types, DataOutput output) throws IOException {
MetadataDescriptor m = new MetadataDescriptor();
m.locale = Locale.getDefault().toString();
m.gmtOffset = TimeZone.getDefault().getRawOffset();
TimeZone tz = TimeZone.getDefault();
m.gmtOffset = tz.getRawOffset();
m.dst = tz.getDSTSavings();
m.types.addAll(types);
MetadataWriter w = new MetadataWriter(m);
w.writeBinary(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public MetadataReader(RecordingInput input) throws IOException {
buildEvenTypes();
Element time = root.elements("region").get(0);
descriptor.gmtOffset = time.attribute(MetadataDescriptor.ATTRIBUTE_GMT_OFFSET, 1);
descriptor.dst = time.attribute(MetadataDescriptor.ATTRIBUTE_DST, 0L);
descriptor.locale = time.attribute(MetadataDescriptor.ATTRIBUTE_LOCALE, "");
descriptor.root = root;
if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static jdk.jfr.internal.MetadataDescriptor.ATTRIBUTE_DEFAULT_VALUE;
import static jdk.jfr.internal.MetadataDescriptor.ATTRIBUTE_DIMENSION;
import static jdk.jfr.internal.MetadataDescriptor.ATTRIBUTE_GMT_OFFSET;
import static jdk.jfr.internal.MetadataDescriptor.ATTRIBUTE_DST;
import static jdk.jfr.internal.MetadataDescriptor.ATTRIBUTE_ID;
import static jdk.jfr.internal.MetadataDescriptor.ATTRIBUTE_LOCALE;
import static jdk.jfr.internal.MetadataDescriptor.ATTRIBUTE_NAME;
Expand Down Expand Up @@ -72,6 +73,7 @@ public MetadataWriter(MetadataDescriptor descriptor) {
Element region = new Element("region");
region.addAttribute(ATTRIBUTE_LOCALE, descriptor.locale);
region.addAttribute(ATTRIBUTE_GMT_OFFSET, descriptor.gmtOffset);
region.addAttribute(ATTRIBUTE_DST, descriptor.dst);
root.add(region);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private ChunkParser(ChunkHeader header, ChunkParser previous, ParserConfiguratio
this.configuration = previous.configuration;
}
this.metadata = header.readMetadata(previousMetadata);
this.timeConverter = new TimeConverter(chunkHeader, metadata.getGMTOffset());
this.timeConverter = new TimeConverter(chunkHeader, metadata.getGMTOffset() + metadata.getDST());
if (metadata != previousMetadata) {
ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter);
parsers = factory.getParsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ final class TimeConverter {
private final double divisor;
private final ZoneOffset zoneOffset;

TimeConverter(ChunkHeader chunkHeader, int rawOffset) {
TimeConverter(ChunkHeader chunkHeader, int offset) {
this.startTicks = chunkHeader.getStartTicks();
this.startNanos = chunkHeader.getStartNanos();
this.divisor = chunkHeader.getTicksPerSecond() / 1000_000_000L;
this.zoneOffset = zoneOfSet(rawOffset);
this.zoneOffset = zoneOfSet(offset);
}

public long convertTimestamp(long ticks) {
Expand All @@ -60,11 +60,11 @@ public ZoneOffset getZoneOffset() {
return zoneOffset;
}

private ZoneOffset zoneOfSet(int rawOffset) {
private ZoneOffset zoneOfSet(int offset) {
try {
return ZoneOffset.ofTotalSeconds(rawOffset / 1000);
return ZoneOffset.ofTotalSeconds(offset / 1000);
} catch (DateTimeException dte) {
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Could not create ZoneOffset from raw offset " + rawOffset);
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Could not create ZoneOffset from raw offset " + offset);
}
return ZoneOffset.UTC;
}
Expand Down

1 comment on commit 48674d4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.