Skip to content

Commit

Permalink
Parsing Phases for ZGC
Browse files Browse the repository at this point in the history
  • Loading branch information
Marysunithajoseph committed Jan 15, 2019
1 parent dda185a commit 9643bd8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Expand Up @@ -79,13 +79,14 @@ public ExtendedType parseTypeWithCause(String typeName) {
typeName = typeName.trim(); typeName = typeName.trim();
ExtendedType extendedType = null; ExtendedType extendedType = null;
String lookupTypeName = getLookupTypeName(typeName); String lookupTypeName = getLookupTypeName(typeName);

AbstractGCEvent.Type gcType = AbstractGCEvent.Type.lookup(lookupTypeName); AbstractGCEvent.Type gcType = AbstractGCEvent.Type.lookup(lookupTypeName);
// the gcType may be null because there was a PrintGCCause flag enabled - if so, reparse it with the first paren set stripped // the gcType may be null because there was a PrintGCCause flag enabled - if so, reparse it with the first paren set stripped
if (gcType == null) { if (gcType == null) {
// try to parse it again with the parens removed // try to parse it again with the parents removed
Matcher parenMatcher = parenthesesPattern.matcher(lookupTypeName); Matcher parentMatcher = parenthesesPattern.matcher(lookupTypeName);
if (parenMatcher.find()) { if (parentMatcher.find()) {
gcType = AbstractGCEvent.Type.lookup(parenMatcher.replaceFirst("")); gcType = AbstractGCEvent.Type.lookup(parentMatcher.replaceFirst(""));
} }
} }


Expand Down
Expand Up @@ -123,15 +123,17 @@ public class DataReaderUnifiedJvmLogging extends AbstractDataReader {
private static final String TAG_GC_HEAP = "gc,heap"; private static final String TAG_GC_HEAP = "gc,heap";
private static final String TAG_GC_METASPACE = "gc,metaspace"; private static final String TAG_GC_METASPACE = "gc,metaspace";
private static final String TAG_GC_PHASES = "gc,phases"; private static final String TAG_GC_PHASES = "gc,phases";



/** list of strings, that must be part of the gc log line to be considered for parsing */ /** list of strings, that must be part of the gc log line to be considered for parsing */
private static final List<String> INCLUDE_STRINGS = Arrays.asList("[gc ", "[gc]", "[" + TAG_GC_START, "[" + TAG_GC_HEAP, "[" + TAG_GC_METASPACE, "[" + TAG_GC_PHASES); private static final List<String> INCLUDE_STRINGS = Arrays.asList("[gc ", "[gc]", "[" + TAG_GC_START, "[" + TAG_GC_HEAP, "[" + TAG_GC_METASPACE);
/** list of strings, that target gc log lines, that - although part of INCLUDE_STRINGS - are not considered a gc event */ /** list of strings, that target gc log lines, that - although part of INCLUDE_STRINGS - are not considered a gc event */
private static final List<String> EXCLUDE_STRINGS = Arrays.asList("Cancelling concurrent GC", "[debug", "[trace", "gc,heap,coops", "gc,heap,exit"); private static final List<String> EXCLUDE_STRINGS = Arrays.asList("Cancelling concurrent GC", "[debug", "[trace", "gc,heap,coops", "gc,heap,exit");
/** list of strings, that are gc log lines, but not a gc event -&gt; should be logged only */ /** list of strings, that are gc log lines, but not a gc event -&gt; should be logged only */
private static final List<String> LOG_ONLY_STRINGS = Arrays.asList("Using", "Heap region size"); private static final List<String> LOG_ONLY_STRINGS = Arrays.asList("Using", "Heap region size");

/** Pattern - for ZGC phases - that are to be included for parsing */

private static final Pattern PATTERN_INCLUDE_STRINGS_PHASE = Pattern.compile("\\[(gc,phases[ ]*)][ ]GC\\(([0-9]+)\\)[ ](?<type>[a-zA-Z1 ()]+)(([ ]([0-9]{1}.*))|$)");

protected DataReaderUnifiedJvmLogging(GCResource gcResource, InputStream in) throws UnsupportedEncodingException { protected DataReaderUnifiedJvmLogging(GCResource gcResource, InputStream in) throws UnsupportedEncodingException {
super(gcResource, in); super(gcResource, in);
} }
Expand All @@ -149,6 +151,7 @@ public GCModel read() throws IOException {
model.setFormat(GCModel.Format.UNIFIED_JVM_LOGGING); model.setFormat(GCModel.Format.UNIFIED_JVM_LOGGING);


Stream<String> lines = in.lines(); Stream<String> lines = in.lines();

lines.map(line -> new ParseContext(line, partialEventsMap, infoMap)) lines.map(line -> new ParseContext(line, partialEventsMap, infoMap))
.filter(this::lineContainsParseableEvent) .filter(this::lineContainsParseableEvent)
.map(this::parseEvent) .map(this::parseEvent)
Expand All @@ -163,7 +166,6 @@ public GCModel read() throws IOException {


private ParseContext parseEvent(ParseContext context) { private ParseContext parseEvent(ParseContext context) {
AbstractGCEvent<?> event = null; AbstractGCEvent<?> event = null;

Matcher decoratorsMatcher = PATTERN_DECORATORS.matcher(context.getLine()); Matcher decoratorsMatcher = PATTERN_DECORATORS.matcher(context.getLine());
try { try {
event = createGcEventWithStandardDecorators(decoratorsMatcher, context.getLine()); event = createGcEventWithStandardDecorators(decoratorsMatcher, context.getLine());
Expand Down Expand Up @@ -333,7 +335,6 @@ private void parseGcRegionTail(ParseContext context, AbstractGCEvent<?> event, S
private AbstractGCEvent<?> createGcEventWithStandardDecorators(Matcher decoratorsMatcher, String line) throws UnknownGcTypeException { private AbstractGCEvent<?> createGcEventWithStandardDecorators(Matcher decoratorsMatcher, String line) throws UnknownGcTypeException {
if (decoratorsMatcher.find()) { if (decoratorsMatcher.find()) {
AbstractGCEvent.ExtendedType type = getDataReaderTools().parseType(decoratorsMatcher.group(GROUP_DECORATORS_GC_TYPE)); AbstractGCEvent.ExtendedType type = getDataReaderTools().parseType(decoratorsMatcher.group(GROUP_DECORATORS_GC_TYPE));

AbstractGCEvent<?> event = type.getConcurrency().equals(Concurrency.CONCURRENT) ? new ConcurrentGCEvent() : new GCEventUJL(); AbstractGCEvent<?> event = type.getConcurrency().equals(Concurrency.CONCURRENT) ? new ConcurrentGCEvent() : new GCEventUJL();
event.setExtendedType(type); event.setExtendedType(type);
event.setNumber(Integer.parseInt(decoratorsMatcher.group(GROUP_DECORATORS_GC_NUMBER))); event.setNumber(Integer.parseInt(decoratorsMatcher.group(GROUP_DECORATORS_GC_NUMBER)));
Expand Down Expand Up @@ -393,7 +394,7 @@ private boolean isLogOnlyLine(String line) {
} }


private boolean lineContainsParseableEvent(ParseContext context) { private boolean lineContainsParseableEvent(ParseContext context) {
if (isCandidateForParseableEvent(context.getLine()) && !isExcludedLine(context.getLine())) { if ((isCandidateForParseableEvent(context.getLine()) && !isExcludedLine(context.getLine())) || isParseablePhaseEvent(context.getLine())) {
if (isLogOnlyLine(context.getLine())) { if (isLogOnlyLine(context.getLine())) {
String tail = context.getLine().substring(context.getLine().lastIndexOf("]")+1); String tail = context.getLine().substring(context.getLine().lastIndexOf("]")+1);
enrichContext(context, tail); enrichContext(context, tail);
Expand All @@ -406,7 +407,18 @@ private boolean lineContainsParseableEvent(ParseContext context) {
return false; return false;
} }


private void enrichContext(ParseContext context, String tail) { private boolean isParseablePhaseEvent(String line) {
Matcher phaseStringMatcher = line != null ? PATTERN_INCLUDE_STRINGS_PHASE.matcher(line) : null;
if(phaseStringMatcher.find()) {
String phaseType = phaseStringMatcher.group(GROUP_DECORATORS_GC_TYPE);
if(phaseType != null && AbstractGCEvent.Type.lookup(phaseType) != null) {
return true;
}
}
return false;
}

private void enrichContext(ParseContext context, String tail) {
Matcher regionSizeMatcher = tail != null ? PATTERN_HEAP_REGION_SIZE.matcher(tail.trim()) : null; Matcher regionSizeMatcher = tail != null ? PATTERN_HEAP_REGION_SIZE.matcher(tail.trim()) : null;
if (regionSizeMatcher != null && regionSizeMatcher.find()) { if (regionSizeMatcher != null && regionSizeMatcher.find()) {
try { try {
Expand Down

0 comments on commit 9643bd8

Please sign in to comment.