-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upstream merge from branch 'develop' into feature/#87/swingworker
* develop: reduce number of WARNING messages when parsing introduction of a detailed G1 message fails (#128) add Àngel Ollé Blázquez to list of contributors fix merge problem between #129 and #130 export graph to PNG fature using the GCViewer GUI Command line graph generation random issue parallel scavenge collector: handle combination of -XX:+PrintAdaptiveSizePolicy, -XX:+PrintTenuringDistribution, -XX:+PrintApplicationStoppedTime (#128) fix negative pause for VM_OPERATION event near parser problem (#128) Conflicts: src/main/java/com/tagtraum/perf/gcviewer/exp/impl/DataWriterFactory.java src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderSun1_7_0G1.java src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderSun1_8_0G1.java
- Loading branch information
Showing
18 changed files
with
428 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ public enum DataWriterType { | |
CSV, | ||
CSV_TS, | ||
SIMPLE, | ||
SUMMARY; | ||
SUMMARY, | ||
PNG; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
/** | ||
* Factory for all available {@link DataWriter} implementations. | ||
* | ||
* | ||
* <p>Date: Feb 1, 2002 | ||
* <p>Time: 10:34:39 AM | ||
* @author <a href="mailto:[email protected]">Hendrik Schreiber</a> | ||
|
@@ -21,7 +21,7 @@ public class DataWriterFactory { | |
/** | ||
* Standard factory method to retrieve one of the <code>DataWriter</code> implementations. | ||
* If a DataWriter implementation needs additional configuration, use the other method. | ||
* | ||
* | ||
* @param file file, where to write output to | ||
* @param type type of DataWriter | ||
* @return instance of DataWriter according to <code>type</code> parameter | ||
|
@@ -36,7 +36,7 @@ public static DataWriter getDataWriter(File file, DataWriterType type) throws IO | |
* Factory method to retrieve one of the <code>DataWriter</code> implementations including | ||
* the option to add a map of configuration objects. The map will be passed to the DataWriter, | ||
* which can use its contents. | ||
* | ||
* | ||
* @param file file, where to write output to | ||
* @param type type of DataWriter | ||
* @param configuration Map containing additional configuration objects that will be passed | ||
|
@@ -46,15 +46,15 @@ public static DataWriter getDataWriter(File file, DataWriterType type) throws IO | |
* @throws IOException unknown DataWriter or problem creating file | ||
*/ | ||
public static DataWriter getDataWriter(File file, DataWriterType type, Map<String, Object> configuration) throws IOException { | ||
try (FileOutputStream outputStream = new FileOutputStream(file)) { | ||
switch (type) { | ||
case PLAIN : return new PlainDataWriter(outputStream); | ||
case CSV : return new CSVDataWriter(outputStream); | ||
case CSV_TS : return new CSVTSDataWriter(outputStream); | ||
case SIMPLE : return new SimpleGcWriter(outputStream); | ||
case SUMMARY : return new SummaryDataWriter(outputStream, configuration); | ||
default : throw new IOException(LocalisationHelper.getString("datawriterfactory_instantiation_failed") + " " + file); | ||
} | ||
FileOutputStream outputStream = new FileOutputStream(file); | ||
switch (type) { | ||
case PLAIN : return new PlainDataWriter(outputStream); | ||
case CSV : return new CSVDataWriter(outputStream); | ||
case CSV_TS : return new CSVTSDataWriter(outputStream); | ||
case SIMPLE : return new SimpleGcWriter(outputStream); | ||
case SUMMARY : return new SummaryDataWriter(outputStream, configuration); | ||
case PNG : return new PNGDataWriter(outputStream); | ||
default : throw new IOException(LocalisationHelper.getString("datawriterfactory_instantiation_failed") + " " + file); | ||
} | ||
} | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
src/main/java/com/tagtraum/perf/gcviewer/exp/impl/PNGDataWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.tagtraum.perf.gcviewer.exp.impl; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import com.tagtraum.perf.gcviewer.view.SimpleChartRenderer; | ||
import com.tagtraum.perf.gcviewer.exp.AbstractDataWriter; | ||
import com.tagtraum.perf.gcviewer.model.GCModel; | ||
|
||
/** | ||
* PNG data writter | ||
* | ||
* @author Angel Olle Blazquez | ||
* | ||
*/ | ||
public class PNGDataWriter extends AbstractDataWriter { | ||
private FileOutputStream out; | ||
|
||
public PNGDataWriter(OutputStream outputStream) { | ||
super(outputStream); | ||
out = (FileOutputStream)outputStream; | ||
} | ||
|
||
@Override | ||
public void write(GCModel model) throws IOException { | ||
new SimpleChartRenderer().render(model, out); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 94 additions & 21 deletions
115
src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,119 @@ | ||
package com.tagtraum.perf.gcviewer.view; | ||
|
||
import com.tagtraum.perf.gcviewer.model.GCModel; | ||
import com.tagtraum.perf.gcviewer.view.model.GCPreferences; | ||
|
||
import javax.imageio.ImageIO; | ||
import javax.swing.*; | ||
|
||
import java.awt.*; | ||
import java.awt.Color; | ||
import java.awt.Dimension; | ||
import java.awt.EventQueue; | ||
import java.awt.Graphics2D; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
import java.io.OutputStream; | ||
import java.lang.reflect.InvocationTargetException; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.SwingUtilities; | ||
|
||
import com.tagtraum.perf.gcviewer.view.model.GCPreferences; | ||
|
||
public class SimpleChartRenderer { | ||
private static final Logger LOGGER = Logger.getLogger(SimpleChartRenderer.class.getName()); | ||
|
||
public void render(GCModel model, String chartFilePath) throws IOException { | ||
public void render(GCModel model, FileOutputStream outputStream) throws IOException { | ||
GCPreferences gcPreferences = new GCPreferences(); | ||
gcPreferences.load(); | ||
Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight()); | ||
|
||
BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); | ||
Graphics2D graphics = image.createGraphics(); | ||
graphics.setBackground(Color.WHITE); | ||
graphics.clearRect(0, 0, image.getWidth(), image.getHeight()); | ||
|
||
ChartDrawingParameters params | ||
= new ChartDrawingParameters(model, gcPreferences, d, graphics, image, outputStream); | ||
|
||
if (EventQueue.isDispatchThread()) { | ||
drawAndSaveToStream(params); | ||
} | ||
else { | ||
new SwingChartToStreamHelper().execute(params); | ||
} | ||
} | ||
|
||
final ModelChartImpl pane = new ModelChartImpl(); | ||
private void drawAndSaveToStream(ChartDrawingParameters params) throws IOException { | ||
ModelChartImpl pane = new ModelChartImpl(); | ||
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); | ||
|
||
pane.setModel(model, gcPreferences); | ||
pane.setFootprint(model.getFootprint()); | ||
pane.setMaxPause(model.getPause().getMax()); | ||
pane.setRunningTime(model.getRunningTime()); | ||
pane.setModel(params.model, params.gcPreferences); | ||
pane.setFootprint(params.model.getFootprint()); | ||
pane.setMaxPause(params.model.getPause().getMax()); | ||
pane.setRunningTime(params.model.getRunningTime()); | ||
|
||
Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight()); | ||
pane.setSize(d); | ||
pane.setSize(params.dimension); | ||
pane.addNotify(); | ||
pane.validate(); | ||
|
||
pane.autoSetScaleFactor(); | ||
pane.paint(params.graphics); | ||
|
||
final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); | ||
final Graphics2D graphics = image.createGraphics(); | ||
graphics.setBackground(Color.WHITE); | ||
graphics.clearRect(0, 0, image.getWidth(), image.getHeight()); | ||
ImageIO.write(params.image, "png", params.outputStream); | ||
params.outputStream.close(); | ||
} | ||
|
||
/** | ||
* Helperclass that saves the chart to a file making sure, it happens on the EventDispathThread. | ||
*/ | ||
private class SwingChartToStreamHelper { | ||
|
||
private IOException ioException; | ||
|
||
public void execute(ChartDrawingParameters params) throws IOException { | ||
try { | ||
SwingUtilities.invokeAndWait(() -> { | ||
try { | ||
drawAndSaveToStream(params); | ||
} | ||
catch (IOException e) { | ||
this.ioException = e; | ||
} | ||
}); | ||
} | ||
catch (InterruptedException | InvocationTargetException e) { | ||
// may look a bit strange, but allows to defer exception handling to a place, where it makes sense. | ||
ioException = new IOException(e); | ||
} | ||
|
||
if (ioException != null) { | ||
throw ioException; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Holder class wrapping all parameters needed to draw the chart and save it to an OutputStream. | ||
*/ | ||
private static class ChartDrawingParameters { | ||
|
||
GCModel model; | ||
GCPreferences gcPreferences; | ||
Dimension dimension; | ||
Graphics2D graphics; | ||
BufferedImage image; | ||
OutputStream outputStream; | ||
|
||
pane.paint(graphics); | ||
public ChartDrawingParameters(GCModel model, | ||
GCPreferences gcPreferences, | ||
Dimension dimension, | ||
Graphics2D graphics, | ||
BufferedImage image, | ||
OutputStream outputStream) { | ||
|
||
ImageIO.write(image, "png", new File(chartFilePath)); | ||
this.model = model; | ||
this.gcPreferences = gcPreferences; | ||
this.dimension = dimension; | ||
this.graphics = graphics; | ||
this.image = image; | ||
this.outputStream = outputStream; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.