From 46ba130b7b836d2fdcdcadb1318d3debc60e71f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Link?= Date: Fri, 15 Jan 2021 06:03:54 +0100 Subject: [PATCH] ILogParser allows Readers for processing now. This makes the API more flexible. E.g. one could pass in a Reader that is based on a ProgressInputStream so that progress can be reported for large input files. --- .../jitwatch/parser/AbstractLogParser.java | 9 +++--- .../jitwatch/parser/ILogParser.java | 28 +++++++++++-------- .../parser/hotspot/HotSpotLogParser.java | 7 ++--- .../jitwatch/parser/j9/J9LogParser.java | 27 +++++++++--------- .../jitwatch/parser/zing/ZingLogParser.java | 7 ++--- .../jitwatch/test/UnitTestLogParser.java | 18 ++++++------ 6 files changed, 50 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/AbstractLogParser.java b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/AbstractLogParser.java index 3e8a5024..2e4e56b2 100644 --- a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/AbstractLogParser.java +++ b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/AbstractLogParser.java @@ -30,6 +30,7 @@ import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_TASK_DONE; import java.io.File; +import java.io.Reader; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -344,7 +345,7 @@ private void logSplitStats() } @Override - public void processLogFile(File logFile, ILogParseErrorListener errorListener) + public void processLogFile(Reader logFileReader, ILogParseErrorListener errorListener) { reset(); @@ -355,7 +356,7 @@ public void processLogFile(File logFile, ILogParseErrorListener errorListener) this.errorListener = errorListener; - splitLogFile(logFile); + splitLogFile(logFileReader); if (DEBUG_LOGGING) { @@ -540,7 +541,7 @@ protected void setTagTask(Task tagTask, IMetaMember member) if (compilation != null) { compilation.setTagTask(tagTask); - + if (currentCompilerThread != null) { currentCompilerThread.addCompilation(compilation); @@ -671,7 +672,7 @@ private void renameCompilationCompletedTimestamp(Tag tag) protected abstract void parseLogFile(); - protected abstract void splitLogFile(File logFile); + protected abstract void splitLogFile(Reader logFileReader); protected abstract void handleTag(Tag tag); } diff --git a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/ILogParser.java b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/ILogParser.java index 3a98d3a7..9ad9f6e4 100644 --- a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/ILogParser.java +++ b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/ILogParser.java @@ -6,7 +6,9 @@ package org.adoptopenjdk.jitwatch.parser; import java.io.File; +import java.io.FileReader; import java.io.IOException; +import java.io.Reader; import org.adoptopenjdk.jitwatch.core.JITWatchConfig; import org.adoptopenjdk.jitwatch.model.JITDataModel; @@ -16,24 +18,28 @@ public interface ILogParser { void setConfig(JITWatchConfig config); - - void processLogFile(File logFile, ILogParseErrorListener listener) throws IOException; - + + default void processLogFile(File logFile, ILogParseErrorListener listener) throws IOException{ + processLogFile(new FileReader(logFile), listener); + } + + void processLogFile(Reader logFileReader, ILogParseErrorListener listener) throws IOException; + SplitLog getSplitLog(); - + void stopParsing(); - + ParsedClasspath getParsedClasspath(); - + JITDataModel getModel(); - + JITWatchConfig getConfig(); - + void reset(); - + boolean hasParseError(); - + String getVMCommand(); - + void discardParsedLogs(); } \ No newline at end of file diff --git a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/hotspot/HotSpotLogParser.java b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/hotspot/HotSpotLogParser.java index 4d257549..7779dbd1 100644 --- a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/hotspot/HotSpotLogParser.java +++ b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/hotspot/HotSpotLogParser.java @@ -42,9 +42,8 @@ import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.ATTR_TIME_MS; import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.List; @@ -182,11 +181,11 @@ private void parseAssemblyLines() } @Override - protected void splitLogFile(File hotspotLog) + protected void splitLogFile(Reader hotspotLogReader) { reading = true; - try (BufferedReader reader = new BufferedReader(new FileReader(hotspotLog), 65536)) + try (BufferedReader reader = new BufferedReader(hotspotLogReader, 65536)) { String currentLine = reader.readLine(); diff --git a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/j9/J9LogParser.java b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/j9/J9LogParser.java index e384546b..b542a14f 100644 --- a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/j9/J9LogParser.java +++ b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/j9/J9LogParser.java @@ -11,9 +11,8 @@ import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_TASK_QUEUED; import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.io.Reader; import org.adoptopenjdk.jitwatch.core.IJITListener; import org.adoptopenjdk.jitwatch.model.NumberedLine; @@ -39,47 +38,47 @@ protected void parseLogFile() processLineNumber = numberedLine.getLineNumber(); J9Line j9Line = J9Util.parseLine(numberedLine.getLine()); - + if (DEBUG_LOGGING) { logger.debug("J9 log line parsed\n{}", j9Line); } - + Tag tagQueued = j9Line.toTagQueued(compileID, timestampMillis); Tag tagNMethod = j9Line.toTagNMethod(compileID, timestampMillis); Tag tagTask = j9Line.toTagTask(compileID, timestampMillis); - + compileID++; - + timestampMillis++; - + if (tagQueued != null) { handleTag(tagQueued); } - + if (tagNMethod != null) { handleTag(tagNMethod); } - + if (tagTask != null) { handleTag(tagTask); } } } - + @Override protected void handleTag(Tag tag) { String tagName = tag.getName(); - + if (DEBUG_LOGGING) { logger.debug("handling {}", tagName); } - + switch (tagName) { case TAG_TASK_QUEUED: @@ -100,11 +99,11 @@ protected void handleTag(Tag tag) } @Override - protected void splitLogFile(File logFile) + protected void splitLogFile(Reader logFileReader) { reading = true; - try (BufferedReader reader = new BufferedReader(new FileReader(logFile), 65536)) + try (BufferedReader reader = new BufferedReader(logFileReader, 65536)) { String currentLine = reader.readLine(); diff --git a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/zing/ZingLogParser.java b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/zing/ZingLogParser.java index 1256225b..32ffb678 100644 --- a/core/src/main/java/org/adoptopenjdk/jitwatch/parser/zing/ZingLogParser.java +++ b/core/src/main/java/org/adoptopenjdk/jitwatch/parser/zing/ZingLogParser.java @@ -11,9 +11,8 @@ import static org.adoptopenjdk.jitwatch.core.JITWatchConstants.TAG_TASK_QUEUED; import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.io.Reader; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -347,11 +346,11 @@ protected void parseLogFile() } @Override - protected void splitLogFile(File logFile) + protected void splitLogFile(Reader logFileReader) { reading = true; - try (BufferedReader reader = new BufferedReader(new FileReader(logFile), 65536)) + try (BufferedReader reader = new BufferedReader(logFileReader, 65536)) { String currentLine = reader.readLine(); diff --git a/core/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestLogParser.java b/core/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestLogParser.java index 9894a008..425df91c 100644 --- a/core/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestLogParser.java +++ b/core/src/test/java/org/adoptopenjdk/jitwatch/test/UnitTestLogParser.java @@ -1,6 +1,6 @@ package org.adoptopenjdk.jitwatch.test; -import java.io.File; +import java.io.Reader; import org.adoptopenjdk.jitwatch.core.IJITListener; import org.adoptopenjdk.jitwatch.model.CompilerThread; @@ -10,11 +10,11 @@ import org.adoptopenjdk.jitwatch.parser.AbstractLogParser; public class UnitTestLogParser extends AbstractLogParser -{ +{ public UnitTestLogParser(IJITListener jitListener) { super(jitListener); - + currentCompilerThread = new CompilerThread("1234", "TestCompilerThread"); } @@ -24,33 +24,33 @@ protected void parseLogFile() } @Override - protected void splitLogFile(File logFile) + protected void splitLogFile(Reader logFileReader) { } @Override protected void handleTag(Tag tag) - { + { } - + @Override public void setTagTaskQueued(Tag tagTaskQueued, IMetaMember metaMember) { super.setTagTaskQueued(tagTaskQueued, metaMember); } - + @Override public void setTagNMethod(Tag tagNMethod, IMetaMember member) { super.setTagNMethod(tagNMethod, member); } - + @Override public void setTagTask(Task tagTask, IMetaMember member) { super.setTagTask(tagTask, member); } - + public void setTagTaskDone(Tag tagTaskDone, IMetaMember member) { super.handleTaskDone(tagTaskDone, member);