Permalink
Browse files

Mostly finished profiling ouput viewer.

  • Loading branch information...
1 parent 5c688d9 commit f11626cebc96b4716f188711e943ea4aeed7d720 @serras serras committed Jul 21, 2011
@@ -8,7 +8,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.team.core,
org.eclipse.core.resources,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ org.eclipse.birt.chart.device.swt,
+ org.eclipse.birt.chart.ui
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %bundleVendor
@@ -0,0 +1,206 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Qi Liang (IBM Corporation)
+ *
+ * Modified as explained in
+ * http://www.eclipse.org/forums/index.php/mv/msg/171310/557779/#msg_557779
+*******************************************************************************/
+package net.sf.eclipsefp.haskell.profiler.internal.editors;
+
+import org.eclipse.birt.chart.device.IDeviceRenderer;
+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.model.Chart;
+import org.eclipse.birt.chart.model.attribute.Bounds;
+import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl;
+import org.eclipse.birt.chart.util.PluginSettings;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * The canvas to show chart.
+ *
+ * @author Qi Liang
+ */
+public class ChartCanvas extends Canvas {
+
+ /**
+ * The device render for rendering chart.
+ */
+ protected IDeviceRenderer render = null;
+
+ /**
+ * The chart instantce.
+ */
+ protected Chart chart = null;
+
+ /**
+ * The chart state.
+ */
+ protected GeneratedChartState state = null;
+
+ /**
+ * The image which caches the chart image to improve drawing performance.
+ */
+ private Image cachedImage = null;
+
+ /**
+ * Constructs one canvas containing chart.
+ *
+ * @param parent
+ * a composite control which will be the parent of the new
+ * instance (cannot be null)
+ * @param style
+ * the style of control to construct
+ */
+ public ChartCanvas(Composite parent, int style) {
+ super(parent, style);
+
+ // initialize the SWT rendering device
+ try {
+ PluginSettings ps = PluginSettings.instance();
+ render = ps.getDevice("dv.SWT");
+ } catch (ChartException ex) {
+ ex.printStackTrace();
+ }
+
+ addPaintListener(new PaintListener() {
+
+ public void paintControl(PaintEvent e) {
+
+ Composite co = (Composite) e.getSource();
+ final Rectangle rect = co.getClientArea();
+
+ render.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, e.gc);
+
+ if (cachedImage == null) {
+ buildChart();
+ drawToCachedImage(rect);
+ }
+ e.gc.drawImage(cachedImage,
+ 0,
+ 0,
+ cachedImage.getBounds().width,
+ cachedImage.getBounds().height,
+ 0,
+ 0,
+ rect.width,
+ rect.height);
+
+ }
+ });
+
+ addControlListener(new ControlAdapter() {
+
+ public void controlResized(ControlEvent e) {
+
+ render.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, new GC(ChartCanvas.this));
+ buildChart();
+ cachedImage = null;
+ }
+ });
+ }
+
+ /**
+ * Builds the chart state. This method should be call when data is changed.
+ */
+ private void buildChart() {
+ Point size = getSize();
+ Bounds bo = BoundsImpl.create(0, 0, size.x, size.y);
+ int resolution = render.getDisplayServer().getDpiResolution();
+ bo.scale(72d / resolution);
+ try {
+ Generator gr = Generator.instance();
+ state = gr.build(render.getDisplayServer(),
+ chart,
+ bo,
+ null,
+ null,
+ null);
+ } catch (ChartException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ * Draws the chart onto the cached image in the area of the given
+ * <code>Rectangle</code>.
+ *
+ * @param size
+ * the area to draw
+ */
+ public void drawToCachedImage(Rectangle size) {
+ GC gc = null;
+ try {
+ if (cachedImage != null)
+ cachedImage.dispose();
+ cachedImage = new Image(Display.getCurrent(), size.width,
+ size.height);
+
+ gc = new GC(cachedImage);
+ render.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, gc);
+
+ Generator gr = Generator.instance();
+
+ gr.render(render, state);
+ } catch (ChartException ex) {
+ ex.printStackTrace();
+ } finally {
+ if (gc != null)
+ gc.dispose();
+ }
+ }
+
+ /**
+ * Returns the chart which is contained in this canvas.
+ *
+ * @return the chart contained in this canvas.
+ */
+ public Chart getChart() {
+ return chart;
+ }
+
+ /**
+ * Sets the chart into this canvas. Note: When the chart is set, the cached
+ * image will be dopped, but this method doesn't reset the flag
+ * <code>cachedImage</code>.
+ *
+ * @param chart
+ * the chart to set
+ */
+ public void setChart(Chart chart) {
+ if (cachedImage != null)
+ cachedImage.dispose();
+
+ cachedImage = null;
+ this.chart = chart;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.widgets.Widget#dispose()
+ */
+ public void dispose() {
+ if (cachedImage != null)
+ cachedImage.dispose();
+ super.dispose();
+ }
+
+}
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Qi Liang (IBM Corporation)
+*******************************************************************************/
+package net.sf.eclipsefp.haskell.profiler.internal.editors;
+
+import org.eclipse.birt.chart.device.IDeviceRenderer;
+import org.eclipse.birt.chart.device.IUpdateNotifier;
+import org.eclipse.birt.chart.model.Chart;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * The canvas to draw chart with the tool tip to show the value.
+ *
+ * @author Qi Liang
+ */
+public class ChartWithToolTipCanvas extends ChartCanvas implements
+ IUpdateNotifier {
+
+ public ChartWithToolTipCanvas(Composite parent, int style) {
+ super(parent, style);
+ render.setProperty(IDeviceRenderer.UPDATE_NOTIFIER, this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#regenerateChart()
+ */
+ public void regenerateChart() {
+ redraw();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#repaintChart()
+ */
+ public void repaintChart() {
+ redraw();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#peerInstance()
+ */
+ public Object peerInstance() {
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#getDesignTimeModel()
+ */
+ public Chart getDesignTimeModel() {
+ return chart;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#getRunTimeModel()
+ */
+ public Chart getRunTimeModel() {
+ return state.getChartModel();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#getContext(java.lang.Object)
+ */
+ public Object getContext(Object arg0) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#putContext(java.lang.Object,
+ * java.lang.Object)
+ */
+ public Object putContext(Object arg0, Object arg1) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.birt.chart.device.IUpdateNotifier#removeContext(java.lang.Object)
+ */
+ public Object removeContext(Object arg0) {
+ return null;
+ }
+}
@@ -0,0 +1,49 @@
+package net.sf.eclipsefp.haskell.profiler.internal.editors;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.eclipsefp.haskell.profiler.model.Job;
+import net.sf.eclipsefp.haskell.profiler.model.Sample;
+
+public class ProfileNumbers {
+
+ private LinkedHashMap<String, double[]> entries;
+ private double[] rest;
+
+ public ProfileNumbers(List<Map.Entry<String, BigInteger>> entriesApart, int noSamples) {
+ this.entries = new LinkedHashMap<String, double[]>();
+ for (Map.Entry<String, BigInteger> e : entriesApart) {
+ double[] values = new double[noSamples];
+ Arrays.fill(values, 0.0);
+ entries.put(e.getKey(), values);
+ }
+ this.rest = new double[noSamples];
+ Arrays.fill(this.rest, 0.0);
+ }
+
+ public void fillIn(Job job) {
+ int sampleNo = 0;
+ for (Sample s : job.getSamples()) {
+ for (Map.Entry<String, Long> e : s.getEntries()) {
+ if (entries.containsKey(e.getKey())) {
+ entries.get(e.getKey())[sampleNo] = e.getValue();
+ } else {
+ rest[sampleNo] += e.getValue();
+ }
+ }
+ sampleNo++;
+ }
+ }
+
+ public LinkedHashMap<String, double[]> getEntries() {
+ return entries;
+ }
+
+ public double[] getRest() {
+ return rest;
+ }
+}
Oops, something went wrong.

0 comments on commit f11626c

Please sign in to comment.