Skip to content

Commit

Permalink
7039: Timestamp granularity too coarse
Browse files Browse the repository at this point in the history
Reviewed-by: hirt
  • Loading branch information
Suchita Chaturvedi committed Feb 3, 2021
1 parent 2bcb03e commit 7b1ae3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -47,6 +47,7 @@
import static org.openjdk.jmc.common.unit.DecimalPrefix.YOTTA;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -512,6 +513,16 @@ private static LinearKindOfQuantity createTimespan() {
return timeSpan;
}

private static DateFormat patchTimestamp(DateFormat df) {
if (df instanceof SimpleDateFormat) {
SimpleDateFormat sdf = (SimpleDateFormat) df;
String pattern = sdf.toPattern();
String newPattern = pattern.replaceFirst("s{2,4}", "ss.SSS"); //$NON-NLS-1$ //$NON-NLS-2$
sdf.applyPattern(newPattern);
}
return df;
}

private static TimestampKind createTimestamp(LinearKindOfQuantity timespan) {
TimestampKind timestampContentType = TimestampKind.buildContentType(timespan);
timestampContentType
Expand All @@ -521,7 +532,9 @@ public String format(IQuantity quantity) {
try {
// NOTE: This used to return the floor value.
Date date = new Date(quantity.longValueIn(TimestampKind.MILLIS_UNIT));
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(date);
DateFormat df = patchTimestamp(
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM));
return df.format(date);
} catch (QuantityConversionException e) {
return Messages.getString(Messages.UnitLookup_TIMESTAMP_OUT_OF_RANGE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ Enabling the following event types would improve the accuracy of this rule: jdk.
<id>ManyRunningProcesses</id>
<severity>OK</severity>
<summary>137 processes were running while this Flight Recording was made.</summary>
<explanation>At 4/4/14 11:17:10 AM, a total of 137 other processes were running on the host machine that this Flight Recording was made on.</explanation>
<explanation>At 4/4/14 11:17:10.326 AM, a total of 137 other processes were running on the host machine that this Flight Recording was made on.</explanation>
<solution>If this is a server environment, it may be good to only run other critical processes on that machine.</solution>
</rule>
<rule>
Expand Down Expand Up @@ -2322,7 +2322,7 @@ Enabling the following event types would improve the accuracy of this rule: jdk.
<id>ManyRunningProcesses</id>
<severity>OK</severity>
<summary>137 processes were running while this Flight Recording was made.</summary>
<explanation>At 4/4/14 8:54:38 AM, a total of 137 other processes were running on the host machine that this Flight Recording was made on.</explanation>
<explanation>At 4/4/14 8:54:38.623 AM, a total of 137 other processes were running on the host machine that this Flight Recording was made on.</explanation>
<solution>If this is a server environment, it may be good to only run other critical processes on that machine.</solution>
</rule>
<rule>
Expand Down

0 comments on commit 7b1ae3e

Please sign in to comment.