Skip to content

Commit

Permalink
upstream merge from branch 'develop' into feature/#87/swingworker
Browse files Browse the repository at this point in the history
* 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
chewiebug committed May 13, 2015
2 parents c0dd10b + 72f0c8a commit d6ae8ca
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 168 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<developer>
<name>Reinhard Nägele</name>
</developer>
<developer>
<name>Àngel Ollé Blázquez</name>
<url>https://github.com/aolle</url>
</developer>
<developer>
<name>Rupesh Ramachandran</name>
</developer>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/tagtraum/perf/gcviewer/GCViewer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tagtraum.perf.gcviewer;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
Expand Down Expand Up @@ -86,7 +87,7 @@ private void exportType(GCModel model, String summaryFilePath, DataWriterType ty

private void renderChart(GCModel model, String chartFilePath) throws IOException {
SimpleChartRenderer renderer = new SimpleChartRenderer();
renderer.render(model, chartFilePath);
renderer.render(model, new FileOutputStream(new File(chartFilePath)));
}

private static void usage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Export(final GCViewerGui gcViewer) {
saveDialog.addChoosableFileFilter(new ExtensionFileFilter(".txt", LocalisationHelper.getString("fileexport_dialog_txt"), DataWriterType.PLAIN));
saveDialog.addChoosableFileFilter(new ExtensionFileFilter(".simple.log", LocalisationHelper.getString("fileexport_dialog_simplelog"), DataWriterType.SIMPLE));
saveDialog.addChoosableFileFilter(new ExtensionFileFilter(".csv", LocalisationHelper.getString("fileexport_dialog_summarylog"), DataWriterType.SUMMARY));
saveDialog.addChoosableFileFilter(new ExtensionFileFilter(".png", LocalisationHelper.getString("fileexport_dialog_png"), DataWriterType.PNG));
}

public void actionPerformed(final ActionEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public enum DataWriterType {
CSV,
CSV_TS,
SIMPLE,
SUMMARY;
SUMMARY,
PNG;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class DataReaderSun1_6_0 extends AbstractDataReaderSun {
private static final String CMS_LARGE_BLOCK = "CMS: Large "; // -XX:+PrintFLSStatistics=1
private static final String SIZE = "size["; // -XX:+PrintFLSStatistics=1
private static final String TIMES = " [Times";
private static final String ADAPTIVE_PATTERN = "AdaptiveSize";

private static final List<String> EXCLUDE_STRINGS = new LinkedList<String>();

Expand Down Expand Up @@ -106,6 +107,9 @@ public class DataReaderSun1_6_0 extends AbstractDataReaderSun {
EXCLUDE_STRINGS.add(" free"); // -XX:+PrintFLSStatistics=2
EXCLUDE_STRINGS.add(SIZE); // -XX:+PrintFLSStatistics=2
EXCLUDE_STRINGS.add("demand"); // -XX:+PrintFLSStatistics=2
EXCLUDE_STRINGS.add(ADAPTIVE_PATTERN); // -XX:+PrintAdaptiveSizePolicy
EXCLUDE_STRINGS.add("PS" + ADAPTIVE_PATTERN); // -XX:PrintAdaptiveSizePolicy
EXCLUDE_STRINGS.add(" avg_survived_padded_avg"); // -XX:PrintAdaptiveSizePolicy
}

private static final String EVENT_YG_OCCUPANCY = "YG occupancy";
Expand Down Expand Up @@ -146,13 +150,6 @@ public class DataReaderSun1_6_0 extends AbstractDataReaderSun {
HEAP_STRINGS.add("}");
}

private static final List<String> ADAPTIVE_SIZE_POLICY_STRINGS = new LinkedList<String>();
static {
ADAPTIVE_SIZE_POLICY_STRINGS.add("PSAdaptiveSize");
ADAPTIVE_SIZE_POLICY_STRINGS.add("AdaptiveSize");
ADAPTIVE_SIZE_POLICY_STRINGS.add("avg_survived_padded_avg");
}

// 1_6_0_u24 mixes lines, when outputing a "promotion failed" which leads to a "concurrent mode failure"
// pattern looks always like "...[CMS<datestamp>..." or "...[CMS<timestamp>..."
// the next line starts with " (concurrent mode failure)" which in earlier releases followed "CMS" immediately
Expand All @@ -172,7 +169,6 @@ public class DataReaderSun1_6_0 extends AbstractDataReaderSun {
// -> to parse it, the first line must be split, and the following left out until the rest of the gc information follows
private static final String ADAPTIVE_SIZE_POLICY_PATTERN_STRING = "(.*GC \\([a-zA-Z ]*\\)|.*GC)(?:[0-9.:]*.*)[ ]?AdaptiveSize.*";
private static final Pattern adaptiveSizePolicyPattern = Pattern.compile(ADAPTIVE_SIZE_POLICY_PATTERN_STRING);
private static final String ADAPTIVE_PATTERN = "AdaptiveSize";

// -XX:+PrintAdaptiveSizePolicy combined with -XX:-UseAdaptiveSizePolicy (not using the policy, just printing)
// outputs the following line:
Expand Down Expand Up @@ -355,7 +351,6 @@ else if (line.indexOf(ADAPTIVE_PATTERN) >= 0) {
continue;
}
beginningOfLine.addFirst(adaptiveSizePolicyMatcher.group(1));
lineNumber = skipLines(in, parsePosition, lineNumber, ADAPTIVE_SIZE_POLICY_STRINGS);
}
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ public class DataReaderSun1_6_0G1 extends AbstractDataReaderSun {
EXCLUDE_STRINGS.add(SURVIVOR_AGE);
EXCLUDE_STRINGS.add(MARK_STACK_IS_FULL);
EXCLUDE_STRINGS.add(SETTING_ABORT_IN);
EXCLUDE_STRINGS.add(" [Root Region"); // all the details of a G1 event -> filter away, if parsing of introduction was not possible
EXCLUDE_STRINGS.add(" [Parallel Time");
EXCLUDE_STRINGS.add(" [GC Worker Start");
EXCLUDE_STRINGS.add(" [Ext Root Scanning");
EXCLUDE_STRINGS.add(" [SATB Filtering");
EXCLUDE_STRINGS.add(" [Update RS");
EXCLUDE_STRINGS.add(" [Processed Buffers");
EXCLUDE_STRINGS.add(" [Scan RS");
EXCLUDE_STRINGS.add(" [Code Root Scanning");
EXCLUDE_STRINGS.add(" [Object Copy");
EXCLUDE_STRINGS.add(" [Termination");
EXCLUDE_STRINGS.add(" [GC Worker");
EXCLUDE_STRINGS.add(" [Code Root");
EXCLUDE_STRINGS.add(" [Clear");
EXCLUDE_STRINGS.add(" [Other:");
EXCLUDE_STRINGS.add(" [Choose CSet");
EXCLUDE_STRINGS.add(" [Ref ");
EXCLUDE_STRINGS.add(" [Redirty Cards");
EXCLUDE_STRINGS.add(" [Humongous Reclaim");
EXCLUDE_STRINGS.add(" [Free CSet");
}

// the following pattern is specific for G1 with -XX:+PrintGCDetails
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/tagtraum/perf/gcviewer/model/GCModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,17 @@ private void adjustPause(VmOperationEvent vmOpEvent) {

// only count overhead of vmOpEvent, not whole pause,
// because it includes the previous stop the world event
vmOpEvent.setPause(vmOpEvent.getPause() - previousEvent.getPause());
adjustTimeStamp(previousEvent, vmOpEvent);

assert vmOpEvent.getPause() > 0 : "vmOpEvent at " + vmOpEvent.getTimestamp() + " should not have negative pause";
double adjustedPause = vmOpEvent.getPause() - previousEvent.getPause();
if (adjustedPause > 0) {
vmOpEvent.setPause(adjustedPause);
adjustTimeStamp(previousEvent, vmOpEvent);
}
else {
// this happens if the first VM_OPERATION event after a GCEvent could not be read (mixed with concurrent event)
// and the next is used to calculate the overhead
LOG.fine("vmOpEvent at " + vmOpEvent.getTimestamp()
+ " should not have negative pause -> no adjustment made");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class AboutDialog extends ScreenCenteredDialog implements ActionListener
"Samuel Mendenhall",
"Carl Meyer",
"Reinhard Nägele",
"Àngel Ollé Blázquez",
"Rupesh Ramachandran",
"Heiko W. Rupp",
"Stephan Schroevers",
Expand Down
115 changes: 94 additions & 21 deletions src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java
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;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/localStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ fileexport_dialog_csv_ts = Comma separated values with unix timestamp (*.csv)

fileexport_dialog_error_occured = An error occured.

fileexport_dialog_png = PNG Image (*.png)

fileexport_dialog_simplelog = Simple GC Log (GCHisto compatible, *.simple.log)

fileexport_dialog_summarylog = Summary GC Log (*.csv)
Expand Down
Loading

0 comments on commit d6ae8ca

Please sign in to comment.