Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2011-12-16 16:25:57 -0500
committerRoland Grunberg2011-12-20 13:36:44 -0500
commit17cb3b872638d898e7a32228793463da5fc63115 (patch)
treec6a34be7ee284a2e266be9dde4ce27ac0a2fc302 /valgrind
parent572b52cea19d3936d0cce41265d3216d8f2ea9c4 (diff)
downloadorg.eclipse.linuxtools-17cb3b872638d898e7a32228793463da5fc63115.tar.gz
org.eclipse.linuxtools-17cb3b872638d898e7a32228793463da5fc63115.tar.xz
org.eclipse.linuxtools-17cb3b872638d898e7a32228793463da5fc63115.zip
Implement exporting heap chart to PNG format.
Diffstat (limited to 'valgrind')
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java6
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java11
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartEditor.java15
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartSVG.java93
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/HeapChart.java10
5 files changed, 37 insertions, 98 deletions
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java
index a370a4fbcf..6404d7bb24 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartExportTest.java
@@ -12,12 +12,12 @@ package org.eclipse.linuxtools.internal.valgrind.massif.tests;
import java.io.File;
-import org.eclipse.birt.chart.model.Chart;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.linuxtools.internal.valgrind.massif.birt.ChartEditorInput;
import org.eclipse.linuxtools.internal.valgrind.massif.birt.ChartSVG;
+import org.eclipse.linuxtools.internal.valgrind.massif.birt.HeapChart;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI;
@@ -50,9 +50,9 @@ public class ChartExportTest extends AbstractMassifTest {
IEditorInput input = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();
if (input instanceof ChartEditorInput) {
- Chart chart = ((ChartEditorInput) input).getChart();
+ HeapChart chart = ((ChartEditorInput) input).getChart();
- ChartSVG svg = new ChartSVG(chart, ((ChartEditorInput) input).getView());
+ ChartSVG svg = new ChartSVG(chart);
svg.renderSVG(svgPath);
File chartFile = svgPath.toFile();
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java
index 9445a38120..bfa980a2a8 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/MassifViewPart.java
@@ -248,13 +248,10 @@ public class MassifViewPart extends ViewPart implements IValgrindToolView {
@Override
public void run() {
ChartEditorInput currentInput = getChartInput(pid);
- String path = getChartSavePath(currentInput.getName() + ".svg"); //$NON-NLS-1$
+ String path = getChartSavePath(currentInput.getName() + ".png"); //$NON-NLS-1$
if (path != null) {
- /**
- * TODO : Implement this
- */
-// ChartSVG renderer = new ChartSVG(currentInput.getChart(), MassifViewPart.this);
-// renderer.renderSVG(Path.fromOSString(path));
+ ChartSVG renderer = new ChartSVG(currentInput.getChart());
+ renderer.renderSVG(Path.fromOSString(path));
}
}
};
@@ -290,7 +287,7 @@ public class MassifViewPart extends ViewPart implements IValgrindToolView {
FileDialog dialog = new FileDialog(parent, SWT.SAVE);
dialog.setText(Messages.getString("MassifViewPart.Save_chart_dialog_title")); //$NON-NLS-1$
dialog.setOverwrite(true);
- dialog.setFilterExtensions(new String[] { ".svg" }); //$NON-NLS-1$
+ dialog.setFilterExtensions(new String[] { ".png" }); //$NON-NLS-1$
dialog.setFileName(defaultName);
return dialog.open();
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartEditor.java b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartEditor.java
index e408219b4f..51ac9c24ba 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartEditor.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartEditor.java
@@ -24,10 +24,6 @@ import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
@@ -43,7 +39,6 @@ import org.swtchart.IAxisSet;
import org.swtchart.ILineSeries;
import org.swtchart.ILineSeries.PlotSymbolType;
import org.swtchart.ISeries.SeriesType;
-import org.swtchart.IAxis;
import org.swtchart.ITitle;
import org.swtchart.LineStyle;
import org.swtchart.Range;
@@ -87,6 +82,7 @@ public class ChartEditor extends EditorPart {
final ChartEditorInput input = (ChartEditorInput) getEditorInput();
final HeapChart heapChart = input.getChart();
control = new Chart(parent, SWT.FILL);
+ heapChart.setChartControl(control);
final Color LIGHTYELLOW = new Color(Display.getDefault(), 255, 255, 225);
final Color WHITE = new Color(Display.getDefault(), 255, 255, 255);
@@ -226,15 +222,6 @@ public class ChartEditor extends EditorPart {
});
- /*Display dsp = Display.getCurrent();
- GC gc = new GC(control);
- Image img = new Image(dsp, 640, 480);
- gc.copyArea(img, 0, 0);
- gc.dispose();
- ImageLoader imageLoader = new ImageLoader();
- imageLoader.data = new ImageData[] {img.getImageData()};
- imageLoader.save("/home/rgrunber/Desktop/test.jpg",SWT.IMAGE_JPEG);*/
-
}
public Chart getControl() {
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartSVG.java b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartSVG.java
index f52d3fbbe6..22f71a84ad 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartSVG.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/ChartSVG.java
@@ -11,99 +11,44 @@
***********************************************************************/
package org.eclipse.linuxtools.internal.valgrind.massif.birt;
-import org.eclipse.birt.chart.computation.DataPointHints;
-import org.eclipse.birt.chart.device.ICallBackNotifier;
-import org.eclipse.birt.chart.device.IDeviceRenderer;
-import org.eclipse.birt.chart.event.WrappedStructureSource;
-import org.eclipse.birt.chart.exception.ChartException;
-import org.eclipse.birt.chart.factory.GeneratedChartState;
-import org.eclipse.birt.chart.factory.Generator;
-import org.eclipse.birt.chart.factory.RunTimeContext;
-import org.eclipse.birt.chart.model.Chart;
-import org.eclipse.birt.chart.model.attribute.Bounds;
-import org.eclipse.birt.chart.model.attribute.CallBackValue;
-import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
-import org.eclipse.birt.chart.util.PluginSettings;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifViewPart;
import org.eclipse.linuxtools.valgrind.ui.ValgrindUIConstants;
-import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
-public class ChartSVG implements ICallBackNotifier {
+public class ChartSVG {
- protected Chart cm = null;
- protected GeneratedChartState state = null;
- protected IDeviceRenderer deviceRenderer = null;
+ protected HeapChart cm = null;
- private MassifViewPart view;
-
- public ChartSVG(Chart chart, MassifViewPart view) {
- this.view = view;
+ public ChartSVG(HeapChart chart) {
cm = chart;
}
public void renderSVG(IPath svgPath) {
- try {
- RunTimeContext rtc = new RunTimeContext();
-
- deviceRenderer = PluginSettings.instance().getDevice("dv.SVG"); //$NON-NLS-1$
- Generator gr = Generator.instance();
- Bounds bo = BoundsImpl.create(0, 0, 800, 600);
- state = gr.build(deviceRenderer.getDisplayServer(), cm, bo, null,
- rtc, null);
- deviceRenderer.setProperty(IDeviceRenderer.FILE_IDENTIFIER, svgPath
- .toOSString());
- deviceRenderer.setProperty(IDeviceRenderer.UPDATE_NOTIFIER, this);
-
- gr.render(deviceRenderer, state);
- } catch (ChartException e) {
- e.printStackTrace();
- }
- }
-
- public void callback(Object event, Object source, CallBackValue value) {
- // give Valgrind view focus
- showView();
- MouseEvent mEvent = (MouseEvent) event;
-
- DataPointHints point = ((DataPointHints)((WrappedStructureSource)source).getSource());
- // select the corresponding snapshot in the TableViewer
- TableViewer viewer = view.getTableViewer();
- view.setTopControl(viewer.getControl());
-
- MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(point.getIndex());
-
- switch (mEvent.count) {
- case 1: // single click
- viewer.setSelection(new StructuredSelection(snapshot));
- break;
- case 2: // double click
-// if (snapshot.isDetailed()) {
-// ChartLocationsDialog dialog = new ChartLocationsDialog(getShell());
-// dialog.setInput(snapshot);
-//
-// if (dialog.open() == Window.OK) {
-// dialog.openEditorForResult();
-// }
-// }
- }
+ Composite comp = cm.getChartControl();
+ Display dsp = Display.getCurrent();
+ GC gc = new GC(comp);
+ Image img = new Image(dsp, comp.getSize().x, comp.getSize().y);
+ gc.copyArea(img, 0, 0);
+ gc.dispose();
+ ImageLoader imageLoader = new ImageLoader();
+ imageLoader.data = new ImageData[] {img.getImageData()};
+ imageLoader.save(svgPath.toOSString(), SWT.IMAGE_PNG);
}
- public Chart getDesignTimeModel() {
+ public HeapChart getDesignTimeModel() {
return cm;
}
- public Chart getRunTimeModel() {
- return state.getChartModel();
- }
-
public Object peerInstance() {
return this;
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/HeapChart.java b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/HeapChart.java
index 1e49a5e676..1e5639f67b 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/HeapChart.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif/src/org/eclipse/linuxtools/internal/valgrind/massif/birt/HeapChart.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.valgrind.massif.birt;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot.TimeUnit;
+import org.eclipse.swt.widgets.Composite;
public class HeapChart {
@@ -45,6 +46,7 @@ public class HeapChart {
protected String xUnits;
protected String yUnits;
public double [] time, dataUseful, dataExtra, dataStacks, dataTotal;
+ private Composite chartControl;
public HeapChart(MassifSnapshot[] snapshots, String title) {
TimeUnit timeUnit = snapshots[0].getUnit();
@@ -165,4 +167,12 @@ public class HeapChart {
return secondUnits;
}
+ public void setChartControl(Composite control) {
+ chartControl = control;
+ }
+
+ public Composite getChartControl (){
+ return chartControl;
+ }
+
}

Back to the top