Skip to content

Commit

Permalink
Implement DataTimestamps decorator parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ophillan committed Aug 31, 2017
1 parent 5a68aa6 commit 31f0add
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.time.ZonedDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
Expand Down Expand Up @@ -42,24 +43,31 @@ public class DataReaderShenandoah extends AbstractDataReader {
// Group 1: 0.693 // Group 1: 0.693
// Group 2: Pause Init Mark // Group 2: Pause Init Mark
// Group 3: 1.070 // Group 3: 1.070
// Regex: ^\[([0-9]+[.,][0-9]+)[^\-]*\)[ ]([^\-]*)[ ]([0-9]+[.,][0-9]+) // Regex: ^\[([^s\]]*)[^\-]*\)[ ]([^\-]*)[ ]([0-9]+[.,][0-9]+)
private static final Pattern PATTERN_WITHOUT_HEAP = Pattern.compile("^\\[([0-9]+[.,][0-9]+)[^\\-]*\\)[ ]([^\\-]*)[ ]([0-9]+[.,][0-9]+)"); private static final Pattern PATTERN_WITHOUT_HEAP = Pattern.compile(
"^\\[([^s\\]]*)[^\\-]*\\)[ ]([^\\-]*)[ ]([0-9]+[.,][0-9]+)");


// Input: [13.522s][info][gc ] GC(708) Concurrent evacuation 4848M->4855M(4998M) 2.872ms // Input: [13.522s][info][gc ] GC(708) Concurrent evacuation 4848M->4855M(4998M) 2.872ms
// Group 1: 13.522 // Group 1: 13.522
// Group 2: Concurrent evacuation // Group 2: Concurrent evacuation
// Group 3: 4848M->4855M(4998M) // Group 3: 4848M->4855M(4998M)
// Group 4: 2.872 // Group 4: 2.872
// Regex: ^\[([0-9]+[.,][0-9]+).*\)[ ](.*)[ ]([0-9]+[BKMG]\-\>[0-9]+[BKMG]\([0-9]+[BKMG]\)) ([0-9]+[.,][0-9]+) // Regex: ^\[([^s\]]*).*\)[ ](.*)[ ]([0-9]+[BKMG]\-\>[0-9]+[BKMG]\([0-9]+[BKMG]\)) ([0-9]+[.,][0-9]+)
private static final Pattern PATTERN_WITH_HEAP = Pattern.compile( private static final Pattern PATTERN_WITH_HEAP = Pattern.compile(
"^\\[([0-9]+[.,][0-9]+).*\\)[ ](.*)[ ]([0-9]+[BKMG]->[0-9]+[BKMG]\\([0-9]+[BKMG]\\)) ([0-9]+[.,][0-9]+)"); "^\\[([^s\\]]*).*\\)[ ](.*)[ ]([0-9]+[BKMG]\\-\\>[0-9]+[BKMG]\\([0-9]+[BKMG]\\)) ([0-9]+[.,][0-9]+)");


// Input: 4848M->4855M(4998M) // Input: 4848M->4855M(4998M)
// Group 1: 4848 // Group 1: 4848
// Group 2: 4855 // Group 2: 4855
// Group 3: 4998 // Group 3: 4998
// Regex: ([0-9]+)[BKMG]\-\>([0-9]+)[BKMG]\(([0-9]+)[BKMG]\) // Regex: ([0-9]+)[BKMG]\-\>([0-9]+)[BKMG]\(([0-9]+)[BKMG]\)
private static final Pattern PATTERN_HEAP_CHANGES = Pattern.compile("([0-9]+)([BKMG])->([0-9]+)([BKMG])\\(([0-9]+)([BKMG])\\)"); private static final Pattern PATTERN_HEAP_CHANGES = Pattern.compile(
"([0-9]+)([BKMG])->([0-9]+)([BKMG])\\(([0-9]+)([BKMG])\\)");

// Input: 2017-08-30T23:22:47.357+0300
// Regex: ^\d{4}\-\d\d\-\d\d[tT][\d:\.]*?(?:[zZ]|[+\-]\d\d:?\d\d)?$
private static final Pattern PATTERN_ISO8601_DATE = Pattern.compile(
"^\\d{4}\\-\\d\\d\\-\\d\\d[tT][\\d:\\.]*?(?:[zZ]|[+\\-]\\d\\d:?\\d\\d)?$");


private static final int NO_HEAP_TIMESTAMP = 1; private static final int NO_HEAP_TIMESTAMP = 1;
private static final int NO_HEAP_EVENT_NAME = 2; private static final int NO_HEAP_EVENT_NAME = 2;
Expand Down Expand Up @@ -109,30 +117,35 @@ private AbstractGCEvent<?> parseShenandoahEvent(String line) {
event = new GCEvent(); event = new GCEvent();
AbstractGCEvent.Type type = AbstractGCEvent.Type.lookup(noHeapMatcher.group(NO_HEAP_EVENT_NAME)); AbstractGCEvent.Type type = AbstractGCEvent.Type.lookup(noHeapMatcher.group(NO_HEAP_EVENT_NAME));
event.setType(type); event.setType(type);
setPauseAndTimestamp(event, noHeapMatcher.group(NO_HEAP_DURATION), noHeapMatcher.group(NO_HEAP_TIMESTAMP)); setPauseAndDateOrTimestamp(event, noHeapMatcher.group(NO_HEAP_TIMESTAMP), noHeapMatcher.group(NO_HEAP_DURATION));
} else if (withHeapMatcher.find()) { } else if (withHeapMatcher.find()) {
event = line.contains("Concurrent") ? new ConcurrentGCEvent() : new GCEvent(); event = line.contains("Concurrent") ? new ConcurrentGCEvent() : new GCEvent();
AbstractGCEvent.Type type = AbstractGCEvent.Type.lookup(withHeapMatcher.group(WITH_HEAP_EVENT_NAME)); AbstractGCEvent.Type type = AbstractGCEvent.Type.lookup(withHeapMatcher.group(WITH_HEAP_EVENT_NAME));
event.setType(type); event.setType(type);
setPauseAndTimestamp(event, withHeapMatcher.group(WITH_HEAP_DURATION), withHeapMatcher.group(WITH_HEAP_TIMESTAMP)); setPauseAndDateOrTimestamp(event, withHeapMatcher.group(WITH_HEAP_TIMESTAMP), withHeapMatcher.group(WITH_HEAP_DURATION));
addHeapDetailsToEvent(event, withHeapMatcher.group(WITH_HEAP_MEMORY)); addHeapDetailsToEvent(event, withHeapMatcher.group(WITH_HEAP_MEMORY));
} else { } else {
getLogger().warning(String.format("Failed to parse Line number %d in the log file: %s", in.getLineNumber(), line)); getLogger().warning(String.format("Failed to parse line number %d in the log file: %s", in.getLineNumber(), line));
} }


return event; return event;
} }


/** /**
* @param event GC event to which pause and timestamp information is added * @param event GC event to which pause and timestamp information is added
* @param pauseAsString Pause information from regex group as string * @param pauseAsString Pause information from regex group as string
* @param timestampAsString Timestamp information from regex group as string * @param dateOrTimeStampAsString Date- or timestamp information from regex group as string
*/ */
private void setPauseAndTimestamp(AbstractGCEvent<?> event, String pauseAsString, String timestampAsString) { private void setPauseAndDateOrTimestamp(AbstractGCEvent<?> event, String dateOrTimeStampAsString, String pauseAsString) {
double pause = Double.parseDouble(pauseAsString.replace(",", ".")); double pause = Double.parseDouble(pauseAsString.replace(",", "."));
double timestamp = Double.parseDouble(timestampAsString.replace(",", "."));
event.setPause(pause / 1000); event.setPause(pause / 1000);
event.setTimestamp(timestamp); if (PATTERN_ISO8601_DATE.matcher(dateOrTimeStampAsString).find()) {
ZonedDateTime dateTime = ZonedDateTime.parse(dateOrTimeStampAsString, AbstractDataReaderSun.DATE_TIME_FORMATTER);
event.setDateStamp(dateTime);
} else {
double timestamp = Double.parseDouble(dateOrTimeStampAsString.replace(",", "."));
event.setTimestamp(timestamp);
}
} }


/** /**
Expand Down
Expand Up @@ -6,6 +6,7 @@


import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.time.ZonedDateTime;
import java.util.logging.Level; import java.util.logging.Level;


import com.tagtraum.perf.gcviewer.UnittestHelper; import com.tagtraum.perf.gcviewer.UnittestHelper;
Expand Down Expand Up @@ -140,6 +141,30 @@ public void parseSeveralSystemGCEvents() throws Exception {
assertThat("timestamp", event.getTimestamp(), closeTo(1.303, 0.001)); assertThat("timestamp", event.getTimestamp(), closeTo(1.303, 0.001));
} }


@Test
public void parseDateTimeStamps() throws Exception {
GCModel model = getGCModelFromLogFile("SampleShenandoahDateTimeStamps.txt");
assertThat("size", model.size(), is(557));

GCEvent event = (GCEvent) model.get(0);
assertThat("datestamp", event.getDatestamp(), is(ZonedDateTime.parse("2017-08-30T23:22:47.357+0300",
AbstractDataReaderSun.DATE_TIME_FORMATTER)));
assertThat("timestamp", event.getTimestamp(), is(0.0));
assertThat("type", event.getTypeAsString(), is(AbstractGCEvent.Type.SHEN_STW_INIT_MARK.toString()));
assertThat("generation", event.getGeneration(), is(AbstractGCEvent.Generation.TENURED));

ConcurrentGCEvent event2 = (ConcurrentGCEvent) model.get(1);
assertThat("datestamp", event.getDatestamp(), is(ZonedDateTime.parse("2017-08-30T23:22:47.357+0300",
AbstractDataReaderSun.DATE_TIME_FORMATTER)));
assertThat("timestamp", event2.getTimestamp(), closeTo(0.003, 0.001));
assertThat("type", event2.getTypeAsString(), is(AbstractGCEvent.Type.SHEN_CONCURRENT_CONC_MARK.toString()));
assertThat("preUsed heap size", event2.getPreUsed(), is(90 * 1024));
assertThat("postUsed heap size", event2.getPostUsed(), is(90 * 1024));
assertThat("total heap size", event2.getTotal(), is(128 * 1024));
assertThat("generation", event2.getGeneration(), is(AbstractGCEvent.Generation.TENURED));
}


private GCModel getGCModelFromLogFile(String fileName) throws IOException { private GCModel getGCModelFromLogFile(String fileName) throws IOException {
TestLogHandler handler = new TestLogHandler(); TestLogHandler handler = new TestLogHandler();
handler.setLevel(Level.WARNING); handler.setLevel(Level.WARNING);
Expand Down

0 comments on commit 31f0add

Please sign in to comment.