Skip to content

Commit

Permalink
Merge pull request #337 from renelink/master
Browse files Browse the repository at this point in the history
ILogParser allows Readers for processing now.
  • Loading branch information
chriswhocodes authored Jan 16, 2021
2 parents bcb5ba8 + 46ba130 commit bb50980
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -344,7 +345,7 @@ private void logSplitStats()
}

@Override
public void processLogFile(File logFile, ILogParseErrorListener errorListener)
public void processLogFile(Reader logFileReader, ILogParseErrorListener errorListener)
{
reset();

Expand All @@ -355,7 +356,7 @@ public void processLogFile(File logFile, ILogParseErrorListener errorListener)

this.errorListener = errorListener;

splitLogFile(logFile);
splitLogFile(logFileReader);

if (DEBUG_LOGGING)
{
Expand Down Expand Up @@ -540,7 +541,7 @@ protected void setTagTask(Task tagTask, IMetaMember member)
if (compilation != null)
{
compilation.setTagTask(tagTask);

if (currentCompilerThread != null)
{
currentCompilerThread.addCompilation(compilation);
Expand Down Expand Up @@ -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);
}
28 changes: 17 additions & 11 deletions core/src/main/java/org/adoptopenjdk/jitwatch/parser/ILogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
}

Expand All @@ -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);
Expand Down

0 comments on commit bb50980

Please sign in to comment.