Skip to content

Commit

Permalink
Merge branch 'feature/enhance-shenandoah-datareader' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
chewiebug committed Sep 8, 2017
2 parents f306f4c + 60d19ae commit 30873e0
Show file tree
Hide file tree
Showing 28 changed files with 33,598 additions and 380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ protected Logger getLogger() {
return gcResource.getLogger();
}

private DataReaderTools dataReaderTools;

protected DataReaderTools getDataReaderTools() {
if (dataReaderTools == null) {
dataReaderTools = new DataReaderTools(getLogger());
}

return dataReaderTools;
}

@Override
public abstract GCModel read() throws IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package com.tagtraum.perf.gcviewer.imp;

import com.tagtraum.perf.gcviewer.model.AbstractGCEvent;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.ExtendedType;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.GcPattern;
import com.tagtraum.perf.gcviewer.model.GCEvent;
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.util.NumberParser;
import com.tagtraum.perf.gcviewer.util.ParseInformation;

import java.io.IOException;
import java.io.InputStream;
import java.io.LineNumberReader;
Expand All @@ -22,6 +14,14 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.tagtraum.perf.gcviewer.model.AbstractGCEvent;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.ExtendedType;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.GcPattern;
import com.tagtraum.perf.gcviewer.model.GCEvent;
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.util.NumberParser;
import com.tagtraum.perf.gcviewer.util.ParseInformation;

/**
* The AbstractDataReaderSun is the base class of most Sun / Oracle parser implementations.
* <p>
Expand Down Expand Up @@ -79,24 +79,7 @@ protected AbstractDataReaderSun(GCResource gcResource, InputStream in, GcLogType
* @return amount of memory in kilobyte
*/
private int getMemoryInKiloByte(double memoryValue, char memUnit, String line) {
if ('B' == memUnit) {
return (int) Math.rint(memoryValue / 1024);
}
else if ('K' == memUnit) {
return (int) Math.rint(memoryValue);
}
else if ('M' == memUnit) {
return (int) Math.rint(memoryValue * 1024);
}
else if ('G' == memUnit) {
return (int) Math.rint(memoryValue * 1024*1024);
}
else {
if (getLogger().isLoggable(Level.WARNING)) {
getLogger().warning("unknown memoryunit '" + memUnit + "' in line " + line);
}
return 1;
}
return getDataReaderTools().getMemoryInKiloByte(memoryValue, memUnit, line);
}

/**
Expand Down
76 changes: 44 additions & 32 deletions src/main/java/com/tagtraum/perf/gcviewer/imp/DataReaderFacade.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package com.tagtraum.perf.gcviewer.imp;

import com.tagtraum.perf.gcviewer.ctrl.impl.GcSeriesLoader;
import com.tagtraum.perf.gcviewer.model.GCModel;
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import com.tagtraum.perf.gcviewer.model.GcResourceSeries;
import com.tagtraum.perf.gcviewer.util.BuildInfoReader;
import com.tagtraum.perf.gcviewer.util.HttpUrlConnectionHelper;
import com.tagtraum.perf.gcviewer.util.LocalisationHelper;

import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
Expand All @@ -21,6 +12,15 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;

import com.tagtraum.perf.gcviewer.ctrl.impl.GcSeriesLoader;
import com.tagtraum.perf.gcviewer.model.GCModel;
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import com.tagtraum.perf.gcviewer.model.GcResourceSeries;
import com.tagtraum.perf.gcviewer.util.BuildInfoReader;
import com.tagtraum.perf.gcviewer.util.HttpUrlConnectionHelper;
import com.tagtraum.perf.gcviewer.util.LocalisationHelper;

/**
* DataReaderFacade is a helper class providing a simple interface to read a gc log file
* including standard error handling.
Expand Down Expand Up @@ -103,34 +103,46 @@ private GCModel readModel(GcResourceFile gcResource) throws IOException {
URL url = gcResource.getResourceNameAsUrl();
DataReaderFactory factory = new DataReaderFactory();
long contentLength = 0L;
InputStream in;
if (url.getProtocol().startsWith("http")) {
AtomicLong cl = new AtomicLong();
URLConnection conn = url.openConnection();
in = HttpUrlConnectionHelper.openInputStream((HttpURLConnection)conn, HttpUrlConnectionHelper.GZIP, cl);
contentLength = cl.get();
}
else {
in = url.openStream();
if (url.getProtocol().startsWith("file")) {
File file = new File(url.getFile());
if (file.exists()) {
contentLength = file.length();
InputStream in = null;
try {
if (url.getProtocol().startsWith("http")) {
AtomicLong cl = new AtomicLong();
URLConnection conn = url.openConnection();
in = HttpUrlConnectionHelper.openInputStream((HttpURLConnection) conn,
HttpUrlConnectionHelper.GZIP,
cl);
contentLength = cl.get();
}
else {
in = url.openStream();
if (url.getProtocol().startsWith("file")) {
File file = new File(url.getFile());
if (file.exists()) {
contentLength = file.length();
}
}
}
}
if (contentLength > 100L) {
in = new MonitoredBufferedInputStream(in, DataReaderFactory.FOUR_KB, contentLength);
for (PropertyChangeListener listener : propertyChangeListeners) {
((MonitoredBufferedInputStream)in).addPropertyChangeListener(listener);
if (contentLength > 100L) {
in = new MonitoredBufferedInputStream(in, DataReaderFactory.FOUR_KB, contentLength);
for (PropertyChangeListener listener : propertyChangeListeners) {
((MonitoredBufferedInputStream) in).addPropertyChangeListener(listener);
}
}
}

DataReader reader = factory.getDataReader(gcResource, in);
GCModel model = reader.read();
model.setURL(url);
DataReader reader = factory.getDataReader(gcResource, in);
GCModel model = reader.read();
model.setURL(url);

return model;
return model;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
gcResource.getLogger().warning("A problem occurred trying to close the InputStream: " + e.toString());
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ public GCModel read() throws IOException {
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Reading done.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,6 @@ If the heap area holding the reflection objects (representing classes and method
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Reading done.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ public GCModel read() throws IOException {
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Reading done.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ else if (line.indexOf("managing allocation failure, action=3") != -1) {
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Done reading.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ else if (line.indexOf("managing allocation failure, action=3") != -1) {
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Done reading.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ else if (line.indexOf("collection ending") != -1) {
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Done reading.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ else if (line.substring(startTimeIndex).startsWith("<")) {
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Reading done.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ else if (line.indexOf("->") == -1){
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Reading done.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ else if ((line.indexOf("C#") == -1) || (line.indexOf("->") == -1)){
return model;
}
finally {
if (in != null)
try {
in.close();
}
catch (IOException ioe) {
}
if (getLogger().isLoggable(Level.INFO)) getLogger().info("Reading done.");
}
}
Expand Down
Loading

0 comments on commit 30873e0

Please sign in to comment.