Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,52 +66,51 @@ public class Decorators {

int numberOfDecorators;

private Matcher decoratorMatcher = null;
private String[] decoratorGroups;
private String tags;

public Decorators(String line) {
extractValues(line);
}

private void extractValues(String line) {

if (!line.startsWith("["))
return;

decoratorMatcher = UnifiedLoggingTokens.DECORATORS.matcher(line);
Matcher decoratorMatcher = UnifiedLoggingTokens.DECORATORS.matcher(line);
if (!decoratorMatcher.find()) {
return;
}

for ( int i = 1; i <= decoratorMatcher.groupCount(); i++) {
if ( decoratorMatcher.group(i) != null)
// Retrieving a group from a matcher calls substring each time
// Store all the groups in an array ahead of time to avoid paying this cost unnecessarily
decoratorGroups = new String[11];
Copy link
Member

Choose a reason for hiding this comment

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

new String[decoratorMatcher.groupCount()] might be a bit more robust here

for (int i = 1; i <= decoratorMatcher.groupCount(); i++) {
String group = decoratorMatcher.group(i);
decoratorGroups[i] = group;
if (group != null)
numberOfDecorators++;
}

Matcher tagMatcher = UnifiedLoggingTokens.TAGS.matcher(line);
if (tagMatcher.find()) {
numberOfDecorators++;
tags = String.join(",", Arrays.asList(tagMatcher.group(1).trim().split(",")));
}
}

// For some reason, ISO_DATE_TIME doesn't like that time-zone is -0100. It wants -01:00.
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

public ZonedDateTime getDateStamp() {
try {
String value = decoratorMatcher.group(1);
String value = decoratorGroups[1];
if (value != null) {
TemporalAccessor temporalAccessor = formatter.parse(value.substring(1, value.length()-1));
return ZonedDateTime.from(temporalAccessor); }
return ZonedDateTime.from(temporalAccessor);
}
} catch (NullPointerException npe) {
LOGGER.log(Level.SEVERE, npe.getMessage(), npe);
}
return null;
}

public double getUpTime() {
String value = decoratorMatcher.group(2);
String value = decoratorGroups[2];
if (value != null) {
value = value.replace(",", ".");
return Double.parseDouble(unboxValue(value, 1));
Expand All @@ -121,10 +120,10 @@ public double getUpTime() {

private long extractClock(int groupIndex, long threshold) {
long clockReading = -1L;
String stringValue = decoratorMatcher.group(groupIndex);
String stringValue = decoratorGroups[groupIndex];
if (stringValue != null) {
clockReading = Long.parseLong(unboxValue(stringValue, 2));
if (decoratorMatcher.group(groupIndex + 1) == null)
if (decoratorGroups[groupIndex + 1] == null)
if (clockReading < threshold)
clockReading = -1L;
}
Expand All @@ -136,9 +135,9 @@ public long getTimeMillis() {
}

public long getUptimeMillis() {
String value = decoratorMatcher.group(4);
String value = decoratorGroups[4];
if (value == null) {
value = decoratorMatcher.group(3);
value = decoratorGroups[3];
}
if (value != null) {
long longValue = Long.parseLong(unboxValue(value, 2));
Expand All @@ -153,9 +152,9 @@ public long getTimeNano() {
}

public long getUptimeNano() {
String value = decoratorMatcher.group(6);
String value = decoratorGroups[6];
if (value == null) {
value = decoratorMatcher.group(5);
value = decoratorGroups[5];
}
if (value != null) {
long longValue = Long.parseLong(unboxValue(value, 2));
Expand All @@ -166,23 +165,23 @@ public long getUptimeNano() {
}

public int getPid() {
String value = decoratorMatcher.group(7);
String value = decoratorGroups[7];
if (value != null) {
return Integer.parseInt(unboxValue(value));
}
return -1;
}

public int getTid() {
String value = decoratorMatcher.group(8);
String value = decoratorGroups[8];
if (value != null) {
return Integer.parseInt(unboxValue(value));
}
return -1;
}

public Optional<UnifiedLoggingLevel> getLogLevel() {
String level = decoratorMatcher.group(9);
String level = decoratorGroups[9];
if (level != null)
try {
return Optional.of(UnifiedLoggingLevel.valueOf(unboxValue(level)));
Expand Down Expand Up @@ -211,10 +210,13 @@ private String unboxValue(String boxedValue) {
}

public boolean tagsContain(String tagList) {
return tags.contains(tagList);
return getTags().contains(tagList);
}

public String getTags() {
if (tags == null && decoratorGroups[10] != null) {
tags = String.join(",", Arrays.asList(unboxValue(decoratorGroups[10]).trim().split(",")));
}
return tags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public interface UnifiedLoggingTokens extends GenericTokens {
String TIME_NANOS = "\\[\\d+ns\\]";
String PID_TID = "\\[\\d+\\]";
String UNIFIED_LOG_LEVEL_BLOCK = "\\[(?:error|warning|info|debug|trace|develop) *\\]";
Pattern DECORATORS = Pattern.compile("(" + DATE_STAMP + ")?(" + UPTIME + ")?(" + TIME_MILLIS + ")?(" + TIME_MILLIS + ")?(" + TIME_NANOS + ")?(" + TIME_NANOS + ")?(" + PID_TID + ")?(" + PID_TID + ")?(" + UNIFIED_LOG_LEVEL_BLOCK + ")?");
//Using zero-width negative lookbehind to miss capturing records formatted like [0x1f03].
//[0.081s][trace][safepoint] Thread: 0x00007fd0d2006800 [0x1f03] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
Pattern TAGS = Pattern.compile(".*(?<=^|\\])\\[([a-z0-9,. ]+)\\]");
// We combine TAGS with the DECORATORS for performance reasons.
String TAGS = "\\[[a-z0-9,. ]+\\]";
Pattern DECORATORS = Pattern.compile("^(" + DATE_STAMP + ")?(" + UPTIME + ")?(" + TIME_MILLIS + ")?(" + TIME_MILLIS + ")?(" + TIME_NANOS + ")?(" + TIME_NANOS + ")?(" + PID_TID + ")?(" + PID_TID + ")?(" + UNIFIED_LOG_LEVEL_BLOCK + ")?(" + TAGS + ")?");

String UNIFIED_META_RECORD = "Metaspace: " + BEFORE_AFTER_CONFIGURED;
String WORKER_SUMMARY_REAL = "Min:\\s+" + TIME + ", Avg:\\s+" + TIME + ", Max:\\s+" + TIME + ", Diff:\\s+" + TIME + ", Sum:\\s+" + TIME + ", Workers:\\s+" + COUNTER;
Expand Down