Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for rotated logfiles has been added. This allows to open a series of consecutive logfiles and treat them as one (merged) gc log. This allows to analyze logfiles that have been created over a longer period in a production environment.
- Loading branch information
Showing
34 changed files
with
2,413 additions
and
255 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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/OpenSeries.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,66 @@ | |||
package com.tagtraum.perf.gcviewer.ctrl.action; | |||
|
|||
import com.tagtraum.perf.gcviewer.ctrl.GCModelLoaderController; | |||
import com.tagtraum.perf.gcviewer.model.GCResource; | |||
import com.tagtraum.perf.gcviewer.model.GcResourceFile; | |||
import com.tagtraum.perf.gcviewer.util.LocalisationHelper; | |||
import com.tagtraum.perf.gcviewer.view.ActionCommands; | |||
import com.tagtraum.perf.gcviewer.view.GCViewerGui; | |||
import com.tagtraum.perf.gcviewer.view.OpenFileView; | |||
import com.tagtraum.perf.gcviewer.view.util.ImageHelper; | |||
|
|||
import javax.swing.*; | |||
import java.awt.*; | |||
import java.awt.event.ActionEvent; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.logging.Logger; | |||
|
|||
/** | |||
* Allows to open a series of log files, treating them as a consecutive log. | |||
* | |||
* @author martin.geldmacher | |||
*/ | |||
public class OpenSeries extends AbstractAction { | |||
private static final Logger logger = Logger.getLogger(OpenSeries.class.getName()); | |||
|
|||
private GCModelLoaderController controller; | |||
private GCViewerGui gcViewer; | |||
private OpenFileView openFileView; | |||
|
|||
public OpenSeries(GCModelLoaderController controller, final GCViewerGui gcViewer) { | |||
this.controller = controller; | |||
this.gcViewer = gcViewer; | |||
|
|||
putValue(NAME, LocalisationHelper.getString("main_frame_menuitem_open_series")); | |||
putValue(SHORT_DESCRIPTION, LocalisationHelper.getString("main_frame_menuitem_hint_open_series")); | |||
putValue(MNEMONIC_KEY, Integer.valueOf(LocalisationHelper.getString("main_frame_menuitem_mnemonic_open_series").charAt(0))); | |||
putValue(ACTION_COMMAND_KEY, ActionCommands.OPEN_SERIES.toString()); | |||
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); | |||
putValue(SMALL_ICON, ImageHelper.loadImageIcon("open.png")); | |||
|
|||
openFileView = new OpenFileView(); | |||
} | |||
|
|||
@Override | |||
public void actionPerformed(ActionEvent e) { | |||
final int val = openFileView.showOpenDialog(gcViewer); | |||
if (val == JFileChooser.APPROVE_OPTION) { | |||
File[] selectedFiles = openFileView.getSelectedFiles(); | |||
List<GCResource> resources = getResources(selectedFiles); | |||
controller.openAsSeries(resources); | |||
} | |||
} | |||
|
|||
private List<GCResource> getResources(File[] selectedFiles) { | |||
if (selectedFiles == null || selectedFiles.length == 0) | |||
throw new IllegalArgumentException("At least one file must be selected!"); | |||
|
|||
java.util.List<GCResource> resources = new ArrayList<>(); | |||
for (File file : selectedFiles) { | |||
resources.add(new GcResourceFile(file)); | |||
} | |||
return resources; | |||
} | |||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/tagtraum/perf/gcviewer/ctrl/impl/AbstractGCModelLoaderImpl.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,62 @@ | |||
package com.tagtraum.perf.gcviewer.ctrl.impl; | |||
|
|||
import com.tagtraum.perf.gcviewer.ctrl.GCModelLoader; | |||
import com.tagtraum.perf.gcviewer.imp.DataReaderException; | |||
import com.tagtraum.perf.gcviewer.imp.MonitoredBufferedInputStream; | |||
import com.tagtraum.perf.gcviewer.model.GCModel; | |||
|
|||
import javax.swing.*; | |||
import java.beans.PropertyChangeEvent; | |||
import java.util.concurrent.ExecutionException; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
|
|||
/** | |||
* Base class for {@link GCModelLoader}s | |||
* | |||
* @author martin.geldmacher (refactored) | |||
*/ | |||
public abstract class AbstractGCModelLoaderImpl extends SwingWorker<GCModel, Object> implements GCModelLoader { | |||
@Override | |||
public void propertyChange(PropertyChangeEvent evt) { | |||
if (evt.getPropertyName() == MonitoredBufferedInputStream.PROGRESS) { | |||
setProgress((int) evt.getNewValue()); | |||
} | |||
} | |||
|
|||
protected void done() { | |||
Logger logger = getGcResource().getLogger(); | |||
|
|||
try { | |||
getGcResource().setModel(get()); | |||
// TODO delete | |||
getGcResource().getModel().printDetailedInformation(); | |||
} | |||
catch (InterruptedException e) { | |||
logger.log(Level.FINE, "model get() interrupted", e); | |||
} | |||
catch (ExecutionException | RuntimeException e) { | |||
if (logger.isLoggable(Level.WARNING)) | |||
logger.log(Level.WARNING, "Failed to create GCModel from " + getGcResource().getResourceName(), e); | |||
} | |||
} | |||
|
|||
@Override | |||
protected GCModel doInBackground() throws Exception { | |||
setProgress(0); | |||
final GCModel result; | |||
try { | |||
result = loadGcModel(); | |||
} | |||
catch (DataReaderException | RuntimeException e) { | |||
Logger logger = getGcResource().getLogger(); | |||
if (logger.isLoggable(Level.FINE)) { | |||
logger.log(Level.FINE, "Failed to load GCModel from " + getGcResource().getResourceName(), e); | |||
} | |||
throw e; | |||
} | |||
return result; | |||
} | |||
|
|||
protected abstract GCModel loadGcModel() throws DataReaderException; | |||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/tagtraum/perf/gcviewer/ctrl/impl/GCModelLoaderFactory.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
package com.tagtraum.perf.gcviewer.ctrl.impl; | |||
|
|||
import com.tagtraum.perf.gcviewer.ctrl.GCModelLoader; | |||
import com.tagtraum.perf.gcviewer.model.GCResource; | |||
import com.tagtraum.perf.gcviewer.model.GcResourceFile; | |||
import com.tagtraum.perf.gcviewer.model.GcResourceSeries; | |||
|
|||
/** | |||
* @author martin.geldmacher | |||
*/ | |||
public class GCModelLoaderFactory { | |||
/** | |||
* Creates an appropriate {@link GCModelLoader} for the given {@link GCResource} | |||
* | |||
* @param gcResource the {@link GCResource} | |||
* @return an appropriate {@link GCModelLoader} | |||
*/ | |||
public static GCModelLoader createFor(GCResource gcResource) { | |||
if (gcResource instanceof GcResourceFile) { | |||
return new GCModelLoaderImpl(gcResource); | |||
} | |||
else if (gcResource instanceof GcResourceSeries) { | |||
return new GCModelSeriesLoaderImpl((GcResourceSeries) gcResource); | |||
} | |||
else | |||
throw new IllegalArgumentException("Unknown GcResource: " + gcResource); | |||
} | |||
} |
75 changes: 15 additions & 60 deletions
75
src/main/java/com/tagtraum/perf/gcviewer/ctrl/impl/GCModelLoaderImpl.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,81 +1,36 @@ | |||
package com.tagtraum.perf.gcviewer.ctrl.impl; | package com.tagtraum.perf.gcviewer.ctrl.impl; | ||
|
|
||
import com.tagtraum.perf.gcviewer.ctrl.GCModelLoader; | |||
import com.tagtraum.perf.gcviewer.imp.DataReaderException; | import com.tagtraum.perf.gcviewer.imp.DataReaderException; | ||
import com.tagtraum.perf.gcviewer.imp.DataReaderFacade; | import com.tagtraum.perf.gcviewer.imp.DataReaderFacade; | ||
import com.tagtraum.perf.gcviewer.imp.MonitoredBufferedInputStream; | |||
import com.tagtraum.perf.gcviewer.model.GCModel; | import com.tagtraum.perf.gcviewer.model.GCModel; | ||
import com.tagtraum.perf.gcviewer.model.GCResource; | import com.tagtraum.perf.gcviewer.model.GCResource; | ||
|
|
||
import javax.swing.*; | |||
import java.beans.PropertyChangeEvent; | |||
import java.util.concurrent.ExecutionException; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
|
|||
/** | /** | ||
* Loads the model in a background thread (progress can be tracked by propertyChangeListeners). | * Loads the model in a background thread (progress can be tracked by propertyChangeListeners). | ||
* | * | ||
* @author Hans Bausewein | * @author Hans Bausewein | ||
* @author <a href="mailto:gcviewer@gmx.ch">Joerg Wuethrich</a> | * @author <a href="mailto:gcviewer@gmx.ch">Joerg Wuethrich</a> | ||
* <p>Date: November 8, 2013</p> | * <p>Date: November 8, 2013</p> | ||
*/ | */ | ||
public class GCModelLoaderImpl extends SwingWorker<GCModel, Object> implements GCModelLoader { | public class GCModelLoaderImpl extends AbstractGCModelLoaderImpl { | ||
|
private final DataReaderFacade dataReaderFacade; | ||
private final DataReaderFacade dataReaderFacade; | |||
private final GCResource gcResource; | private final GCResource gcResource; | ||
|
|||
public GCModelLoaderImpl(final GCResource gcResource) { | |||
super(); | |||
|
|||
this.gcResource = gcResource; | |||
this.dataReaderFacade = new DataReaderFacade(); | |||
this.dataReaderFacade.addPropertyChangeListener(this); // receive progress updates from loading | |||
} | |||
|
|||
@Override | |||
protected GCModel doInBackground() throws Exception { | |||
setProgress(0); | |||
final GCModel result; | |||
try { | |||
result = dataReaderFacade.loadModel(gcResource); | |||
} | |||
catch (DataReaderException | RuntimeException e) { | |||
Logger logger = gcResource.getLogger(); | |||
if (logger.isLoggable(Level.FINE)) { | |||
logger.log(Level.FINE, "Failed to load GCModel from " + gcResource.getResourceName(), e); | |||
} | |||
throw e; | |||
} | |||
return result; | |||
} | |||
|
|
||
protected void done() { | public GCModelLoaderImpl(final GCResource gcResource) { | ||
Logger logger = gcResource.getLogger(); | super(); | ||
|
|
||
try { | this.gcResource = gcResource; | ||
gcResource.setModel(get()); | this.dataReaderFacade = new DataReaderFacade(); | ||
// TODO delete | this.dataReaderFacade.addPropertyChangeListener(this); // receive progress updates from loading | ||
gcResource.getModel().printDetailedInformation(); | } | ||
} | |||
catch (InterruptedException e) { | |||
logger.log(Level.FINE, "model get() interrupted", e); | |||
} | |||
catch (ExecutionException | RuntimeException e) { | |||
if (logger.isLoggable(Level.WARNING)) | |||
logger.log(Level.WARNING, "Failed to create GCModel from " + gcResource.getResourceName(), e); | |||
} | |||
} | |||
|
|
||
@Override | @Override | ||
public GCResource getGcResource() { | protected GCModel loadGcModel() throws DataReaderException { | ||
return gcResource; | return dataReaderFacade.loadModel(gcResource); | ||
} | } | ||
|
|
||
@Override | @Override | ||
public void propertyChange(PropertyChangeEvent evt) { | public GCResource getGcResource() { | ||
if (evt.getPropertyName() == MonitoredBufferedInputStream.PROGRESS) { | return gcResource; | ||
setProgress((int)evt.getNewValue()); | |||
} | |||
} | } | ||
} | } |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/tagtraum/perf/gcviewer/ctrl/impl/GCModelSeriesLoaderImpl.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
package com.tagtraum.perf.gcviewer.ctrl.impl; | |||
|
|||
import com.tagtraum.perf.gcviewer.imp.DataReaderException; | |||
import com.tagtraum.perf.gcviewer.imp.DataReaderFacade; | |||
import com.tagtraum.perf.gcviewer.model.GCModel; | |||
import com.tagtraum.perf.gcviewer.model.GCResource; | |||
import com.tagtraum.perf.gcviewer.model.GcResourceSeries; | |||
|
|||
/** | |||
* An {@link AbstractGCModelLoaderImpl} that loads {@link GCResource}s as a series of logs | |||
* | |||
* @author gelder. | |||
*/ | |||
public class GCModelSeriesLoaderImpl extends AbstractGCModelLoaderImpl { | |||
private final DataReaderFacade dataReaderFacade; | |||
private final GcResourceSeries gcResourceSeries; | |||
|
|||
public GCModelSeriesLoaderImpl(GcResourceSeries gcResourceSeries) { | |||
this.dataReaderFacade = new DataReaderFacade(); | |||
this.dataReaderFacade.addPropertyChangeListener(this); // receive progress updates from loading | |||
this.gcResourceSeries = gcResourceSeries; | |||
} | |||
|
|||
@Override | |||
public GCResource getGcResource() { | |||
return gcResourceSeries; | |||
} | |||
|
|||
@Override | |||
protected GCModel loadGcModel() throws DataReaderException { | |||
return dataReaderFacade.loadModelFromSeries(gcResourceSeries); | |||
} | |||
} |
Oops, something went wrong.