Skip to content

Commit 0de1622

Browse files
committed
GH-534 LogRecord: read time from 'instant' field
1 parent c96ca72 commit 0de1622

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/details/jdk/TimeDetailsProvider.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,20 @@ public TimeDetailsProvider() {
4646

4747
public String getDetailsString(String className, Instance instance) {
4848
if (INSTANT_MASK.equals(className)) {
49-
long seconds = DetailsUtils.getLongFieldValue(instance, "seconds", -1); // NOI18N
50-
int nanos = DetailsUtils.getIntFieldValue(instance, "nanos", -1); // NOI18N
49+
Instant instant = getInstant(instance);
50+
if (instant != null) return instant.toString();
51+
}
52+
return null;
53+
}
54+
55+
static Instant getInstant(Object instant) {
56+
if (instant instanceof Instance) {
57+
Instance instantObj = (Instance) instant;
58+
long seconds = DetailsUtils.getLongFieldValue(instantObj, "seconds", -1); // NOI18N
59+
int nanos = DetailsUtils.getIntFieldValue(instantObj, "nanos", -1); // NOI18N
5160

5261
if (seconds != -1 && nanos != -1) {
53-
return Instant.ofEpochSecond(seconds, nanos).toString();
62+
return Instant.ofEpochSecond(seconds, nanos);
5463
}
5564
}
5665
return null;

visualvm/libs.profiler/profiler.heapwalker/src/org/graalvm/visualvm/lib/profiler/heapwalk/details/jdk/UtilDetailsProvider.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.graalvm.visualvm.lib.profiler.heapwalk.details.jdk;
2626

27+
import java.time.Instant;
2728
import java.util.ArrayList;
2829
import java.util.Date;
2930
import java.util.List;
@@ -265,11 +266,7 @@ record = rec;
265266

266267
@Override
267268
public long getMillis() {
268-
Object time = record.getValueOfField("millis");
269-
if (time instanceof Number) {
270-
return ((Number)time).longValue();
271-
}
272-
return 0;
269+
return getInstant().toEpochMilli();
273270
}
274271

275272
@Override
@@ -292,6 +289,19 @@ public String getMessage() {
292289
return DetailsUtils.getInstanceFieldString(record, "message"); // NOI18N
293290
}
294291

292+
// @Override since JDK 9
293+
public Instant getInstant() {
294+
Object instant = record.getValueOfField("instant"); // NOI18N
295+
if (instant instanceof Instance) {
296+
return TimeDetailsProvider.getInstant(instant);
297+
}
298+
Object time = record.getValueOfField("millis");
299+
if (time instanceof Number) {
300+
return Instant.ofEpochMilli(((Number)time).longValue());
301+
}
302+
return Instant.EPOCH;
303+
}
304+
295305
@Override
296306
public Object[] getParameters() {
297307
Object pars = record.getValueOfField("parameters");

0 commit comments

Comments
 (0)