Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 331467 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/AbstractView.java (+313 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency;
13
14
import org.eclipse.linuxtools.lttng.ui.views.latency.handlers.ViewHandler;
15
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractMouseListener;
16
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.AbstractPaintListener;
17
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.ZoomListener;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWTException;
20
import org.eclipse.swt.widgets.Canvas;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Display;
23
24
25
/**
26
 * Abstract view.
27
 * 
28
 * @author Philippe Sawicki
29
 */
30
public abstract class AbstractView extends Canvas {
31
	
32
	/**
33
	 * Parent composite node.
34
	 */
35
	protected Composite parent_;
36
37
	/**
38
	 * View handler (retrieves the information).
39
	 */
40
	protected ViewHandler viewHandler_ = null;
41
	
42
	/**
43
	 * Horizontal axis min value.
44
	 */
45
	protected long xMin_;
46
	/**
47
	 * Horizontal axis max value.
48
	 */
49
	protected long xMax_;
50
	/**
51
	 * Vertical axis min value.
52
	 */
53
	protected long yMin_;
54
	/**
55
	 * Vertical axis max value.
56
	 */
57
	protected long yMax_;
58
	
59
	/**
60
	 * Paint listener.
61
	 */
62
	protected AbstractPaintListener paintListener_;
63
	
64
	/**
65
	 * Zoom listener, to zoom in and out of a graph using the scroll wheel.
66
	 */
67
	protected ZoomListener zoomListener_;
68
	
69
	/**
70
	 * Tooltip listener.
71
	 */
72
	protected AbstractMouseListener mouseListener_;
73
	
74
	
75
	/**
76
	 * Constructor.
77
	 * @param parent The parent composite node.
78
	 * @param style The SWT style to use to render the view.
79
	 */
80
	public AbstractView(Composite parent, int style) {
81
		super(parent, style);
82
		
83
		parent_ = parent;
84
	}
85
	
86
	/**
87
	 * Sets the min value of the horizontal axis.
88
	 * @param xMin The min value of the horizontal axis.
89
	 */
90
	public void setXMin(long xMin) {
91
		xMin_ = xMin;
92
	}
93
	
94
	/**
95
	 * Returns the min value of the horizontal axis.
96
	 * @return The min value of the horizontal axis.
97
	 */
98
	public long getXMin() {
99
		return xMin_;
100
	}
101
	
102
	/**
103
	 * Sets the max value of the horizontal axis.
104
	 * @param xMax The max value of the horizontal axis.
105
	 */
106
	public void setXMax(long xMax) {
107
		xMax_ = xMax;
108
	}
109
	
110
	/**
111
	 * Returns the max value of the horizontal axis.
112
	 * @return The max value of the horizontal axis.
113
	 */
114
	public long getXMax() {
115
		return xMax_;
116
	}
117
	
118
	/**
119
	 * Sets the min value of the vertical axis.
120
	 * @param yMin The min value of the vertical axis.
121
	 */
122
	public void setYMin(long yMin) {
123
		yMin_ = yMin;
124
	}
125
	/**
126
	 * Returns the min value of the vertical axis.
127
	 * @return The min value of the vertical axis.
128
	 */
129
	public long getYMin() {
130
		return yMin_;
131
	}
132
	
133
	/**
134
	 * Sets the max value of the vertical axis.
135
	 * @param yMax The max value of the vertical axis.
136
	 */
137
	public void setYMax(long yMax) {
138
		yMax_ = yMax;
139
	}
140
	/**
141
	 * Returns the max value of the vertical axis.
142
	 * @return The max value of the vertical axis.
143
	 */
144
	public long getYMax() {
145
		return yMax_;
146
	}
147
148
	/**
149
	 * Adds a point to the view.
150
	 * @param point The point to add to the view.
151
	 */
152
	public abstract void addPoint(int point);
153
	
154
	/**
155
	 * Adds a buffer of points to the view.
156
	 * @param points The buffer of points to add to the view.
157
	 * @param nbPoints The number of points in the buffer.
158
	 */
159
	public abstract void addPoints(ChartPoint[] points, int nbPoints);
160
	
161
	/**
162
	 * Clears the view.
163
	 */
164
	public abstract void clear();
165
	
166
	/**
167
	 * Clears the background of the view but keeps min and max values.
168
	 */
169
	public abstract void clearBackground();
170
	
171
	/**
172
	 * Clears the points buffer, if any exists.
173
	 */
174
	public void clearPoints() {
175
		paintListener_.clearPoints();
176
	}
177
	
178
	/**
179
	 * Sets the view handler.
180
	 * @param viewHandler The view handler.
181
	 */
182
	public void setViewHandler(ViewHandler viewHandler) {
183
		viewHandler_ = viewHandler;
184
	}
185
	
186
	/**
187
	 * Draw horizontal label each "nbTicks" ticks.
188
	 * @param nbTicks The draw interval.
189
	 */
190
	public void drawLabelEachNTicks(int nbTicks) {
191
		paintListener_.drawLabelEachNTicks(nbTicks);
192
	}
193
	
194
	/**
195
	 * Sets the title of the graph.
196
	 * @param graphTitle The title of the graph.
197
	 */
198
	public void setGraphTitle(String graphTitle) {
199
		paintListener_.setGraphTitle(graphTitle);
200
	}
201
	
202
	/**
203
	 * Sets the horizontal axis label.
204
	 * @param xLabel The horizontal axis label.
205
	 * @param offset The horizontal axis draw offset (in pixels).
206
	 */
207
	public void setXAxisLabel(String xLabel, int offset) {
208
		paintListener_.setXAxisLabel(xLabel, offset);
209
	}
210
211
	/**
212
	 * Sets the vertical axis label.
213
	 * @param yLabel The vertical axis label.
214
	 */
215
	public void setYAxisLabel(String yLabel) {
216
		paintListener_.setYAxisLabel(yLabel);
217
	}
218
	
219
	/**
220
	 * Asks for the view to be redrawn, synchronously or asynchronously.
221
	 * @param asyncRedraw If "true", the view will be redrawn asynchronously, otherwise it will be 
222
	 * redraw synchronously.
223
	 */
224
	public void askForRedraw(boolean asyncRedraw) {
225
		if (asyncRedraw == true) {
226
			Display.getDefault().asyncExec(new Runnable() {
227
				public void run() {
228
					try {
229
						redraw();
230
					} catch (SWTException e) {
231
						// ...
232
					}
233
				}
234
			});
235
		} else {
236
			Display.getDefault().syncExec(new Runnable() {
237
				public void run() {
238
					try {
239
						redraw();
240
					} catch (SWTException e) {
241
						// ...
242
					}
243
				}
244
			});
245
		}
246
	}
247
	
248
	/**
249
	 * Asks for the view to be redrawn (asynchronously).
250
	 */
251
	public void askForRedraw() {
252
		askForRedraw(true);
253
	}
254
	
255
	/**
256
	 * Returns the zoom factor for the canvas.
257
	 * @return The zoom factor for the canvas.
258
	 */
259
	public int getZoomFactor() {
260
		if (zoomListener_ != null) {
261
			return zoomListener_.getZoomFactor();
262
		} else {
263
			return 1;
264
		}
265
	}
266
267
	/**
268
	 * Returns the zoom increment for the canvas.
269
	 * @return The zoom increment for the canvas.
270
	 */
271
	public int getZoomIncrement() {
272
		if (zoomListener_ != null) {
273
			return zoomListener_.getZoomIncrement();
274
		} else {
275
			return 1;
276
		}
277
	}
278
	
279
	/**
280
	 * Redraws the title after a zoom to display the new zoom factor.
281
	 */
282
	public void redrawTitle() {
283
		paintListener_.paintGraphTitle();
284
	}
285
	
286
	/**
287
	 * Removes the view's listeners before disposing of it.
288
	 */
289
	public void dispose() {
290
		try {
291
			if (paintListener_ != null) {
292
				removePaintListener(paintListener_);
293
				paintListener_ = null;
294
			} 
295
			if (zoomListener_ != null) {
296
				removeListener(SWT.MouseWheel, zoomListener_);
297
				zoomListener_ = null;
298
			}
299
			if (mouseListener_ != null) {
300
				removeListener(SWT.MouseMove, mouseListener_);
301
				mouseListener_ = null;
302
			}
303
		} catch (SWTException e) {
304
    		// This exception will be thrown if the user closes the view
305
    		// while it is receiving data from the Analyser.
306
    		
307
    		// ...
308
		}
309
		
310
		super.dispose();
311
	}
312
313
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/ChartPoint.java (+80 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency;
13
14
15
/**
16
 * Class holding data values to later draw points/bars to the screen.
17
 * 
18
 * @author Philippe Sawicki
19
 */
20
public class ChartPoint {
21
	
22
	/**
23
	 * Point x-value.
24
	 */
25
	private long x_;
26
	/**
27
	 * Point y-value.
28
	 */
29
	private long y_;
30
	
31
	
32
	/**
33
	 * Constructor.
34
	 * @param x The point's x-value.
35
	 * @param y The point's y-value.
36
	 */
37
	public ChartPoint(long x, long y) {
38
		x_ = x;
39
		y_ = y;
40
	}
41
	
42
	/**
43
	 * Constructor.
44
	 */
45
	public ChartPoint() {
46
		this(0L, 0L);
47
	}
48
	
49
	/**
50
	 * Sets the point's x-value.
51
	 * @param x The point's x-value.
52
	 */
53
	public void setX(long x) {
54
		x_ = x;
55
	}
56
	
57
	/**
58
	 * Returns the point's x-value.
59
	 * @return The point's x-value.
60
	 */
61
	public long getX() {
62
		return x_;
63
	}
64
	
65
	/**
66
	 * Sets the point's y-value.
67
	 * @param y The point's y-value.
68
	 */
69
	public void setY(long y) {
70
		y_ = y;
71
	}
72
	
73
	/**
74
	 * Returns the point's y-value.
75
	 * @return The point's y-value.
76
	 */
77
	public long getY() {
78
		return y_;
79
	}
80
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/GraphView.java (+74 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency;
13
14
import org.eclipse.linuxtools.lttng.analysis.Config;
15
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.GraphPaintListener;
16
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.TimePointerListener;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Composite;
19
20
21
/**
22
 * Graph view.
23
 * 
24
 * @author Philippe Sawicki
25
 */
26
public class GraphView extends AbstractView {
27
28
	/**
29
	 * Constructor.
30
	 * @param parent The parent composite node.
31
	 * @param style The SWT style to use to render the view.
32
	 */
33
	public GraphView(Composite parent, int style) {
34
		super(parent, style);
35
		
36
		// Register the paint listener
37
		paintListener_ = new GraphPaintListener(this);
38
		addPaintListener(paintListener_);
39
		
40
		// Register the mouse click listener
41
		mouseListener_ = new TimePointerListener(this, (GraphPaintListener)paintListener_);
42
		addListener(SWT.MouseMove, mouseListener_); 
43
	}
44
45
	@Override
46
	public void addPoint(int point) {
47
		if (Config.PRINT_GRAPH_VIEW_STATUS)
48
			System.out.println("GRAPH : ADDING 1 POINT");
49
	}
50
	
51
	@Override
52
	public void addPoints(ChartPoint[] points, int nbPoints) {
53
		if (Config.PRINT_GRAPH_VIEW_STATUS)
54
			System.out.println("GRAPH : ADDING " + nbPoints + " POINTS");
55
		paintListener_.addPoints(points, nbPoints);
56
	}
57
58
	@Override
59
	public void clear() {
60
		xMin_ = 0L;
61
		xMax_ = 0L;
62
		
63
		yMin_ = 0L;
64
		yMax_ = 0L;
65
		
66
		paintListener_.clear();
67
	}
68
	
69
	@Override
70
	public void clearBackground() {
71
		paintListener_.clear();
72
	}
73
74
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/HistogramView.java (+114 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency;
13
14
import org.eclipse.linuxtools.lttng.analysis.Config;
15
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.HistogramPaintListener;
16
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.TooltipListener;
17
import org.eclipse.linuxtools.lttng.ui.views.latency.listeners.ZoomListener;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Composite;
20
21
22
/**
23
 * Histogram view.
24
 * 
25
 * @author Philippe Sawicki
26
 */
27
public class HistogramView extends AbstractView {
28
	
29
	/**
30
	 * Usable width for data plotting.
31
	 */
32
	protected int usableWidth_;
33
	
34
	/**
35
	 * Standard latencies table.
36
	 */
37
	protected double[] standardLatencies_;
38
	
39
40
	/**
41
	 * Constructor.
42
	 * @param parent The parent composite node.
43
	 * @param style The SWT style to use to render the view.
44
	 */
45
	public HistogramView(Composite parent, int style) {
46
		super(parent, style);
47
		
48
		// Register the paint listener
49
		paintListener_ = new HistogramPaintListener(this);
50
		addPaintListener(paintListener_);
51
		
52
		// Register the zoom listener
53
		zoomListener_ = new ZoomListener(this);
54
		addListener(SWT.MouseWheel, zoomListener_);
55
		
56
		// Register the mouse click listener
57
		mouseListener_ = new TooltipListener(this, (HistogramPaintListener)paintListener_);
58
		addListener(SWT.MouseMove, mouseListener_); 
59
	}
60
61
	@Override
62
	public void addPoint(int point) {
63
		if (Config.PRINT_HISTO_VIEW_STATUS)
64
			System.out.println("HISTOGRAM : ADDING 1 POINT");
65
	}
66
	
67
	@Override
68
	public void addPoints(ChartPoint[] points, int nbPoints) {
69
		if (Config.PRINT_HISTO_VIEW_STATUS)
70
			System.out.println("HISTOGRAM : ADDING " + nbPoints + " POINTS");
71
		paintListener_.addPoints(points, nbPoints);
72
	}
73
74
	@Override
75
	public void clear() {
76
		xMin_ = 0L;
77
		xMax_ = 0L;
78
		
79
		yMin_ = 0L;
80
		yMax_ = 0L;
81
82
		paintListener_.clear();
83
	}
84
	
85
	@Override
86
	public void clearBackground() {
87
		paintListener_.clear();
88
	}
89
	
90
	/**
91
	 * Returns the number of bars available.
92
	 * @return The number of bars available.
93
	 */
94
	public int getNumberOfBars() {
95
		usableWidth_ = getClientArea().width - 2*Config.GRAPH_PADDING;
96
		return usableWidth_ / Config.HISTOGRAM_BAR_WIDTH;
97
	}
98
	
99
	/**
100
	 * Notify the view handler of the number of bars available.
101
	 */
102
	public void notifyNumberOfBars() {
103
		viewHandler_.notifyNumberOfBars( getNumberOfBars() );
104
	}
105
	
106
	/**
107
	 * Sets the standard latencies table.
108
	 * @param standardLatencies The standard latencies table.
109
	 */
110
	public void setStandardLatencies(double[] standardLatencies) {
111
		standardLatencies_ = standardLatencies;
112
	}
113
114
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/LatencyView.java (+502 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency;
13
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.IToolBarManager;
17
import org.eclipse.jface.action.Separator;
18
import org.eclipse.linuxtools.lttng.analysis.Config;
19
import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator;
20
import org.eclipse.linuxtools.lttng.event.LttngEvent;
21
import org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.AddDialog;
22
import org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.DeleteDialog;
23
import org.eclipse.linuxtools.lttng.ui.views.latency.dialogs.ListDialog;
24
import org.eclipse.linuxtools.tmf.event.TmfEvent;
25
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
26
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
27
import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
28
import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal;
29
import org.eclipse.linuxtools.tmf.signal.TmfRangeSynchSignal;
30
import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
31
import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal;
32
import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
33
import org.eclipse.linuxtools.tmf.trace.TmfContext;
34
import org.eclipse.linuxtools.tmf.ui.views.TmfView;
35
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.events.ControlEvent;
37
import org.eclipse.swt.events.ControlListener;
38
import org.eclipse.swt.layout.FillLayout;
39
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Display;
41
import org.eclipse.ui.IActionBars;
42
import org.eclipse.ui.plugin.AbstractUIPlugin;
43
44
45
/**
46
 * TmfView displaying the latency views (i.e. the two latency charts).
47
 * 
48
 * @author Philippe Sawicki
49
 */
50
public class LatencyView extends TmfView {
51
52
	/**
53
	 * The view's unique ID.
54
	 */
55
    public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView";
56
    
57
    /**
58
     * A reference to the currently selected experiment.
59
     */
60
    protected static TmfExperiment<LttngEvent> experiment_ = null;
61
    
62
    /**
63
     * Parent composite.
64
     */
65
    protected static Composite parent_;
66
    
67
    /**
68
     * Graph view.
69
     */
70
    protected GraphView graphView_;
71
    /**
72
     * Histogram view.
73
     */
74
    protected HistogramView histogramView_;
75
    
76
    /**
77
     * Action executed when the user wants to see the list of matching events.
78
     */
79
    protected Action listMatchingEvents_;
80
    /**
81
     * Action executed when the user wants to add matching events.
82
     */
83
    protected Action addMatchingEvents_;
84
    /**
85
     * Action executed when the user wants to delete matching events.
86
     */
87
    protected Action deleteMatchingEvents_;
88
    /**
89
     * Action executed when the user wants to increase the width of the histogram bars.
90
     */
91
    protected Action increaseBarWidth_;
92
    /**
93
     * Action executed when the user wants to decrease the width of the histogram bars.
94
     */
95
    protected Action decreaseBarWidth_;
96
    
97
    /**
98
     * The current histogram window time range.
99
     */
100
    protected static TmfTimeRange timeRange_ = null;
101
    
102
    /**
103
     * A reference to the last TmfRangeSynchSignal recorded.
104
     */
105
    protected static TmfRangeSynchSignal rangeSyncSignal_;
106
    /**
107
     * A reference to the last TmfExperimentSelectedSignal<TmfEvent> recorded.
108
     */
109
    protected TmfExperimentSelectedSignal<TmfEvent> experimentSelectedSignal_;
110
    
111
    
112
    
113
    /**
114
     * Constructor.
115
     */
116
    public LatencyView() {
117
    	super("LatencyView");
118
    }
119
    
120
	/**
121
	 * Create the UI controls of this view.
122
	 * 
123
	 * @param parent The composite parent of this view.
124
	 */
125
	@Override
126
	public void createPartControl(Composite parent) {
127
		// Save the parent
128
		parent_ = parent;
129
		
130
		makeActions();
131
		contributeToActionBars();
132
		
133
		// Add a control listener to handle the view resize events (to redraw the canvas)
134
		parent_.addControlListener(new ControlListener() {
135
			@Override
136
			public void controlMoved(ControlEvent event) {
137
				resendSignalsIfNeeded();
138
			}
139
140
			@Override
141
			public void controlResized(ControlEvent event) {
142
				resendSignalsIfNeeded();
143
			}
144
			
145
			/**
146
			 * Resend trace signals if the resize or the move forced the views
147
			 * to be cleared, so that after the view is resized/moved, the events
148
			 * from the trace start being plotted.
149
			 */
150
			protected void resendSignalsIfNeeded() {
151
				if (rangeSyncSignal_ != null) {
152
					synchToTimeRange(rangeSyncSignal_);
153
				} else if (experimentSelectedSignal_ != null) { 
154
					experimentSelected(experimentSelectedSignal_);
155
				} else {
156
					graphView_.clear();
157
					histogramView_.clear();
158
				}
159
			}
160
		});
161
		
162
		
163
		
164
		/////////////////////////////////////////////////////////////////////////////////////
165
		// Layout for the whole view, other elements will be in a child composite of this one 
166
		// Contains :
167
		// 		Composite layoutSelectionWindow
168
		//		Composite layoutTimesSpinner
169
		//		Composite layoutExperimentHistogram
170
		/////////////////////////////////////////////////////////////////////////////////////
171
		Composite layoutFullView = new Composite(parent_, SWT.FILL);
172
		FillLayout gridFullView = new FillLayout();
173
		gridFullView.marginHeight = 0;
174
		gridFullView.marginWidth = 0;
175
		layoutFullView.setLayout(gridFullView);
176
    	
177
    	// Create the graph views
178
    	graphView_ = new GraphView(layoutFullView, SWT.DOUBLE_BUFFERED);
179
    	graphView_.drawLabelEachNTicks(2);
180
    	graphView_.setGraphTitle(Messages.getString("LatencyView.Graphs.Graph.Title"));
181
    	graphView_.setXAxisLabel(Messages.getString("LatencyView.Graphs.Graph.XAxisLabel"), 40);
182
    	graphView_.setYAxisLabel(Messages.getString("LatencyView.Graphs.Graph.YAxisLabel"));
183
    	
184
    	histogramView_ = new HistogramView(layoutFullView, SWT.DOUBLE_BUFFERED);
185
    	histogramView_.setGraphTitle(Messages.getString("LatencyView.Graphs.Histogram.Title"));
186
    	histogramView_.setXAxisLabel(Messages.getString("LatencyView.Graphs.Histogram.XAxisLabel"), 55);
187
    	histogramView_.setYAxisLabel(Messages.getString("LatencyView.Graphs.Histogram.YAxisLabel"));
188
    	
189
    	// Register the graph views to the InterfaceMediator
190
    	InterfaceMediator.getInstance().registerGraphView(graphView_);
191
    	InterfaceMediator.getInstance().registerHistogramView(histogramView_);
192
	}
193
	
194
    @Override
195
	public String toString() {
196
    	return "[LatencyView]";
197
    }
198
    
199
    /**
200
     * Returns the currently selected experiment.
201
     * @return The currently selected experiment.
202
     */
203
    public static TmfExperiment<LttngEvent> getExperiment() {
204
    	return (TmfExperiment<LttngEvent>) experiment_;
205
    }
206
    
207
208
    // ------------------------------------------------------------------------
209
    // Signal handlers
210
	// ------------------------------------------------------------------------
211
    
212
	@SuppressWarnings("unchecked")
213
    @TmfSignalHandler
214
    public void experimentSelected(TmfExperimentSelectedSignal<TmfEvent> signal) {
215
		experimentSelectedSignal_ = signal;
216
		
217
		// Clear the views
218
		graphView_.clear();
219
		histogramView_.clear();
220
		
221
    	histogramView_.notifyNumberOfBars();
222
    	
223
		if (parent_ != null) {
224
	        // Update the trace reference
225
			experiment_ = (TmfExperiment<LttngEvent>) experimentSelectedSignal_.getExperiment();
226
			
227
			sendAnalysisRequest();
228
		}
229
    }
230
	
231
	/**
232
	 * Ask the analyser to compute the latencies for the current experiment.
233
	 */
234
	public static void sendAnalysisRequest() {
235
		if (parent_ != null) {
236
			Display display = parent_.getDisplay();
237
			display.asyncExec(new Runnable() {
238
				public void run() {
239
					new Thread() {
240
						public void run() {
241
							try {
242
								TmfTimestamp startTime = getExperimentTimeRange().getStartTime();
243
								TmfTimestamp endTime   = new TmfTimestamp(startTime.getValue() + org.eclipse.linuxtools.lttng.ui.views.histogram.HistogramView.getDEFAULT_WINDOW_SIZE());
244
								timeRange_ = new TmfTimeRange(startTime, endTime);
245
								
246
						        InterfaceMediator.getInstance().analyseLatencyForAllEvents();
247
							} catch (NullPointerException e) {
248
								// Thrown when the user has not selected an experiment yet but reset the latency pairs to 
249
								// default in the dialog.
250
							}
251
						}
252
					}.start();
253
				}
254
			});
255
		}
256
	}
257
258
	/**
259
	 * Called when the LatencyView is closed: disposes of the canvas and 
260
	 * unregisters them from the InterfaceMediator.
261
	 */
262
	@Override
263
	public void dispose() {
264
		graphView_.dispose();
265
		histogramView_.dispose();
266
		
267
		InterfaceMediator.getInstance().unregisterViews();
268
		
269
		super.dispose();
270
	}
271
	
272
	
273
	
274
	
275
	
276
	/**
277
     * Method called when synchonization is active and that the user select an event.<p>
278
     * We update the current event timeTextGroup and move the selected window if needed.
279
     * 
280
     * @param signal Signal received from the framework. Contain the event.
281
     */
282
    @TmfSignalHandler
283
    public void currentTimeUpdated(TmfTimeSynchSignal signal) {
284
    	
285
    }
286
    
287
    @TmfSignalHandler
288
	public void synchToTimeRange(TmfRangeSynchSignal signal) {
289
    	rangeSyncSignal_ = signal;
290
    	if (rangeSyncSignal_ != null && rangeSyncSignal_.getSource() != this) {
291
    		// Erase the graph views
292
    		graphView_.clear();
293
    		histogramView_.clear();
294
    		
295
    		TmfTimestamp startTime = rangeSyncSignal_.getCurrentRange().getStartTime();
296
    		TmfTimestamp endTime   = rangeSyncSignal_.getCurrentRange().getEndTime();
297
    		timeRange_ = new TmfTimeRange(startTime, endTime);
298
    		
299
    		InterfaceMediator.getInstance().analyseLatencyForAllEvents();
300
    	}
301
	}
302
    
303
    
304
    
305
    
306
    
307
    /**
308
     * Fills the local pull down menu.
309
     * @param manager The menu manager.
310
     */
311
    private void fillLocalPullDown(IMenuManager manager) {
312
    	manager.add(new Separator());
313
    	manager.add(increaseBarWidth_);
314
    	manager.add(decreaseBarWidth_);
315
    	manager.add(new Separator());
316
    	manager.add(listMatchingEvents_);
317
    	manager.add(addMatchingEvents_);
318
    	manager.add(deleteMatchingEvents_);
319
    	manager.add(new Separator());
320
    }
321
    
322
    /**
323
     * Fills the local toolbar.
324
     * @param manager The toolbar manager
325
     */
326
    private void fillLocalToolBar(IToolBarManager manager) {
327
    	manager.add(new Separator());
328
    	manager.add(increaseBarWidth_);
329
    	manager.add(decreaseBarWidth_);
330
    	manager.add(new Separator());
331
    	manager.add(listMatchingEvents_);
332
    	manager.add(addMatchingEvents_);
333
    	manager.add(deleteMatchingEvents_);
334
    	manager.add(new Separator());
335
    }
336
    
337
    /**
338
     * Creates the actions required by the dialog events.
339
     */
340
    private void makeActions() {
341
    	// Increase the histogram bar width
342
    	increaseBarWidth_ = new Action() {
343
    		public void run() {
344
    			Config.HISTOGRAM_BAR_WIDTH += 5;
345
    			if (Config.HISTOGRAM_BAR_WIDTH > 300)
346
    				Config.HISTOGRAM_BAR_WIDTH = 300;
347
    			histogramView_.notifyNumberOfBars();
348
    			sendAnalysisRequest();
349
    		}
350
    	};
351
    	String tooltipText = Messages.getString("LatencyView.Action.IncreaseBarWidth.Tooltip");
352
    	increaseBarWidth_.setText(tooltipText);
353
    	increaseBarWidth_.setToolTipText(tooltipText);
354
    	increaseBarWidth_.setImageDescriptor(
355
    			AbstractUIPlugin.imageDescriptorFromPlugin(
356
    					Messages.getString("LatencyView.tmf.UI"), 
357
    					"icons/increasebar_button.gif"));
358
    	
359
    	
360
361
    	
362
363
    	// Decrease the histogram bar width
364
    	decreaseBarWidth_ = new Action() {
365
    		public void run() {
366
    			Config.HISTOGRAM_BAR_WIDTH -= 5;
367
    			if (Config.HISTOGRAM_BAR_WIDTH < 5)
368
    				Config.HISTOGRAM_BAR_WIDTH = 5;
369
    			histogramView_.notifyNumberOfBars();
370
    			sendAnalysisRequest();
371
    		}
372
    	};
373
    	tooltipText = Messages.getString("LatencyView.Action.DecreaseBarWidth.Tooltip");
374
    	decreaseBarWidth_.setText(tooltipText);
375
    	decreaseBarWidth_.setToolTipText(tooltipText);
376
    	decreaseBarWidth_.setImageDescriptor(
377
    			AbstractUIPlugin.imageDescriptorFromPlugin(
378
    					Messages.getString("LatencyView.tmf.UI"), 
379
    					"icons/decreasebar_button.gif"));
380
    	
381
    	
382
383
    	
384
    	// List matching events dialog
385
    	listMatchingEvents_ = new Action() {
386
    		public void run() {
387
    			ListDialog listDialog = new ListDialog(
388
    					parent_.getShell(),
389
    					Messages.getString("LatencyView.Dialogs.ListEvents.Title"),
390
    					Messages.getString("LatencyView.Dialogs.ListEvents.Message") );
391
    			listDialog.create();
392
    			listDialog.open();
393
    		}
394
    	};
395
    	tooltipText = Messages.getString("LatencyView.Action.ListEvents.Tooltip");
396
    	listMatchingEvents_.setText(tooltipText);
397
    	listMatchingEvents_.setToolTipText(tooltipText);
398
    	listMatchingEvents_.setImageDescriptor(
399
    			AbstractUIPlugin.imageDescriptorFromPlugin(
400
    					Messages.getString("LatencyView.tmf.UI"), 
401
    					"icons/events_view.gif"));
402
    	
403
    	
404
405
    	// Add matching events dialog
406
    	addMatchingEvents_ = new Action() {
407
    		public void run() {
408
    			AddDialog addDialog = new AddDialog(
409
    					parent_.getShell(),
410
    					Messages.getString("LatencyView.Dialogs.AddEvents.Title"),
411
    					Messages.getString("LatencyView.Dialogs.AddEvents.Message") );
412
    			addDialog.create();
413
    			addDialog.open();
414
    		}
415
    	};
416
    	tooltipText = Messages.getString("LatencyView.Action.AddEvents.Tooltip");
417
    	addMatchingEvents_.setText(tooltipText);
418
    	addMatchingEvents_.setToolTipText(tooltipText);
419
    	addMatchingEvents_.setImageDescriptor(
420
    			AbstractUIPlugin.imageDescriptorFromPlugin(
421
    					Messages.getString("LatencyView.tmf.UI"), 
422
    					"icons/add_button.gif"));
423
    	
424
    	
425
426
    	// Remove matching events dialog
427
    	deleteMatchingEvents_ = new Action() {
428
    		public void run() {
429
    			DeleteDialog deleteDialog = new DeleteDialog(
430
    					parent_.getShell(),
431
    					Messages.getString("LatencyView.Dialogs.DeleteEvents.Title"),
432
    					Messages.getString("LatencyView.Dialogs.DeleteEvents.Message") );
433
    			deleteDialog.create();
434
    			deleteDialog.open();
435
    		}
436
    	};
437
    	tooltipText = Messages.getString("LatencyView.Action.DeleteEvents.Tooltip");
438
    	deleteMatchingEvents_.setText(tooltipText);
439
    	deleteMatchingEvents_.setToolTipText(tooltipText);
440
    	deleteMatchingEvents_.setImageDescriptor(
441
    			AbstractUIPlugin.imageDescriptorFromPlugin(
442
    					Messages.getString("LatencyView.tmf.UI"), 
443
    					"icons/delete_button.gif"));
444
    }
445
    
446
    /**
447
     * Build the toolbar and menu by adding action buttons for dialogs.
448
     */
449
    private void contributeToActionBars() {
450
    	IActionBars bars = getViewSite().getActionBars();
451
    	fillLocalPullDown(bars.getMenuManager());
452
    	fillLocalToolBar(bars.getToolBarManager());
453
    }
454
    
455
    
456
    
457
    
458
    
459
    
460
    
461
 
462
    /**
463
     * Before completing its indexing, the experiment doesn't know start/end time. However, LTTng individual traces have this 
464
     * knowledge so we should ask them directly.
465
     * @return The experiment's time range.
466
     */
467
    public static TmfTimeRange getExperimentTimeRange() {
468
		TmfTimestamp startTime = TmfTimestamp.BigCrunch;
469
		TmfTimestamp endTime   = TmfTimestamp.BigBang;
470
		
471
		if (rangeSyncSignal_ != null) {
472
			startTime = rangeSyncSignal_.getCurrentRange().getStartTime();
473
    		endTime   = rangeSyncSignal_.getCurrentRange().getEndTime();
474
    		timeRange_ = new TmfTimeRange(startTime, endTime);
475
		} else if (experiment_ != null) {
476
			for (ITmfTrace trace : experiment_.getTraces()) {
477
				TmfContext context = trace.seekLocation(null);
478
				context.setRank(0);
479
				TmfEvent event = trace.getNextEvent(context);
480
				
481
				TmfTimestamp traceStartTime = event.getTimestamp();
482
				if (traceStartTime.compareTo(startTime, true) < 0)
483
					startTime = traceStartTime;
484
				
485
				TmfTimestamp traceEndTime = trace.getEndTime();
486
				if (traceEndTime.compareTo(endTime, true) > 0)
487
					endTime = traceEndTime;
488
	    	}
489
		}
490
		
491
        return new TmfTimeRange(startTime, endTime);
492
    }
493
    
494
    /**
495
     * Returns the current histogram window time range.
496
     * @return The current histogram window time range.
497
     */
498
    public static TmfTimeRange getTimeRange() {
499
    	return timeRange_;
500
    }
501
502
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/Messages.java (+55 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency;
13
14
import java.util.MissingResourceException;
15
import java.util.ResourceBundle;
16
17
18
/**
19
 * Returns localised strings from the resource bundle (i.e. "messages.properties").
20
 * 
21
 * @author Philippe Sawicki
22
 */
23
public class Messages {
24
	
25
	/**
26
	 * Bundle name.
27
	 */
28
	private static final String BUNDLE_NAME = "org.eclipse.linuxtools.lttng.ui.views.latency.messages"; //$NON-NLS-1$
29
30
	/**
31
	 * A reference to the resource bundle.
32
	 */
33
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
34
35
	
36
	/**
37
	 * Private constructor to defeat instantiation.
38
	 */
39
	private Messages() {
40
		
41
	}
42
43
	/**
44
	 * Returns the localised String for the given key-ID.
45
	 * @param key The key of the localised String.
46
	 * @return The localised String for the given key-ID.
47
	 */
48
	public static String getString(String key) {
49
		try {
50
			return RESOURCE_BUNDLE.getString(key);
51
		} catch (MissingResourceException e) {
52
			return '!' + key + '!';
53
		}
54
	}
55
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AbstractDialog.java (+214 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs;
13
14
import java.util.Vector;
15
16
import org.eclipse.jface.dialogs.IDialogSettings;
17
import org.eclipse.jface.dialogs.IMessageProvider;
18
import org.eclipse.jface.dialogs.TitleAreaDialog;
19
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
20
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair;
21
import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
22
import org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Display;
26
import org.eclipse.swt.widgets.Shell;
27
28
29
/**
30
 * Abstract dialog class, regroups the main functions shared by all the 
31
 * different dialogs.
32
 * 
33
 * @author Philippe Sawicki
34
 */
35
public abstract class AbstractDialog extends TitleAreaDialog {
36
	
37
	/**
38
	 * The dialog window title.
39
	 */
40
	protected String dialogTitle_;
41
	/**
42
	 * The dialog window message.
43
	 */
44
	protected String dialogMessage_;
45
	
46
	/**
47
	 * The code returned by the dialog when the user closes the "Add" dialog.
48
	 */
49
	public static final int ADD = 53445;
50
	/**
51
	 * The code returned by the dialog when the user closes the "Delete" dialog.
52
	 */
53
	public static final int DELETE = ADD+1;
54
	/**
55
	 * The code returned by the dialog when the user resets the latency pair to default.
56
	 */
57
	public static final int RESET = DELETE+1;
58
	
59
	/**
60
	 * String ID of the number of pairs saved in the settings file.
61
	 */
62
	protected static final String LATENCY_NB_MATCH_PAIRS = "NB_LATENCY_MATCH_PAIRS";
63
	/**
64
	 * String ID of the start event pairs saved in the settings file.
65
	 */
66
	protected static final String LATENCY_PAIRS_START = "LATENCY_PAIRS_START";
67
	/**
68
	 * String ID of the end event pairs saved in the settings file.
69
	 */
70
	protected static final String LATENCY_PAIRS_END = "LATENCY_PAIRS_END";
71
	
72
	/**
73
	 * Dialog settings, saves the event pairs across sessions.
74
	 */
75
	protected IDialogSettings settings_;
76
	
77
	/**
78
	 * Do the graphs canvas need to be redrawn due to latency pairs changes ?
79
	 */
80
	protected boolean redrawGraphs_ = false;
81
	
82
	
83
	/**
84
	 * Constructor.
85
	 * @param parentShell The parent shell.
86
	 * @param title The dialog window's title.
87
	 * @param message The dialog window's message.
88
	 */
89
	public AbstractDialog(Shell parentShell, String title, String message) {
90
		super(parentShell);
91
		dialogTitle_ = title;
92
		dialogMessage_ = message;
93
		
94
		settings_ = LTTngUiPlugin.getDefault().getDialogSettings();
95
	}
96
	
97
	/**
98
	 * Constructor
99
	 * @param parentShell The parent shell.
100
	 * @param title The dialog window's title.
101
	 */
102
	public AbstractDialog(Shell parentShell, String title) {
103
		this(parentShell, title, "");
104
	}
105
106
	/**
107
	 * Constructor.
108
	 * @param parentShell The parent shell.
109
	 */
110
	public AbstractDialog(Shell parentShell) {
111
		this(parentShell, "", "");
112
	}
113
	
114
	/**
115
	 * Creates the dialog.
116
	 * 
117
	 * <b>Note :</b> Since there is an issue with the table's vertical scrollbar,
118
	 * this dialog "resize" is necessary to ensure a minimal height for the window.
119
	 */
120
	@Override
121
	public void create() {
122
		super.create();
123
		//  Set the title
124
		setTitle(dialogTitle_);
125
		// Set the message
126
		setMessage(dialogMessage_, IMessageProvider.INFORMATION);
127
		
128
		// Position the dialog at the center of the screen
129
		int windowWidth  = Display.getCurrent().getPrimaryMonitor().getBounds().width;
130
		int windowHeight = Display.getCurrent().getPrimaryMonitor().getBounds().height;
131
		int dialogWidth  = getShell().getSize().x;
132
		int dialogHeight = windowHeight / 2;
133
		
134
		int x = (windowWidth  - dialogWidth)  / 2;
135
		int y = (windowHeight - dialogHeight) / 2;
136
		
137
		getShell().setSize(getShell().getSize().x, dialogHeight);
138
		getShell().setLocation(x, y);
139
	}
140
	
141
	/**
142
	 * Formats the "#" of the event in the table by adding "00" before it.
143
	 * @param number The number to format.
144
	 * @param max The maximum number of event pairs in the list.
145
	 * @return The formatted string.
146
	 */
147
	protected String formatListNumber(int number, int max) {
148
		return String.format("%0"+max+"d", number);
149
	}
150
	
151
	/**
152
	 * Returns the match pairs saved in the settings file.
153
	 * @return The match pairs saved in the settings file.
154
	 */
155
	protected Pair<Vector<String>,Vector<String>> getMatchPairs() {
156
		try {
157
			// Check if the settings file has already some data (i.e. try provoking an exception)
158
			settings_.getInt(LATENCY_NB_MATCH_PAIRS);
159
			
160
			String[] starts = settings_.getArray(LATENCY_PAIRS_START);
161
			String[] ends   = settings_.getArray(LATENCY_PAIRS_END);
162
163
			EventMatcher.getInstance().resetMatches();
164
			for (int i = 0; i < starts.length; i++) {
165
				EventMatcher.getInstance().addMatch(starts[i], ends[i]);
166
			}
167
			
168
			return EventMatcher.getInstance().getEvents();
169
		} catch (NumberFormatException e) {
170
			return EventMatcher.getInstance().getEvents();
171
		}
172
	}
173
	
174
	/**
175
	 * Saves the event match pairs to a settings file.
176
	 * @param start The start event types.
177
	 * @param end The end event types.
178
	 */
179
	protected void saveMatchPairs(Vector<String> start, Vector<String> end) {
180
		settings_.put(LATENCY_NB_MATCH_PAIRS, start.size());
181
		settings_.put(LATENCY_PAIRS_START, start.toArray(new String[]{}));
182
		settings_.put(LATENCY_PAIRS_END, end.toArray(new String[]{}));
183
	}
184
	
185
	/**
186
	 * Ask the LatencyView to send a new analysis request to the views, so that they can be redrawn.
187
	 */
188
	protected void redrawGraphs() {
189
		LatencyView.sendAnalysisRequest();
190
	}
191
192
	/**
193
	 * Creates the dialog area.
194
	 * @param parent The parent.
195
	 */
196
	@Override
197
	protected abstract Control createDialogArea(Composite parent);
198
199
	/**
200
	 * Creates the buttons for the button bar.
201
	 * @param parent The parent.
202
	 */
203
	@Override
204
	protected abstract void createButtonsForButtonBar(Composite parent);
205
	
206
	/**
207
	 * Is the dialog resizable ?
208
	 */
209
	@Override
210
	protected boolean isResizable() {
211
		return true;
212
	}
213
214
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/AddDialog.java (+468 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs;
13
14
import java.util.Vector;
15
16
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
17
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair;
18
import org.eclipse.linuxtools.lttng.ui.views.latency.Messages;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Event;
26
import org.eclipse.swt.widgets.Listener;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.swt.widgets.Table;
29
import org.eclipse.swt.widgets.TableColumn;
30
import org.eclipse.swt.widgets.TableItem;
31
32
33
/**
34
 * Add dialog, lets the user add custom start/end event pairs.
35
 * 
36
 * @author Philippe Sawicki
37
 */
38
public class AddDialog extends AbstractDialog {
39
	
40
	/**
41
	 * The dialog's start table.
42
	 */
43
	protected Table startTable_;
44
	/**
45
	 * The dialog's end table.
46
	 */
47
	protected Table endTable_;
48
	/**
49
	 * The dialog's list table.
50
	 */
51
	protected Table listTable_;
52
	
53
	/**
54
	 * Start table columns.
55
	 */
56
	protected TableColumn[] startColumns_;
57
	/**
58
	 * End table columns.
59
	 */
60
	protected TableColumn[] endColumns_;
61
	/**
62
	 * List table columns.
63
	 */
64
	protected TableColumn[] listColumns_;
65
	
66
	/**
67
	 * Start table column names (header titles).
68
	 */
69
	protected static final String[] START_COLUMN_NAMES = {"", Messages.getString("LatencyView.Dialogs.AddEvents.Columns.Start")};
70
	/**
71
	 * End table column names (header titles).
72
	 */
73
	protected static final String[] END_COLUMN_NAMES = {"", Messages.getString("LatencyView.Dialogs.AddEvents.Columns.End")};
74
	/**
75
	 * List table column names (header titles).
76
	 */
77
	protected static final String[] LIST_COLUMN_NAMES = {"#", Messages.getString("LatencyView.Dialogs.AddEvents.Columns.List.Trigger"), Messages.getString("LatencyView.Dialogs.AddEvents.Columns.List.End")};
78
	/**
79
	 * Column widths.
80
	 */
81
	protected static final int[] COLUMN_WIDTHS = {25, 250, 250};
82
	
83
	/**
84
	 * Possible event types.
85
	 */
86
	protected Vector<String> eventTypes_ = new Vector<String>();
87
	
88
	/**
89
	 * Start event types.
90
	 */
91
	protected Vector<String> eventStartTypes_;
92
	/**
93
	 * End event types.
94
	 */
95
	protected Vector<String> eventEndTypes_;
96
	
97
	/**
98
	 * Selected start type.
99
	 */
100
	protected String startType_;
101
	/**
102
	 * Selected end type.
103
	 */
104
	protected String endType_;
105
	
106
107
	/**
108
	 * Constructor.
109
	 * @param parentShell The parent shell.
110
	 * @param title The dialog's window title.
111
	 * @param message The dialog's window message.
112
	 */
113
	public AddDialog(Shell parentShell, String title, String message) {
114
		super(parentShell, title, message);
115
		
116
		// Get the possible events from the list
117
		eventTypes_ = EventMatcher.getInstance().getTypeList();
118
		
119
		// Get the list of start and end types from the EventMatcher
120
		Pair<Vector<String>,Vector<String>> pair = getMatchPairs();
121
		eventStartTypes_ = pair.getFirst();
122
		eventEndTypes_   = pair.getSecond();
123
	}
124
	
125
	/**
126
	 * Creates the start table's columns (i.e. the table header).
127
	 */
128
	protected void createStartColumns() {
129
		startColumns_ = new TableColumn[START_COLUMN_NAMES.length];
130
		for (int i = 0; i < START_COLUMN_NAMES.length; i++) {
131
			startColumns_[i] = new TableColumn(startTable_, SWT.LEFT);
132
			startColumns_[i].setText(START_COLUMN_NAMES[i]);
133
			startColumns_[i].setWidth(COLUMN_WIDTHS[i]);
134
		}
135
	}
136
	
137
	/**
138
	 * Creates the end table's columns (i.e. the table header).
139
	 */
140
	protected void createEndColumns() {
141
		endColumns_ = new TableColumn[END_COLUMN_NAMES.length];
142
		for (int i = 0; i < END_COLUMN_NAMES.length; i++) {
143
			endColumns_[i] = new TableColumn(endTable_, SWT.LEFT);
144
			endColumns_[i].setText(END_COLUMN_NAMES[i]);
145
			endColumns_[i].setWidth(COLUMN_WIDTHS[i]);
146
		}
147
	}
148
	
149
	/**
150
	 * Creates the list table's columns (i.e. the table header).
151
	 */
152
	protected void createListColumns() {
153
		listColumns_ = new TableColumn[LIST_COLUMN_NAMES.length];
154
		for (int i = 0; i < LIST_COLUMN_NAMES.length; i++) {
155
			listColumns_[i] = new TableColumn(listTable_, SWT.LEFT);
156
			listColumns_[i].setText(LIST_COLUMN_NAMES[i]);
157
			listColumns_[i].setWidth(COLUMN_WIDTHS[i]);
158
		}
159
	}
160
	
161
	/**
162
	 * Creates the start column list.
163
	 * @param parent The parent composite.
164
	 */
165
	protected void createStartColumn(Composite parent) {
166
		final int style = SWT.SINGLE | SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL;
167
		GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
168
		startTable_ = new Table(parent, style);
169
		startTable_.setLayoutData(layoutData);
170
		
171
		// Some cosmetic enhancements
172
		startTable_.setHeaderVisible(true);
173
		startTable_.setLinesVisible(true);
174
		
175
		createStartColumns();
176
		
177
		for (int i = 0; i < eventTypes_.size(); i++) {
178
			TableItem item = new TableItem(startTable_, SWT.RIGHT);
179
			
180
			String[] columns = {
181
					eventTypes_.get(i),
182
					eventTypes_.get(i)
183
			};
184
			
185
			item.setText(columns);
186
		}
187
		
188
		startTable_.setItemCount( eventTypes_.size() );
189
		
190
		startTable_.addListener(SWT.Selection, new Listener() {
191
			public void handleEvent(Event event) {
192
				if (event.detail == SWT.CHECK) {
193
					TableItem[] items = startTable_.getItems();
194
					for (TableItem item : items) {
195
						if (item != event.item) {
196
							item.setChecked(false);
197
						}
198
					}
199
				}
200
			}
201
		});
202
	}
203
204
	/**
205
	 * Creates the end column list.
206
	 * @param parent The parent composite.
207
	 */
208
	protected void createEndColumn(Composite parent) {
209
		final int style = SWT.SINGLE | SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL;
210
		GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
211
		endTable_ = new Table(parent, style);
212
		endTable_.setLayoutData(layoutData);
213
		
214
		// Some cosmetic enhancements
215
		endTable_.setHeaderVisible(true);
216
		endTable_.setLinesVisible(true);
217
		
218
		createEndColumns();
219
		
220
		for (int i = 0; i < eventTypes_.size(); i++) {
221
			TableItem item = new TableItem(endTable_, SWT.RIGHT);
222
			
223
			String[] columns = {
224
					eventTypes_.get(i),
225
					eventTypes_.get(i)
226
			};
227
			
228
			item.setText(columns);
229
		}
230
		
231
		endTable_.setItemCount( eventTypes_.size() );
232
		
233
		endTable_.addListener(SWT.Selection, new Listener() {
234
			public void handleEvent(Event event) {
235
				if (event.detail == SWT.CHECK) {
236
					TableItem[] items = endTable_.getItems();
237
					for (TableItem item : items) {
238
						if (item != event.item) {
239
							item.setChecked(false);
240
						}
241
					}
242
				}
243
			}
244
		});
245
	}
246
247
	/**
248
	 * Creates the list column for already existing event pairs.
249
	 * @param parent The parent composite.
250
	 */
251
	protected void createListColumn(Composite parent) {
252
		final int style = SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL;
253
		GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
254
		layoutData.horizontalSpan = 2;
255
		listTable_ = new Table(parent, style);
256
		listTable_.setLayoutData(layoutData);
257
		
258
		// Some cosmetic enhancements
259
		listTable_.setHeaderVisible(true);
260
		listTable_.setLinesVisible(true);
261
		
262
		createListColumns();
263
		
264
		for (int i = 0; i < eventStartTypes_.size(); i++) {
265
			TableItem item = new TableItem(listTable_, SWT.RIGHT);
266
			
267
			String max = "" + eventStartTypes_.size();
268
			String number = formatListNumber(i+1, max.length());
269
			
270
			String[] columns = {
271
					number,
272
					eventStartTypes_.get(i),
273
					eventEndTypes_.get(i)
274
			};
275
			
276
			item.setText(columns);
277
		}
278
		
279
		listTable_.setItemCount( 103 );
280
		listTable_.remove(eventTypes_.size(), 103-1);
281
	}
282
283
	/**
284
	 * Creates the dialog area.
285
	 * @param parent The parent.
286
	 */
287
	@Override
288
	protected Control createDialogArea(Composite parent) {
289
		GridLayout layout = new GridLayout(2, true);
290
		parent.setLayout(layout);
291
		
292
		createStartColumn(parent);
293
		createEndColumn(parent);
294
		createListColumn(parent);
295
		
296
		return parent;
297
	}
298
299
	/**
300
	 * Creates the buttons for the button bar.
301
	 * @param parent The parent.
302
	 */
303
	@Override
304
	protected void createButtonsForButtonBar(Composite parent) {
305
		GridData gridData = new GridData();
306
		gridData.verticalAlignment = GridData.FILL;
307
		gridData.horizontalSpan = 1;
308
		gridData.grabExcessHorizontalSpace = true;
309
		gridData.grabExcessVerticalSpace = true;
310
		gridData.horizontalAlignment = SWT.RIGHT;
311
		
312
		parent.setLayoutData(gridData);
313
		
314
		// Create the "Add" button
315
		Button addButton = createButton(parent, ADD, Messages.getString("LatencyView.Dialogs.AddEvents.Buttons.Add"), false);
316
		addButton.addListener(SWT.Selection, new Listener() {
317
			public void handleEvent(Event event) {
318
				if (isValidInput()) {
319
					// Add the event pair to the EventMatcher and save the pairs 
320
					EventMatcher.getInstance().addMatch(startType_, endType_);
321
					eventStartTypes_.add(startType_);
322
					eventEndTypes_.add(endType_);
323
					saveMatchPairs(eventStartTypes_, eventEndTypes_);
324
					
325
					Pair<Vector<String>,Vector<String>> pairs = EventMatcher.getInstance().getEvents();
326
					eventStartTypes_ = pairs.getFirst();
327
					eventEndTypes_   = pairs.getSecond();
328
					
329
					listTable_.removeAll();
330
					
331
					for (int i = 0; i < eventStartTypes_.size(); i++) {
332
						TableItem item = new TableItem(listTable_, SWT.RIGHT);
333
						
334
						String max = "" + eventStartTypes_.size();
335
						String number = formatListNumber(i+1, max.length());
336
						
337
						String[] columns = {
338
								number,
339
								eventStartTypes_.get(i),
340
								eventEndTypes_.get(i)
341
						};
342
						
343
						item.setText(columns);
344
					}
345
					
346
					saveMatchPairs(eventStartTypes_, eventEndTypes_);
347
				}
348
				
349
				redrawGraphs_ = true;
350
			}
351
		});
352
		
353
		// Create the "Close" button
354
		Button closeButton = createButton(parent, CANCEL, Messages.getString("LatencyView.Dialogs.AddEvents.Buttons.Close"), false);
355
		closeButton.addListener(SWT.Selection, new Listener() {
356
			@Override
357
			public void handleEvent(Event event) {
358
				setReturnCode(CANCEL);
359
				
360
				if (redrawGraphs_ == true)
361
					redrawGraphs();
362
				
363
				close();
364
			}
365
		});
366
	}
367
	
368
	/**
369
	 * Validate the list before adding event pairs.
370
	 * @return "true" if the input is valid, "false" otherwise.
371
	 */
372
	protected boolean isValidInput() {
373
		// Remove the previous error message
374
		setErrorMessage(null);
375
		
376
		boolean valid = true;
377
		
378
		// Check if an item from the start list is selected
379
		TableItem[] items = startTable_.getItems();
380
		startType_ = null;
381
		boolean startHasSelectedItem = false;
382
		for (int i = 0; i < items.length && !startHasSelectedItem; i++) {
383
			if (items[i].getChecked() == true) {
384
				startType_ = items[i].getText();
385
				startHasSelectedItem = true;
386
			}
387
		}
388
389
		// Check if an item from the end list is selected
390
		items = endTable_.getItems();
391
		endType_ = null;
392
		boolean endHasSelectedItem = false;
393
		for (int i = 0; i < items.length && !endHasSelectedItem; i++) {
394
			if (items[i].getChecked() == true) {
395
				endType_ = items[i].getText();
396
				endHasSelectedItem = true;
397
			}
398
		}
399
		
400
		// Print error message if needed.
401
		if (!startHasSelectedItem && !endHasSelectedItem) {
402
			setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.NoSelection") );
403
			valid = false;
404
		} else if (!startHasSelectedItem) {
405
			setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.StartNotSelected") );
406
			valid = false;
407
		} else if (!endHasSelectedItem) {
408
			setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.EndNotSelected") );
409
			valid = false;
410
		}
411
		
412
		// Check if the same item is selected in both lists
413
		if (startHasSelectedItem && endHasSelectedItem) {
414
			if ( startType_.equalsIgnoreCase(endType_) ) {
415
				setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.SameSelected") );
416
				valid = false;
417
			}
418
		}
419
		
420
		// Check if the selected item is already in the list
421
		if (startHasSelectedItem && endHasSelectedItem) {
422
			Pair<Vector<String>,Vector<String>> pairs = getMatchPairs();
423
			Vector<String> startEvents = pairs.getFirst();
424
			Vector<String> endEvents   = pairs.getSecond();
425
			
426
			boolean startAlreadyUsed      = false;
427
			boolean endAlreadyUsed        = false;
428
			boolean startAsEndAlreadyUsed = false;
429
			boolean endAsStartAlreadyUsed = false;
430
			
431
			if (startEvents.contains(startType_)) {
432
				startAlreadyUsed = true;
433
			}
434
			if (endEvents.contains(endType_)) {
435
				endAlreadyUsed = true;
436
			}
437
			if (startEvents.contains(endType_)) {
438
				endAsStartAlreadyUsed = true;
439
			}
440
			if (endEvents.contains(startType_)) {
441
				startAsEndAlreadyUsed = true;
442
			}
443
			
444
			if (startAlreadyUsed && endAlreadyUsed) {
445
				setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.AlreadyMatched") );
446
				valid = false;
447
			} else if (startAlreadyUsed) {
448
				setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.StartAlreadyMatched") );
449
				valid = false;
450
			} else if (endAlreadyUsed) {
451
				setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.EndAlreadyMatched") );
452
				valid = false;
453
			}
454
			
455
			if (startAsEndAlreadyUsed) {
456
				setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.StartAsEnd") );
457
				valid = false;
458
			}
459
			if (endAsStartAlreadyUsed) {
460
				setErrorMessage( Messages.getString("LatencyView.Dialogs.AddEvents.Errors.EndAsStart") );
461
				valid = false;
462
			}
463
		}
464
		
465
		return valid;
466
	}
467
468
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/DeleteDialog.java (+146 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs;
13
14
import org.eclipse.jface.dialogs.MessageDialog;
15
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
16
import org.eclipse.linuxtools.lttng.ui.views.latency.Messages;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.widgets.Button;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Listener;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.swt.widgets.TableItem;
25
26
27
/**
28
 * Remove dialog, lets the user remove start/end event pairs.
29
 * 
30
 * @author Philippe Sawicki
31
 */
32
public class DeleteDialog extends ListDialog {
33
34
	/**
35
	 * Constructor.
36
	 * @param parentShell The parent shell.
37
	 * @param title The dialog's window title.
38
	 * @param message The dialog's window message.
39
	 */
40
	public DeleteDialog(Shell parentShell, String title, String message) {
41
		super(parentShell, title, message);
42
		
43
		// Set the table style
44
		style_ = SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL;
45
	}
46
47
	/**
48
	 * Creates the buttons for the button bar.
49
	 * @param parent The parent.
50
	 */
51
	@Override
52
	protected void createButtonsForButtonBar(Composite parent) {
53
		GridData gridData = new GridData();
54
		gridData.verticalAlignment = GridData.FILL;
55
		gridData.horizontalSpan = 1;
56
		gridData.grabExcessHorizontalSpace = true;
57
		gridData.grabExcessVerticalSpace = true;
58
		gridData.horizontalAlignment = SWT.RIGHT;
59
		
60
		parent.setLayoutData(gridData);
61
		
62
		// Create the "Delete" button
63
		Button deleteButton = createButton(parent, DELETE, Messages.getString("LatencyView.Dialogs.DeleteEvents.Buttons.Delete"), false);
64
		deleteButton.addListener(SWT.Selection, new Listener() {
65
			public void handleEvent(Event event) {
66
				TableItem selectedItem = table_.getSelection()[0];
67
				if (selectedItem == null)
68
					return;
69
				
70
				int[] selectedIndices = table_.getSelectionIndices();
71
				
72
				String deletePairs = "";
73
				for (int i = 0; i < selectedIndices.length; i++) {
74
					int index = selectedIndices[i];
75
					deletePairs += "\t* " + eventStartTypes_.get(index) + " / " + eventEndTypes_.get(index);
76
					
77
					if (i < selectedIndices.length-1) {
78
						deletePairs += "\n";
79
					}
80
				}
81
				
82
				boolean confirmDeletion = MessageDialog.openQuestion(
83
						getShell(),
84
						Messages.getString("LatencyView.Dialogs.DeleteEvents.Confirm.Title"),
85
						Messages.getString("LatencyView.Dialogs.DeleteEvents.Confirm.Message") + "\n\n" + deletePairs);
86
				
87
				if (confirmDeletion) {
88
					// Remove the events starting from the end of the list, otherwise the TableItem elements will lose their
89
					// index from the table and may trigger an exception when removing an index that is no longer valid.
90
					for (int i = selectedIndices.length-1; i >= 0; i--) {
91
						int selectedIndex = selectedIndices[i];
92
						EventMatcher.getInstance().removeMatch(eventStartTypes_.get(selectedIndex), eventEndTypes_.get(selectedIndex));
93
						
94
						table_.remove(selectedIndex);
95
						
96
						// Update the list of events
97
						eventStartTypes_.remove(selectedIndex);
98
						eventEndTypes_.remove(selectedIndex);
99
					}
100
					
101
					// Save the events pairs in the settings file so it can be retrieved in the next session
102
					saveMatchPairs(eventStartTypes_, eventEndTypes_);
103
					
104
					table_.setItemCount( eventStartTypes_.size() );
105
					
106
					TableItem[] newItems = table_.getItems();
107
					table_.removeAll();
108
					for (int i = 0; i < newItems.length; i++) {
109
						TableItem item = new TableItem(table_, SWT.RIGHT);
110
						
111
						String max = "" + eventStartTypes_.size();
112
						String number = formatListNumber(i+1, max.length());
113
						
114
						String[] columns = {
115
								number,
116
								eventStartTypes_.get(i),
117
								eventEndTypes_.get(i)
118
						};
119
						
120
						item.setText(columns);
121
					}
122
					
123
					redrawGraphs_ = true;
124
				}
125
			}
126
		});
127
		
128
		// Create the "Close" button
129
		Button closeButton = createButton(parent, CANCEL, Messages.getString("LatencyView.Dialogs.AddEvents.Buttons.Close"), false);
130
		closeButton.addListener(SWT.Selection, new Listener() {
131
			@Override
132
			public void handleEvent(Event event) {
133
				// Remember the user's list
134
				saveMatchPairs(eventStartTypes_, eventEndTypes_);
135
				
136
				setReturnCode(CANCEL);
137
138
				if (redrawGraphs_ == true)
139
					redrawGraphs();
140
				
141
				close();
142
			}
143
		});
144
	}
145
146
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/dialogs/ListDialog.java (+233 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.dialogs;
13
14
import java.util.Vector;
15
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
18
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair;
19
import org.eclipse.linuxtools.lttng.ui.views.latency.Messages;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Event;
27
import org.eclipse.swt.widgets.Listener;
28
import org.eclipse.swt.widgets.Shell;
29
import org.eclipse.swt.widgets.Table;
30
import org.eclipse.swt.widgets.TableColumn;
31
import org.eclipse.swt.widgets.TableItem;
32
33
34
/**
35
 * List dialog, shows the list of start/end event pairs.
36
 * 
37
 * @author Philippe Sawicki
38
 */
39
public class ListDialog extends AbstractDialog {
40
	
41
	/**
42
	 * The dialog's table.
43
	 */
44
	protected Table table_;
45
	
46
	/**
47
	 * Start event types.
48
	 */
49
	protected Vector<String> eventStartTypes_;
50
	/**
51
	 * End event types.
52
	 */
53
	protected Vector<String> eventEndTypes_;
54
	
55
	/**
56
	 * Table columns
57
	 */
58
	protected TableColumn[] columns_;
59
	
60
	/**
61
	 * Column names (header titles).
62
	 */
63
	protected static final String[] COLUMN_NAMES = {"#", Messages.getString("LatencyView.Dialogs.ListEvents.Columns.Trigger"), Messages.getString("LatencyView.Dialogs.ListEvents.Columns.End")};
64
	/**
65
	 * Column widths.
66
	 */
67
	protected static final int[] COLUMN_WIDTHS = {25, 250, 250};
68
	
69
	/**
70
	 * The table style.
71
	 */
72
	protected int style_;
73
	
74
75
	/**
76
	 * Constructor.
77
	 * @param parentShell The parent shell.
78
	 * @param title The dialog's window title.
79
	 * @param message The dialog's window message.
80
	 */
81
	public ListDialog(Shell parentShell, String title, String message) {
82
		super(parentShell, title, message);
83
		
84
		// Set the table style
85
		style_ = SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL;
86
		
87
		// Get the list of start and end types from the EventMatcher
88
		Pair<Vector<String>,Vector<String>> pair = getMatchPairs();
89
		eventStartTypes_ = pair.getFirst();
90
		eventEndTypes_   = pair.getSecond();
91
	}
92
	
93
	/**
94
	 * Creates the table's column (i.e. the table header).
95
	 */
96
	protected void createColumns() {
97
		columns_ = new TableColumn[COLUMN_NAMES.length];
98
		for (int i = 0; i < COLUMN_NAMES.length; i++) {
99
			columns_[i] = new TableColumn(table_, SWT.LEFT);
100
			columns_[i].setText(COLUMN_NAMES[i]);
101
			columns_[i].setWidth(COLUMN_WIDTHS[i]);
102
		}
103
	}
104
	
105
	/**
106
	 * Creates the dialog area.
107
	 * @param parent The parent.
108
	 */
109
	@Override
110
	protected Control createDialogArea(Composite parent) {
111
		GridLayout layout = new GridLayout(1, true);
112
		parent.setLayout(layout);
113
		
114
		GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
115
		table_ = new Table(parent, style_);
116
		table_.setLayoutData(layoutData);
117
		
118
		// Some cosmetic enhancements
119
		table_.setHeaderVisible(true);
120
		table_.setLinesVisible(true);
121
		
122
		createColumns();
123
		
124
		for (int i = 0; i < eventStartTypes_.size(); i++) {
125
			TableItem item = new TableItem(table_, SWT.RIGHT);
126
			
127
			String max = "" + eventStartTypes_.size();
128
			String number = formatListNumber(i+1, max.length());
129
			
130
			String[] columns = {
131
					number,
132
					eventStartTypes_.get(i),
133
					eventEndTypes_.get(i)
134
			};
135
			
136
			item.setText(columns);
137
		}
138
		
139
		return parent;
140
	}
141
142
	/**
143
	 * Creates the buttons for the button bar.
144
	 * @param parent The parent.
145
	 */
146
	@Override
147
	protected void createButtonsForButtonBar(Composite parent) {
148
		GridData gridData = new GridData();
149
		gridData.verticalAlignment = GridData.FILL;
150
		gridData.horizontalSpan = 1;
151
		gridData.grabExcessHorizontalSpace = true;
152
		gridData.grabExcessVerticalSpace = true;
153
		gridData.horizontalAlignment = SWT.RIGHT;
154
		
155
		parent.setLayoutData(gridData);
156
		
157
		// Create the "Reset" button
158
		Button resetButton = createButton(parent, RESET, Messages.getString("LatencyView.Dialogs.ListEvents.Buttons.Reset"), false);
159
		resetButton.addListener(SWT.Selection, new Listener() {
160
			public void handleEvent(Event event) {
161
				boolean confirmDeletion = MessageDialog.openQuestion(
162
						getShell(),
163
						Messages.getString("LatencyView.Dialogs.ListEvents.Confirm.Title"),
164
						Messages.getString("LatencyView.Dialogs.ListEvents.Confirm.Message"));
165
				
166
				if (confirmDeletion) {
167
					EventMatcher.getInstance().resetMatches();
168
					
169
					table_.removeAll();
170
					
171
					Vector<String> defaultStarts = new Vector<String>();
172
					Vector<String> defaultEnds   = new Vector<String>();
173
					
174
					defaultStarts.add(EventMatcher.PAGE_FAULT_GET_USER_ENTRY); defaultEnds.add(EventMatcher.PAGE_FAULT_GET_USER_EXIT);
175
					defaultStarts.add(EventMatcher.TASKLET_LOW_ENTRY);         defaultEnds.add(EventMatcher.TASKLET_LOW_EXIT);
176
					defaultStarts.add(EventMatcher.PAGE_FAULT_ENTRY);          defaultEnds.add(EventMatcher.PAGE_FAULT_EXIT);
177
					defaultStarts.add(EventMatcher.SYSCALL_ENTRY);             defaultEnds.add(EventMatcher.SYSCALL_EXIT);
178
					defaultStarts.add(EventMatcher.IRQ_ENTRY);                 defaultEnds.add(EventMatcher.IRQ_EXIT);
179
					defaultStarts.add(EventMatcher.READ);                      defaultEnds.add(EventMatcher.WRITE);
180
					defaultStarts.add(EventMatcher.OPEN);                      defaultEnds.add(EventMatcher.CLOSE);
181
					defaultStarts.add(EventMatcher.BUFFER_WAIT_START);         defaultEnds.add(EventMatcher.BUFFER_WAIT_END);
182
					defaultStarts.add(EventMatcher.START_COMMIT);              defaultEnds.add(EventMatcher.END_COMMIT);
183
					defaultStarts.add(EventMatcher.WAIT_ON_PAGE_START);        defaultEnds.add(EventMatcher.WAIT_ON_PAGE_END);
184
185
					saveMatchPairs(defaultStarts, defaultEnds);
186
					
187
					for (int i = 0; i < defaultStarts.size(); i++) {
188
						EventMatcher.getInstance().addMatch(defaultStarts.get(i), defaultEnds.get(i));
189
					}
190
					
191
192
					// Get the list of start and end types from the EventMatcher
193
					Pair<Vector<String>,Vector<String>> pair = getMatchPairs();
194
					eventStartTypes_ = pair.getFirst();
195
					eventEndTypes_   = pair.getSecond();
196
					
197
					for (int i = 0; i < eventStartTypes_.size(); i++) {
198
						TableItem item = new TableItem(table_, SWT.RIGHT);
199
						
200
						String max = "" + eventStartTypes_.size();
201
						String number = formatListNumber(i+1, max.length());
202
						
203
						String[] columns = {
204
								number,
205
								eventStartTypes_.get(i),
206
								eventEndTypes_.get(i)
207
						};
208
						
209
						item.setText(columns);
210
					}
211
					
212
					table_.setItemCount(eventStartTypes_.size());
213
					
214
					redrawGraphs_ = true;
215
				}
216
			}
217
		});
218
		
219
		// Create the "Close" button
220
		Button closeButton = createButton(parent, CANCEL, Messages.getString("LatencyView.Dialogs.ListEvents.Buttons.Close"), false);
221
		closeButton.addListener(SWT.Selection, new Listener() {
222
			public void handleEvent(Event event) {
223
				setReturnCode(CANCEL);
224
				
225
				if (redrawGraphs_ == true)
226
					redrawGraphs();
227
				
228
				close();
229
			}
230
		});
231
	}
232
233
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/handlers/ViewHandler.java (+33 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.handlers;
13
14
15
/**
16
 * View handler, catches the view requests for data.
17
 * 
18
 * @author Philippe Sawicki
19
 */
20
public interface ViewHandler {
21
	
22
	/**
23
	 * Analyses the latency for all event types.
24
	 */
25
	public void analyseLatencyForAllEvents();
26
	
27
	/**
28
	 * Notifies the view handlers of the number of bars available.
29
	 * @param nbBars The number of bars available.
30
	 */
31
	public void notifyNumberOfBars(int nbBars);
32
33
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractMouseListener.java (+55 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners;
13
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.widgets.Event;
16
import org.eclipse.swt.widgets.Listener;
17
18
19
/**
20
 * AbstractMouseListener, base class for the canvas mouse listener.
21
 * 
22
 * @author Philippe Sawicki
23
 */
24
public abstract class AbstractMouseListener implements Listener {
25
26
	/**
27
	 * Mouse x-coordinate.
28
	 */
29
	protected long mouseX_;
30
	/**
31
	 * Mouse y-coordinate.
32
	 */
33
	protected long mouseY_;
34
	
35
	
36
	/**
37
	 * Handles the event.
38
	 */
39
	public void handleEvent(Event event) {
40
		switch (event.type) {
41
			case SWT.MouseMove:
42
				mouseX_ = event.x;
43
				mouseY_ = event.y;
44
				
45
				display();
46
				
47
				break;
48
		}
49
	}
50
	
51
	/**
52
	 * Tooltip display callback.
53
	 */
54
	protected abstract void display();
55
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/AbstractPaintListener.java (+649 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners;
13
14
import java.util.Collections;
15
import java.util.Vector;
16
17
import org.eclipse.linuxtools.lttng.analysis.Config;
18
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView;
19
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.PaintEvent;
22
import org.eclipse.swt.events.PaintListener;
23
import org.eclipse.swt.graphics.Color;
24
import org.eclipse.swt.graphics.Font;
25
import org.eclipse.swt.graphics.GC;
26
import org.eclipse.swt.graphics.Image;
27
import org.eclipse.swt.graphics.Point;
28
import org.eclipse.swt.graphics.Rectangle;
29
import org.eclipse.swt.widgets.Display;
30
31
32
/**
33
 * Abstract paint listener. Draws the graphs on the view canvas.
34
 * 
35
 * @author Philippe Sawicki
36
 */
37
public abstract class AbstractPaintListener implements PaintListener {
38
	
39
	/**
40
	 * A reference to the listener's view.
41
	 */
42
	protected AbstractView view_;
43
	
44
	/**
45
	 * Graph title
46
	 */
47
	protected String graphTitle_;
48
49
	/**
50
	 * X-axis label.
51
	 */
52
	protected String xAxisLabel_;
53
	/**
54
	 * Y-axis label.
55
	 */
56
	protected String yAxisLabel_;
57
	
58
	/**
59
	 * Horizontal offset for the x-axis label.
60
	 */
61
	protected int xAxisLabelOffset_;
62
	
63
	/**
64
	 * Vertical offset for the horizontal axis offset.
65
	 */
66
	protected int horizontalAxisYOffset_ = 20;
67
68
	/**
69
	 * Graph padding.
70
	 */
71
	protected int padding_ = Config.GRAPH_PADDING;
72
	
73
	/**
74
	 * Graph client area.
75
	 */
76
	protected Rectangle clientArea_ = new Rectangle(0, 0, 1, 1);
77
	
78
	/**
79
	 * Foreground color.
80
	 */
81
	protected Color foregroundColor_;
82
	/**
83
	 * Background color.
84
	 */
85
	protected Color backgroundColor_;
86
	/**
87
	 * Data plotting color.
88
	 */
89
	protected Color dataColor_;
90
	/**
91
	 * Axis label color.
92
	 */
93
	protected Color labelColor_;
94
	/**
95
	 * Text color.
96
	 */
97
	protected Color textColor_;
98
	/**
99
	 * Red.
100
	 */
101
	protected Color redColor_;
102
	/**
103
	 * White.
104
	 */
105
	protected Color whiteColor_;
106
	
107
	/**
108
	 * Original canvas font.
109
	 */
110
	protected Font originalFont_;
111
	/**
112
	 * Font for the title of the graph.
113
	 */
114
	protected Font titleFont_;
115
	/**
116
	 * Font for the values on the horizontal and vertical axis.
117
	 */
118
	protected Font valuesFont_;
119
	/**
120
	 * Font for the horizontal and vertical labels.
121
	 */
122
	protected Font labelFont_;
123
	
124
	/**
125
	 * Horizontal offset for the axis arrow.
126
	 */
127
	protected final int ARROW_DELTA_X = 10;
128
	/**
129
	 * Vertical offset for the axis arrow.
130
	 */
131
	protected final int ARROW_DELTA_Y =  4;
132
	
133
	/**
134
	 * Max horizontal distance between ticks.
135
	 */
136
	protected final int MAX_WIDTH_BETWEEN_TICKS  = 40;
137
	/**
138
	 * Max vertical distance between ticks.
139
	 */
140
	protected final int MAX_HEIGHT_BETWEEN_TICKS = 30;
141
	/**
142
	 * Max characters that can be displayed on the vertical axis.
143
	 */
144
	protected final int MAX_CHAR_VERTICAL_DISPLAY = 5;
145
	
146
	/**
147
	 * Draw label each "drawLabelEachNTicks_" ticks.
148
	 */
149
	protected int drawLabelEachNTicks_ = 1;
150
	
151
	/**
152
	 * Image drawn on the canvas.
153
	 */
154
	protected Image image_;
155
	/**
156
	 * Paint canvas, where the values are plotted.
157
	 */
158
	protected GC axisImage_;
159
	
160
	/**
161
	 * Is the paint listener initialized ?
162
	 */
163
	protected boolean initialised_ = false;
164
	/**
165
	 * Does the listener need to be redrawn ?
166
	 */
167
	protected boolean redraw_ = true;
168
	
169
	/**
170
	 * Draw area.
171
	 */
172
	protected Rectangle drawArea_;
173
	
174
	/**
175
	 * Left padding (in pixels).
176
	 */
177
	protected int paddingLeft_ = 10;
178
	/**
179
	 * Right padding (in pixels).
180
	 */
181
	protected int paddingRight_ = 10;
182
	/**
183
	 * Top padding (in pixels).
184
	 */
185
	protected int paddingTop_ = 10;
186
	/**
187
	 * Bottom padding (in pixels).
188
	 */
189
	protected int paddingBottom_ = 10;
190
	
191
	/**
192
	 * Vertical axis offset (in pixels).
193
	 */
194
	protected int verticalAxisOffset_ = 20;
195
	
196
	/**
197
	 * Vertical axis factor for values (10^delta).
198
	 * When values larger than MAX_CHAR_VERTICAL_DISPLAY.
199
	 */
200
	protected int delta = 0;
201
	
202
	
203
	/**
204
	 * Constructor.
205
	 * @param view A reference to the listener's view.
206
	 */
207
	public AbstractPaintListener(AbstractView view) {
208
		view_ = view;
209
	}
210
	
211
	@Override
212
	public void paintControl(PaintEvent e) {
213
		clientArea_ = view_.getClientArea();
214
		
215
		foregroundColor_ = e.gc.getForeground();
216
		backgroundColor_ = e.gc.getBackground();
217
		dataColor_      = e.gc.getDevice().getSystemColor(SWT.COLOR_RED);
218
		labelColor_      = e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
219
		textColor_       = e.gc.getDevice().getSystemColor(SWT.COLOR_DARK_GRAY);
220
		redColor_        = e.gc.getDevice().getSystemColor(SWT.COLOR_RED);
221
		whiteColor_      = e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE);
222
		
223
		originalFont_ = e.gc.getFont();
224
		titleFont_    = new Font(e.display, "Arial", 10, SWT.BOLD);
225
		valuesFont_   = new Font(e.display, "Arial", 7, SWT.NORMAL);
226
		labelFont_    = new Font(e.display, "Arial", 8, SWT.NORMAL);
227
228
229
		if (!initialised_) {
230
			image_ = new Image(Display.getDefault(), view_.getBounds());
231
			
232
			axisImage_ = new GC(image_);
233
			
234
			axisImage_.setForeground(foregroundColor_);
235
			axisImage_.setBackground(backgroundColor_);
236
			axisImage_.fillRectangle(image_.getBounds());
237
			paintBackground();
238
			
239
			initialised_ = true;
240
		}
241
		
242
		paintGraphTitle();
243
		paintHorizontalAxis();
244
		paintVerticalAxis();
245
		postAddDraw();
246
247
		e.gc.drawImage(image_, 0, 0);
248
		redraw_ = false;
249
	}
250
	
251
	/**
252
	 * Paints the title of the graph.
253
	 */
254
	public void paintGraphTitle() {
255
		if (graphTitle_ != null) {
256
			axisImage_.setFont(titleFont_);
257
			axisImage_.setForeground(labelColor_);
258
			axisImage_.setBackground(backgroundColor_);
259
260
			int zoomFactor = view_.getZoomFactor() / view_.getZoomIncrement() + 1;
261
			int labelWidth = axisImage_.stringExtent(graphTitle_).x;
262
			// Draws the zoom factor in the title only if there is one
263
			if (view_.getZoomFactor() > 1)
264
				axisImage_.drawText(graphTitle_+ " (" + zoomFactor + "x)", (view_.getBounds().width-padding_ - labelWidth)/2, 0);
265
			else
266
				axisImage_.drawText(graphTitle_, (view_.getBounds().width-padding_ - labelWidth)/2, 0);
267
		}
268
	}
269
	
270
	/**
271
	 * Paints the background of the draw area.
272
	 */
273
	public void paintBackground() {
274
		axisImage_.setBackground(whiteColor_);
275
		
276
		Rectangle rectangle = image_.getBounds();
277
		axisImage_.fillRectangle(padding_+verticalAxisOffset_, padding_+paddingTop_, rectangle.width-2*padding_-20, rectangle.height-2*padding_-paddingTop_-10);
278
	}
279
	
280
	/**
281
	 * Paints the horizontal axis.
282
	 */
283
	public void paintHorizontalAxis() {
284
		axisImage_.setForeground(foregroundColor_);
285
		
286
		int y = clientArea_.height - 2*padding_;
287
		
288
		axisImage_.drawLine( clientArea_.x+padding_+verticalAxisOffset_, 
289
				             y, 
290
				             clientArea_.width-padding_, 
291
				             y );
292
293
		paintHorizontalArrow(clientArea_.width-padding_, y);
294
		// Draw the axis graphic details only if there are some data points (i.e. do not draw the axis graphic details
295
		// if the window timerange is so small that no latency can be computed, or if there are no matching events in
296
		// the timerange (for example, when an experiment has many traces with a large time gap between the logged events sets).
297
		if (view_.getXMin() != Long.MAX_VALUE && view_.getXMax() != Long.MIN_VALUE && view_.getXMin() != view_.getXMax()) {
298
			paintHorizontalTicks(y);
299
			paintHorizontalAxisValues(y+30);
300
		}
301
		paintHorizontalAxisLabel(y+5);
302
	}
303
	
304
	/**
305
	 * Paints the vertical axis.
306
	 */
307
	public void paintVerticalAxis() {
308
		axisImage_.setForeground(foregroundColor_);
309
		
310
		int x = clientArea_.x + padding_ + verticalAxisOffset_;
311
		
312
		axisImage_.drawLine( x, 
313
				             clientArea_.y      + padding_, 
314
				             x, 
315
				             clientArea_.height - 2*padding_ );
316
		
317
		paintVerticalArrow(x, clientArea_.y + padding_);
318
		// Draw the axis graphic details only if there are some data points (i.e. do not draw the axis graphic details
319
		// if the window timerange is so small that no latency can be computed, or if there are no matching events in
320
		// the timerange (for example, when an experiment has many traces with a large time gap between the logged events sets).
321
		if (view_.getXMin() != Long.MAX_VALUE && view_.getXMax() != Long.MIN_VALUE && view_.getXMin() != view_.getXMax()) {
322
			//paintVerticalTicks(x);
323
			paintVerticalAxisValues(x);
324
		}
325
		paintVerticalAxisLabel(x);
326
	}
327
	
328
	/**
329
	 * Paints the arrow on the horizontal axis.
330
	 * @param x The x-coordinate of the point where the arrow points.
331
	 * @param y The y-coordinate of the point where the arrow points.
332
	 */
333
	public void paintHorizontalArrow(int x, int y) {
334
		// Arrow top line
335
		axisImage_.drawLine(x-ARROW_DELTA_X, y-ARROW_DELTA_Y, x, y);
336
		// Arrow bottom line
337
		axisImage_.drawLine(x-ARROW_DELTA_X, y+ARROW_DELTA_Y, x, y );
338
	}
339
340
	/**
341
	 * Paints the arrow on the vertical axis.
342
	 * @param x The x-coordinate of the point where the arrow points.
343
	 * @param y The y-coordinate of the point where the arrow points.
344
	 */
345
	public void paintVerticalArrow(int x, int y) {
346
		// Arrow left line
347
		axisImage_.drawLine(x-ARROW_DELTA_Y, y+ARROW_DELTA_X, x, y);
348
		// Arrow right line
349
		axisImage_.drawLine(x+ARROW_DELTA_Y, y+ARROW_DELTA_X, x, y);
350
	}
351
	
352
	/**
353
	 * Paints the horizontal ticks.
354
	 * @param y The y coordinate where to draw the axis.
355
	 */
356
	public void paintHorizontalTicks(int y) {
357
		long xMin = view_.getXMin();
358
		long xMax = view_.getXMax();
359
		
360
		if (xMin != 0L && xMax != 0L) {
361
			int nbTicks = (view_.getBounds().width - 2*padding_ - ARROW_DELTA_X - verticalAxisOffset_) / MAX_WIDTH_BETWEEN_TICKS - 1;
362
			
363
			for (int i = 0; i <= nbTicks+1; i++) {
364
				int x = i*MAX_WIDTH_BETWEEN_TICKS + padding_ + verticalAxisOffset_;
365
				axisImage_.drawLine(x, y, x, y+3);
366
			}
367
		}
368
	}
369
	
370
	/**
371
	 * Paints the horizontal axis values.
372
	 * @param y The y coordinate where to draw the axis.
373
	 */
374
	public void paintHorizontalAxisValues(int y) {
375
		long xMin = view_.getXMin();
376
		long xMax = view_.getXMax();
377
		
378
		if (xMin != 0L && xMax != 0L) {
379
			axisImage_.setForeground(textColor_);
380
			axisImage_.setBackground(backgroundColor_);
381
			
382
			int nbTicks = (view_.getBounds().width - 2*padding_ - ARROW_DELTA_X - verticalAxisOffset_) / MAX_WIDTH_BETWEEN_TICKS;
383
			//System.out.println("nbTicks = " + nbTicks);
384
			
385
			for (int i = 0; i < nbTicks; i++) {
386
				if (i % drawLabelEachNTicks_ == 0) {
387
					int x = i*MAX_WIDTH_BETWEEN_TICKS + padding_ + verticalAxisOffset_;
388
					
389
					double step = (double)(xMax-xMin) / (double)nbTicks;
390
					long currentValue = (long) (xMin + i*step);
391
					String currentLabel = formatStringForHorizontalAxis(currentValue);
392
					
393
					axisImage_.setFont(valuesFont_);
394
					axisImage_.drawText(currentLabel, x, y-24);
395
				}
396
			}
397
		}
398
	}
399
	
400
	/**
401
	 * Paints the horizontal axis label.
402
	 * @param y The y-coordinate where to draw the label.
403
	 */
404
	public void paintHorizontalAxisLabel(int y) {
405
		if (xAxisLabel_ != null) {
406
			axisImage_.setFont(labelFont_);
407
			axisImage_.setForeground(labelColor_);
408
			
409
			int labelWidth = axisImage_.stringExtent(xAxisLabel_).x;
410
			
411
			axisImage_.drawText(xAxisLabel_, view_.getBounds().width-padding_-labelWidth, y);
412
		}
413
	}
414
415
	/**
416
	 * Paints the vertical axis ticks.
417
	 * @param x The x-coordinate where to draw the ticks.
418
	 * @deprecated The vertical ticks are now drawn at the same time as the vertical axis values.
419
	 */
420
	public void paintVerticalTicks(int x) {
421
		long xMin = view_.getXMin();
422
		long xMax = view_.getXMax();
423
		
424
		if (xMin != 0L && xMax != 0L) {
425
			int nbTicks = (view_.getBounds().height-2*padding_-paddingTop_) / MAX_HEIGHT_BETWEEN_TICKS + 1;
426
			
427
			for (int i = 0; i <= nbTicks+1; i++) {
428
				int y = view_.getBounds().height - 2*padding_ - paddingTop_ - i*MAX_HEIGHT_BETWEEN_TICKS;
429
				axisImage_.drawLine(x-3, y+paddingTop_, x, y+paddingTop_);
430
			}
431
		}
432
	}
433
	
434
	/**
435
	 * Paints the vertical axis values.
436
	 * @param x The x-coordinate where to draw the values.
437
	 */
438
	public void paintVerticalAxisValues(int x) {
439
		long xMin = view_.getXMin();
440
		long xMax = view_.getXMax();
441
		int zoomFactor = 1;
442
		
443
		zoomFactor = view_.getZoomFactor();
444
445
		if (xMin != 0L && xMax != 0L) {
446
			axisImage_.setForeground(textColor_);
447
			axisImage_.setBackground(backgroundColor_);
448
			
449
			long yMin = view_.getYMin();
450
			// Apply the zoom to the max value of the graph for the next calculations
451
			long yMax = view_.getYMax() / zoomFactor;
452
							
453
			int nbTicks = (view_.getBounds().height-2*padding_-paddingTop_) / MAX_HEIGHT_BETWEEN_TICKS + 1;
454
			
455
			Vector<Integer> values = new Vector<Integer>();
456
			boolean multipleSameValues = true;
457
			while (multipleSameValues) {
458
				double valueStep = (double)(yMax-yMin) / (double)(nbTicks-1);
459
				
460
				for (int i = 0; i < nbTicks; i++) {
461
					double currentValue = (double) (yMin + i*valueStep)/(Math.pow(10, delta));
462
					
463
					values.add((int) currentValue);
464
				}
465
				
466
				Collections.sort(values);
467
				boolean hasRepetition = false;
468
				for (int i = 1; i < values.size(); i++) {
469
					if (values.get(i) == values.get(i-1)) {
470
						hasRepetition = true;
471
					}
472
				}
473
				
474
				if (hasRepetition) {
475
					nbTicks--;
476
					values.clear();
477
				} else {
478
					multipleSameValues = false;
479
480
					// Draw rectangle over the old values
481
					int height = view_.getBounds().height-4*padding_-paddingTop_;
482
					axisImage_.fillRectangle(0, padding_+paddingTop_, padding_+verticalAxisOffset_, height);
483
484
					double pixelStep = (getHeight() + 2.0*padding_ + paddingTop_ + 1)/*(view_.getBounds().height - 2*padding_ - 1*paddingTop_)*/ / values.size();
485
					
486
					for (int i = 0; i < values.size(); i++) {
487
						double currentValue = values.get(i);
488
						
489
						int y = (int) (view_.getBounds().height - 2*padding_ - i*pixelStep);
490
						String currentLabel = formatStringForVerticalAxis((long) currentValue);
491
						
492
						axisImage_.setFont(valuesFont_);
493
						
494
						Point textDimensions = axisImage_.stringExtent(currentLabel);
495
						axisImage_.drawText(currentLabel, x-textDimensions.x-5, y-textDimensions.y/2);
496
						axisImage_.drawLine(x-3, y, x, y);
497
					}
498
				}
499
			}
500
		}
501
	}
502
	
503
	/**
504
	 * Paints the vertical axis label.
505
	 * @param x The x-coordinate where to draw the label.
506
	 */
507
	public void paintVerticalAxisLabel(int x) {
508
		if (yAxisLabel_ != null) {
509
			axisImage_.setFont(labelFont_);
510
			axisImage_.setForeground(labelColor_);
511
			axisImage_.setBackground(backgroundColor_);
512
			
513
			if (delta >= 1)
514
				axisImage_.drawText(yAxisLabel_ + " (x10^" + delta + ")", x+10, paddingTop_-5);
515
			else 
516
				axisImage_.drawText(yAxisLabel_, x+10, paddingTop_-5);
517
		}
518
	}
519
	
520
	/**
521
	 * Adds points to the graph and draws them to the canvas.
522
	 * @param points The buffer of points to draw.
523
	 * @param nbPoints The number of points in the buffer.
524
	 */
525
	public abstract void addPoints(ChartPoint[] points, int nbPoints);
526
527
	/**
528
	 * Draw horizontal label each "nbTicks" ticks.
529
	 * @param nbTicks The draw interval.
530
	 */
531
	public void drawLabelEachNTicks(int nbTicks) {
532
		drawLabelEachNTicks_ = nbTicks;
533
	}
534
535
	/**
536
	 * Sets the title of the graph.
537
	 * @param graphTitle The title of the graph.
538
	 */
539
	public void setGraphTitle(String graphTitle) {
540
		graphTitle_ = graphTitle;
541
	}
542
543
	/**
544
	 * Sets the horizontal axis label.
545
	 * @param xAxisLabel The horizontal axis label.
546
	 * @param offset The horizontal axis draw offset (in pixels).
547
	 */
548
	public void setXAxisLabel(String xAxisLabel, int offset) {
549
		xAxisLabel_ = xAxisLabel;
550
		xAxisLabelOffset_ = offset;
551
	}
552
553
	/**
554
	 * Sets the vertical axis label.
555
	 * @param yAxisLabel The vertical axis label.
556
	 */
557
	public void setYAxisLabel(String yAxisLabel) {
558
		yAxisLabel_ = yAxisLabel;
559
	}
560
	
561
	/**
562
	 * Clears the image and prepares it for redrawing.
563
	 */
564
	public void clear() {
565
		initialised_ = false;
566
		view_.askForRedraw();
567
	}
568
	
569
	/**
570
	 * Returns a string representing the given value. This method is 
571
	 * redefined in "HistogramPaintListener.java" to convert value to 
572
	 * engineering notation.
573
	 * @param value The numeric value to convert to String.
574
	 * @return The String-formatted value.
575
	 */
576
	public String formatStringForHorizontalAxis(long value) {	
577
		return "" + value;
578
	}
579
	
580
	/**
581
	 * Returns a string representing the given value. This method is 
582
	 * redefined in "GraphPaintListener.java" to convert value to 
583
	 * scientific notation.
584
	 * @param value The numeric value to convert to String.
585
	 * @return The String-formatted value.
586
	 */
587
	public String formatStringForVerticalAxis(long value) {
588
		return "" + value;
589
	}
590
	
591
	/**
592
	 * Clears the points buffer, if any exists.
593
	 */
594
	public void clearPoints() { }
595
	
596
	/**
597
	 * Called for drawing elements after points are added to the graph.
598
	 */
599
	public void postAddDraw() { }
600
	
601
    /**
602
     * Returns the draw area height.
603
     * @return The draw area height.
604
     */
605
    public double getHeight() {
606
    	return (clientArea_.height - 2.0*padding_ - horizontalAxisYOffset_ - 0*paddingTop_ - 1);      
607
    }
608
    
609
    /**
610
     * Returns the histogram's draw area width.
611
     * @return The histogram's draw area width.
612
     */
613
    public double getWidth() {
614
    	return (clientArea_.width - 2.0*padding_ - verticalAxisOffset_);  //width of the plot area;
615
    }
616
    
617
    /**
618
     * Returns the histogram's draw area padding.
619
     * @return The histogram's draw area padding.
620
     */
621
    public int getPadding() {
622
    	return padding_;
623
    }
624
    
625
    /**
626
     * Returns the histogram's draw area top padding.
627
     * @return The histogram's draw area top padding.
628
     */
629
    public int getPaddingTop() {
630
    	return paddingTop_;
631
    }
632
    
633
    /**
634
     * Returns the histogram's vertical axis offset.
635
     * @return The histogram's vertical axis offset.
636
     */
637
    public int getVerticalAxisOffset() {
638
    	return verticalAxisOffset_;
639
    }
640
   
641
    /**
642
     * Returns the histogram's horizontal axis offset.
643
     * @return The histogram's horizontal axis offset.
644
     */
645
    public int getHorizontalAxisYOffset() {
646
    	return horizontalAxisYOffset_;
647
    }
648
	
649
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/GraphPaintListener.java (+77 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners;
13
14
import java.text.DecimalFormat;
15
16
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView;
17
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
18
19
20
/**
21
 * Graph paint listener.
22
 * 
23
 * @author Philippe Sawicki
24
 */
25
public class GraphPaintListener extends AbstractPaintListener {
26
27
	/**
28
	 * Constructor.
29
	 * @param view A reference to the listener's view.
30
	 */
31
	public GraphPaintListener(AbstractView view) {
32
		super(view);
33
	}
34
	
35
	/**
36
	 * Adds points to the graph and draws them to the canvas.
37
	 * @param points The buffer of points to draw.
38
	 * @param nbPoints The number of points in the buffer.
39
	 */
40
	public void addPoints(ChartPoint[] points, int nbPoints) {
41
		axisImage_.setForeground(dataColor_);
42
		axisImage_.setBackground(dataColor_);
43
		
44
		double width = clientArea_.width - 2.0*padding_ - verticalAxisOffset_;
45
		double height = clientArea_.height - 2.0*padding_ - paddingTop_ - horizontalAxisYOffset_ - 1;
46
		
47
		double xMin = view_.getXMin();
48
		double xMax = view_.getXMax();
49
		
50
		double yMin = view_.getYMin();
51
		double yMax = view_.getYMax();
52
		
53
		for (int i = 0; i < nbPoints; i++) {
54
			long pointX = points[i].getX();
55
			long pointY = points[i].getY();
56
			
57
			double x = padding_ + ((pointX-xMin) / (xMax-xMin)) * width + verticalAxisOffset_;
58
			double y = paddingTop_ + padding_ + height - ((pointY-yMin) / (yMax-yMin)) * height;
59
			
60
			axisImage_.fillOval((int)x, (int)y, 3, 3);
61
		}
62
		
63
		redraw_ = true;
64
		view_.askForRedraw();
65
	}
66
67
    /**
68
	 * Paints the vertical horizontal axis values in scientific notation in which the exponent is a multiple of three.
69
	 * @param value The numeric value to convert to scientific notation.
70
	 * @return The given value formatted according to the scientific notation.
71
	 */
72
    public String formatStringForVerticalAxis(long value) {
73
    	DecimalFormat formatter = new DecimalFormat("0.0E0"); 
74
		return formatter.format(value);
75
	}
76
77
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/HistogramPaintListener.java (+230 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners;
13
14
import java.text.DecimalFormat;
15
16
import org.eclipse.linuxtools.lttng.analysis.Config;
17
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView;
18
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
19
import org.eclipse.linuxtools.lttng.ui.views.latency.Messages;
20
import org.eclipse.swt.SWTException;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.ui.plugin.AbstractUIPlugin;
24
25
26
/**
27
 * Histogram paint listener.
28
 *
29
 * @author Philippe Sawicki
30
 */
31
public class HistogramPaintListener extends AbstractPaintListener {
32
	
33
	/**
34
	 * Histogram points buffer.
35
	 */
36
	protected ChartPoint[] points_;
37
	/**
38
	 * Number of points to consider in the buffer.
39
	 */
40
	protected int nbPoints_ = 0;
41
	
42
	/**
43
	 * Is a histogram bar so high that it is clipped from the draw area ?
44
	 */
45
	protected boolean barIsClipped_ = false;
46
	
47
48
    /**
49
     * Constructor.
50
     * @param view A reference to the listener's view.
51
     */
52
    public HistogramPaintListener(AbstractView view) {
53
        super(view);
54
    }
55
56
    /**
57
     * Adds points to the graph and draws them to the canvas.
58
     * @param points The buffer of points to draw.
59
     * @param nbPoints The number of points in the buffer.
60
       @author Philippe Sawicki, modified by Ali Jawhar
61
     */
62
    public void addPoints(ChartPoint[] points, int nbPoints) {
63
        points_ = points;
64
        nbPoints_ = nbPoints;
65
        
66
        // These lines must stay at the end of this function :
67
        redraw_ = true;
68
        Display.getDefault().syncExec(new Runnable() {
69
            public void run() {
70
            	try {
71
	            	postAddDraw();
72
	                view_.redraw();
73
            	} catch (SWTException e) {
74
            		// This exception will be thrown if the user closes the view
75
            		// while it is receiving data from the Analyser.
76
            		
77
            		// ...
78
            	}
79
            }
80
        });
81
    }
82
    
83
    public void postAddDraw() {
84
    	if (nbPoints_ == 0 || points_ == null)
85
    		return;
86
    	
87
    	/**
88
    	 * @todo Rethink this way of redrawing the histogram, because it starts getting crazy about here...
89
    	 */
90
    	double zoomFactor = view_.getZoomFactor();
91
    	
92
    	// Calculate the vertical axis factor and see if it has changed
93
    	double tmpDelta = delta;
94
    	delta = 0;
95
		if (Long.toString(view_.getYMax()/(long)zoomFactor).length() > MAX_CHAR_VERTICAL_DISPLAY){
96
			delta = Long.toString(view_.getYMax()/(long)zoomFactor).length() - MAX_CHAR_VERTICAL_DISPLAY;
97
		}
98
		if (tmpDelta != delta) {
99
			view_.clearBackground();
100
		}
101
		
102
		paintBackground();
103
    	paintVerticalAxis();
104
    	paintHorizontalAxis();
105
    	
106
    	axisImage_.setForeground(dataColor_);
107
        axisImage_.setBackground(dataColor_);
108
109
        //axisImage_.setBackground(backgroundColor_);
110
        // 1.a Iterate over the points, from 0 to nbPoints    
111
        // 1.b Find the max counter value
112
113
        long maxValue = points_[0].getY(); 
114
        for (int i = 1; i < nbPoints_; i++) {
115
        	if (points_[i].getY() > maxValue) {
116
        		maxValue = points_[i].getY();
117
        	}
118
        }
119
       
120
        // 2. Assign the max value to the "yMax_" class attribute
121
        view_.setYMax(maxValue);// set the maximum vertical value
122
       
123
        // 3. Draw the histogram bars using "axisImage_.fillRectangle(...)"
124
        // width of the plot area
125
        double width = clientArea_.width - 2.0*padding_ - verticalAxisOffset_;
126
        // height of the plot area
127
        double height = clientArea_.height - 2.0*padding_ - horizontalAxisYOffset_ - 1;
128
        
129
        double yMin = view_.getYMin();
130
        double yMax = view_.getYMax();
131
        double barWidth = width/(nbPoints_);
132
        
133
        boolean oneBarIsClipped = false;
134
        
135
        for (int i = 0; i < nbPoints_; i++) {
136
        	double pointY = points_[i].getY();
137
        	
138
        	// in pixels
139
        	double x = padding_ + i*barWidth + verticalAxisOffset_ + 1;
140
        	if (i == nbPoints_-1)
141
        		x -= 1.0;
142
        	double barHeight = zoomFactor * ((pointY-yMin) / (yMax-yMin)) * height;
143
        	
144
        	if (barHeight > height + 1) {
145
        		barHeight = height;
146
        		oneBarIsClipped = true;
147
        		
148
        		Image image = AbstractUIPlugin.imageDescriptorFromPlugin(
149
    					Messages.getString("LatencyView.tmf.UI"), 
150
    					"icons/warning.gif").createImage(Display.getCurrent());
151
        		axisImage_.drawImage(image, 5, 3);
152
        	}
153
        	
154
        	// Only draw the bars that have a barHeight of more than 1 pixel
155
        	if (barHeight >= 1) {
156
        		double y = 2*padding_ + height - barHeight;
157
        		axisImage_.setBackground(dataColor_);
158
        		
159
        		if (barHeight > height-1) {
160
        			axisImage_.fillRectangle((int)x, (int)y, (int)barWidth+1, (int)(barHeight+1));
161
        		} else {
162
        			axisImage_.fillRectangle((int)x, (int)y, (int)barWidth+1, (int)(barHeight+2));
163
        		}
164
        	}
165
        }
166
        
167
        if (oneBarIsClipped)
168
        	barIsClipped_ = true;
169
        else
170
        	barIsClipped_ = false;
171
    }
172
173
	/**
174
	 * Clears the image and prepares it for redrawing.
175
	 */
176
    public void clearPoints() {
177
    	points_ = new ChartPoint[nbPoints_];
178
    	for (int i = 0; i < points_.length; i++) {
179
    		points_[i] = new ChartPoint(0, 0);
180
    	}
181
    	//nbPoints_ = 0;
182
    	
183
    	view_.askForRedraw();
184
    }
185
186
    /**
187
	 * Paints the histogram horizontal axis values in engineering notation in which the exponent is a multiple of three.
188
	 * @param value The numeric value to convert to engineering notation.
189
	 * @return The given value formatted according to the engineering notation.
190
	 */
191
    public String formatStringForHorizontalAxis(long value) {
192
    	DecimalFormat formatter = new DecimalFormat("##0.#E0"); 
193
		return formatter.format(value);
194
	}
195
    
196
    /**
197
     * Returns the histogram's data points.
198
     * @return The histogram's data points.
199
     */
200
    public ChartPoint[] getPoints() {
201
    	return points_;
202
    }
203
    
204
    /**
205
     * Returns the histogram's number of data points.
206
     * @return The histogram's number of data points.
207
     */
208
    public int getNBPoints() {
209
    	return nbPoints_;
210
    }
211
    
212
    /**
213
     * Returns the histogram's bar Width.
214
     * @return The histogram's bar Width.
215
     */
216
    public double getBarWidth() {
217
    	if (clientArea_ == null)
218
    		return Config.HISTOGRAM_BAR_WIDTH;
219
    	return (clientArea_.width - 2.0*padding_ - verticalAxisOffset_) / nbPoints_;
220
    }
221
    
222
    /**
223
     * Returns "true" if a histogram bar is so high that it cannot be drawn in the draw area, "false" otherwise.
224
     * @return "true" if a histogram bar is so high that it cannot be drawn in the draw area, "false" otherwise.
225
     */
226
    public boolean barIsClipped() {
227
    	return barIsClipped_;
228
    }
229
    
230
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TimePointerListener.java (+73 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners;
13
14
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView;
15
16
17
/**
18
 * Displays a tooltip showing the approximate values of the point under
19
 * the mouse cursor.
20
 * 
21
 * @author Philippe Sawicki
22
 */
23
public class TimePointerListener extends AbstractMouseListener {
24
	
25
	/**
26
	 * A reference to the observed view.
27
	 */
28
	protected AbstractView view_;
29
	
30
	/**
31
	 * A reference to the HistogramPaintListener.
32
	 */
33
	protected GraphPaintListener graph_ ;
34
	
35
	
36
	/**
37
	 * Constructor.
38
	 * @param view A reference to the observed view.
39
	 * @param histogramPaintListener A reference to the histogram's paintListener.
40
	 */
41
	public TimePointerListener(AbstractView view, GraphPaintListener graphPaintListener) {
42
		view_ = view;
43
		graph_ = graphPaintListener;
44
	}
45
46
	@Override
47
	protected void display() {
48
		long chartWidth  = (long) graph_.getWidth();
49
		long chartHeight = (long) graph_.getHeight();
50
		
51
		mouseX_ -= graph_.getPadding() + graph_.getVerticalAxisOffset();
52
		mouseY_ -= graph_.getPadding() + graph_.getPaddingTop() + 1 ;
53
		mouseY_ = chartHeight - mouseY_; // Reverse the coordinates since (0;0) is a the top of the screen
54
		
55
		long xMin = view_.getXMin();
56
		long xMax = view_.getXMax();
57
		long yMin = view_.getYMin();
58
		long yMax = view_.getYMax();
59
		
60
		long xValue = mouseX_ * (xMax - xMin) / chartWidth  + xMin;
61
		long yValue = mouseY_ * (yMax - yMin) / chartHeight + yMin;
62
		
63
		if (mouseX_ > 0 && mouseX_ < chartWidth
64
			&& mouseY_ > 0 && mouseY_ < chartHeight
65
			&& xValue != 0L && yValue != 0L
66
			&& xValue != Long.MAX_VALUE && yValue != Long.MAX_VALUE) {
67
			view_.setToolTipText("(x;y) ≈ (" + xValue + ";" + yValue + ")");
68
		} else {
69
			view_.setToolTipText("");
70
		}
71
	}
72
73
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/TooltipListener.java (+108 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners;
13
14
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView;
15
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
16
17
18
/**
19
 * Tooltip listener, displays the event count for each latency selected 
20
 * by the mouse click area on histogram.
21
 * 
22
 * @author Ali Jawhar
23
 */
24
public class TooltipListener extends AbstractMouseListener {
25
	
26
	/**
27
	 * A reference to the observed view.
28
	 */
29
	protected AbstractView view_;
30
	
31
	/**
32
	 * A reference to the HistogramPaintListener.
33
	 */
34
	protected HistogramPaintListener histogram_ ;
35
	
36
	/**
37
	 * Is the mouse over the warning icon, indicating that a bar is higher than the draw area due to zooming ?
38
	 */
39
	boolean displayWarning_ = false;
40
	
41
	
42
	/**
43
	 * Constructor.
44
	 * @param view A reference to the observed view.
45
	 * @param histogramPaintListener A reference to the histogram's paintListener.
46
	 */
47
	public TooltipListener(AbstractView view, HistogramPaintListener histogramPaintListener) {
48
		view_ = view;
49
		histogram_ = histogramPaintListener;
50
	}
51
	
52
	@Override
53
	protected void display() {
54
		displayWarningTooltip();
55
		displayTooltip();
56
	}
57
	
58
	/**
59
	 * Displays a tooltip if the mouse is over the warning icon indication that a bar cannot be draw entirely
60
	 * due to the zoom factor.
61
	 */
62
	protected void displayWarningTooltip() {
63
		if (histogram_.barIsClipped()
64
			&& mouseX_ > 5 && mouseX_ < 21
65
			&& mouseY_ > 3 && mouseY_ < 18) {
66
			view_.setToolTipText("One or more bars is higher than the draw area due to zooming.");
67
			displayWarning_ = true;
68
		} else {
69
			displayWarning_ = false;
70
		}
71
	}
72
	
73
	/**
74
	 * Displays the tooltip showing the details of the histogram bar pointed
75
	 * by the mouse.
76
	 */
77
	protected void displayTooltip() {
78
		double barWidth = histogram_.getBarWidth();
79
		double height   = histogram_.getHeight();     // height of the plot area
80
		long yMin = view_.getYMin();
81
		long yMax = view_.getYMax();
82
		double zoomFactor = view_.getZoomFactor();
83
		int padding = histogram_.getPadding();
84
		int verticalAxisOffset = histogram_.getVerticalAxisOffset();
85
		ChartPoint[] points = histogram_.getPoints();
86
		int nbPoints = histogram_.getNBPoints();
87
		int index = (int)((mouseX_ - padding - verticalAxisOffset)/barWidth);
88
		
89
		double barHeight = 0.0;
90
		if (index >= 0 && index < nbPoints) {
91
			barHeight = (zoomFactor * height*(points[index].getY()-yMin) / (yMax-yMin));
92
		}
93
		mouseY_ = (long)height - (mouseY_ - 2*padding);
94
		
95
		// Verifying mouse pointer is over histogram bar
96
		if (index >= 0 && index < nbPoints && mouseY_ < barHeight && mouseY_ < height && mouseX_ > (verticalAxisOffset+padding)) {
97
			if (index+1 < nbPoints){
98
				view_.setToolTipText("(lat;#evt) = (["+points[index].getX()+ ","+(points[index+1].getX()-1)+"] ; " + points[index].getY() + ")");
99
			} else {
100
				long delta = points[index].getX() - points[index-1].getX();
101
				view_.setToolTipText("(lat;#evt) = (["+points[index].getX()+ ","+(points[index].getX()+delta-1)+"] ; " + points[index].getY() + ")");
102
			}
103
	    } else if (displayWarning_ == false) {
104
			view_.setToolTipText("");
105
		}
106
	}
107
108
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/listeners/ZoomListener.java (+113 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.ui.views.latency.listeners;
13
14
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.Canvas;
17
import org.eclipse.swt.widgets.Event;
18
import org.eclipse.swt.widgets.Listener;
19
20
/**
21
 * Canvas zoom listener.
22
 * 
23
 * @author Philippe Sawicki
24
 */
25
public class ZoomListener implements Listener {
26
	
27
	/**
28
	 * A reference to the observed view.
29
	 */
30
	protected AbstractView view_;
31
	/**
32
	 * Default zoom factor.
33
	 */
34
	protected int zoomFactor_;
35
	/**
36
	 * Zoom increment.
37
	 */
38
	protected int zoomIncrement_ = 30;
39
	
40
	
41
	/**
42
	 * Constructor.
43
	 * @param view A reference to the observed view.
44
	 * @param defaultZoomFactor Default zoom factor.
45
	 */
46
	public ZoomListener(AbstractView view, int defaultZoomFactor) {
47
		view_ = view;
48
		zoomFactor_ = defaultZoomFactor;
49
	}
50
	
51
	/**
52
	 * Constructor.
53
	 * @param view A reference to the observed view.
54
	 */
55
	public ZoomListener(AbstractView view) {
56
		this(view, 0);
57
	}
58
59
	/**
60
	 * Handles the event.
61
	 */
62
	public void handleEvent(Event event) {
63
		switch (event.type) {
64
			case SWT.MouseWheel:
65
				/**
66
				 * @todo Find a better way to get the mouse wheel scroll direction
67
				 */
68
				boolean scrollDown = (event.count == 0 ? false : (event.count > 0 ? false : true));
69
				int zoomStep = zoomIncrement_;
70
				if (scrollDown)
71
					zoomStep = -zoomIncrement_;
72
				zoomFactor_ = Math.max(0, zoomFactor_ + zoomStep);
73
				
74
				Canvas canvas = (Canvas)event.widget;
75
				if (view_ != null){
76
					// clear the background to allow redraw of values of the vertical axis. 
77
					view_.clearBackground();
78
					view_.redrawTitle();
79
					view_.askForRedraw();
80
				}
81
				canvas.redraw();
82
				break;
83
		}
84
	}
85
	
86
	/**
87
	 * Returns the zoom factor.
88
	 * @return The zoom factor.
89
	 */
90
	public int getZoomFactor() {
91
		if (zoomFactor_ < 1)
92
			return 1;
93
		else
94
			return zoomFactor_;
95
	}
96
	
97
	/**
98
	 * Returns the zoom increment.
99
	 * @return The zoom increment.
100
	 */
101
	public int getZoomIncrement() {
102
		return zoomIncrement_;
103
	}
104
	
105
	/**
106
	 * Sets the zoom increment.
107
	 * @param zoomIncrement The new zoom increment.
108
	 */
109
	public void setZoomIncrement(int zoomIncrement) {
110
		zoomIncrement_ = zoomIncrement;
111
	}
112
	
113
}
(-)src/org/eclipse/linuxtools/lttng/ui/views/latency/messages.properties (+44 lines)
Line 0 Link Here
1
LatencyView.Action.IncreaseBarWidth.Tooltip=Increase histogram bar width
2
LatencyView.Action.DecreaseBarWidth.Tooltip=Decrease histogram bar width
3
LatencyView.Action.AddEvents.Tooltip=Add matching events
4
LatencyView.Action.DeleteEvents.Tooltip=Deleted matching events
5
LatencyView.Action.ListEvents.Tooltip=List matching events
6
LatencyView.Dialogs.AddEvents.Title=Add event pairs
7
LatencyView.Dialogs.AddEvents.Message=Select a pair of events to add it to the match list :
8
LatencyView.Dialogs.AddEvents.Buttons.Add=Add
9
LatencyView.Dialogs.AddEvents.Buttons.Close=Close
10
LatencyView.Dialogs.AddEvents.Columns.Start=Start event types
11
LatencyView.Dialogs.AddEvents.Columns.End=End event types
12
LatencyView.Dialogs.AddEvents.Columns.List.Trigger=Trigger event type
13
LatencyView.Dialogs.AddEvents.Columns.List.End=End event type
14
LatencyView.Dialogs.AddEvents.Errors.NoSelection=You must select one item from both lists.
15
LatencyView.Dialogs.AddEvents.Errors.StartNotSelected=You must select one item from the start event list.
16
LatencyView.Dialogs.AddEvents.Errors.EndNotSelected=You must select one item from the end event list.
17
LatencyView.Dialogs.AddEvents.Errors.SameSelected=The same event cannot be selected in both list at the same time.
18
LatencyView.Dialogs.AddEvents.Errors.AlreadyMatched=The start and end events are already matched.
19
LatencyView.Dialogs.AddEvents.Errors.StartAlreadyMatched=The start event is already matched.
20
LatencyView.Dialogs.AddEvents.Errors.EndAlreadyMatched=The end event is already matched.
21
LatencyView.Dialogs.AddEvents.Errors.StartAsEnd=The start event is already matched as an end event.
22
LatencyView.Dialogs.AddEvents.Errors.EndAsStart=The end event is already matched as a start event.
23
LatencyView.Dialogs.DeleteEvents.Title=Delete event pairs
24
LatencyView.Dialogs.DeleteEvents.Message=Select a pair of matched events to remove it from the list :
25
LatencyView.Dialogs.DeleteEvents.Buttons.Close=Close
26
LatencyView.Dialogs.DeleteEvents.Buttons.Delete=Delete
27
LatencyView.Dialogs.DeleteEvents.Confirm.Title=Confirm event deletion
28
LatencyView.Dialogs.DeleteEvents.Confirm.Message=Are you sure you want to delete these event pairs?
29
LatencyView.Dialogs.ListEvents.Title=Matched events list
30
LatencyView.Dialogs.ListEvents.Message=List of matched events for latency computation :
31
LatencyView.Dialogs.ListEvents.Buttons.Close=Close
32
LatencyView.Dialogs.ListEvents.Buttons.Reset=Reset to default pairs
33
LatencyView.Dialogs.ListEvents.Columns.Trigger=Trigger event type
34
LatencyView.Dialogs.ListEvents.Columns.End=End event type
35
LatencyView.Dialogs.ListEvents.Confirm.Title=Confirm pairs reset
36
LatencyView.Dialogs.ListEvents.Confirm.Message=Are you sure you want to reset the event pairs to their default values?
37
LatencyView.Graphs.Graph.Title=Latency VS Time
38
LatencyView.Graphs.Graph.XAxisLabel=time (ns)
39
LatencyView.Graphs.Graph.YAxisLabel=latency (ms)
40
LatencyView.Graphs.Histogram.Title=Latency Distribution
41
LatencyView.Graphs.Histogram.XAxisLabel=latency (ns)
42
LatencyView.Graphs.Histogram.YAxisLabel=# events
43
LatencyView.msgSlogan=Latency View
44
LatencyView.tmf.UI=org.eclipse.linuxtools.lttng.ui
(-)src/org/eclipse/linuxtools/lttng/analysis/Config.java (+94 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis;
13
14
15
/**
16
 * Configuration class, holds some application constants.
17
 * 
18
 * @author Philippe Sawicki
19
 */
20
public class Config {
21
	
22
	/**
23
	 * Private constructor to defeat instantiation.
24
	 */
25
	private Config() { }
26
	
27
	
28
	/**
29
	 * Size of the point buffer holding point values before sending them to the view.
30
	 */
31
	public static final int POINT_BUFFER_SIZE = 5000;
32
	
33
	/**
34
	 * Histogram bar width.
35
	 */
36
	public static int HISTOGRAM_BAR_WIDTH = 5;
37
	
38
	/**
39
	 * Diameter of a point drawn on the chart (in pixels).
40
	 */
41
	public static final int GRAPH_POINT_DIAMETER = 1;
42
	
43
	/**
44
	 * Graph padding.
45
	 */
46
	public static final int GRAPH_PADDING = 10;
47
	
48
	/**
49
	 * Write computed data value to .csv files ?
50
	 */
51
	public static final boolean WRITE_COMPUTED_DATA_TO_FILE = false;
52
	
53
	/**
54
	 * Print all debug info to the console ?
55
	 */
56
	public static final boolean PRINT_ALL = false;
57
	
58
	/**
59
	 * Print state changes info to the console ?
60
	 */
61
	public static final boolean PRINT_STATE_CHANGES = (PRINT_ALL ? true : false);
62
	/**
63
	 * Print state constructors info to the console ?
64
	 */
65
	public static final boolean PRINT_STATE_CONSTRUCTOR = (PRINT_ALL ? true : false);
66
	
67
	/**
68
	 * Print counter state info to the console ?
69
	 */
70
	public static final boolean PRINT_COUNTER_STATE_STATUS = (PRINT_ALL ? true : false);
71
	/**
72
	 * Print empty state info to the console ?
73
	 */
74
	public static final boolean PRINT_EMPTY_STATE_STATUS = (PRINT_ALL ? true : false);
75
	/**
76
	 * Print time range state info to the console ?
77
	 */
78
	public static final boolean PRINT_TIMERANGE_STATE_STATUS = (PRINT_ALL ? true : false);
79
	
80
	/**
81
	 * Print graph view info to the console ?
82
	 */
83
	public static final boolean PRINT_GRAPH_VIEW_STATUS = (PRINT_ALL ? true : false);
84
	/**
85
	 * Print histogram view info to the console ?
86
	 */
87
	public static final boolean PRINT_HISTO_VIEW_STATUS = (PRINT_ALL ? true : false);
88
	
89
	/**
90
	 * Print added points info to the console ?
91
	 */
92
	public static final boolean PRINT_INTERFACE_POINT_ADD = (PRINT_ALL ? false : false);
93
	
94
}
(-)src/org/eclipse/linuxtools/lttng/analysis/InterfaceMediator.java (+278 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis;
13
14
import java.util.Vector;
15
16
import org.eclipse.linuxtools.lttng.analysis.analyser.Analyser;
17
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair;
18
import org.eclipse.linuxtools.lttng.ui.views.latency.AbstractView;
19
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
20
import org.eclipse.linuxtools.lttng.ui.views.latency.GraphView;
21
import org.eclipse.linuxtools.lttng.ui.views.latency.HistogramView;
22
import org.eclipse.linuxtools.lttng.ui.views.latency.handlers.ViewHandler;
23
24
25
/**
26
 * Interface mediator.
27
 * 
28
 * @author Philippe Sawicki
29
 */
30
public class InterfaceMediator implements ViewHandler {
31
	
32
	/**
33
	 * Class instance (Singleton pattern).
34
	 */
35
	private static InterfaceMediator instance_;
36
	
37
	/**
38
	 * List of graph views registered for analyser updates.
39
	 */
40
	private Vector<GraphView> graphViews_;
41
	/**
42
	 * List of histogram views registered for analyser updates.
43
	 */
44
	private Vector<HistogramView> histogramViews_;
45
	
46
	/**
47
	 * Graph point buffer.
48
	 */
49
	private ChartPoint[] graphPoints_;
50
	/**
51
	 * Histogram point buffer.
52
	 */
53
	private ChartPoint[] histogramPoints_;
54
	/**
55
	 * Point counter.
56
	 */
57
	private int pointCounter_;
58
59
	/**
60
	 * The number of bars available in the histogram views.
61
	 */
62
	protected int nbBars_;
63
	
64
	
65
	/**
66
	 * Private constructor to defeat instantiation (Singleton pattern).
67
	 */
68
	private InterfaceMediator() {
69
		graphViews_     = new Vector<GraphView>();
70
		histogramViews_ = new Vector<HistogramView>();
71
		
72
		graphPoints_     = new ChartPoint[Config.POINT_BUFFER_SIZE];
73
		pointCounter_ = 0;
74
	}
75
	
76
	/**
77
	 * Returns an instance of the InterfaceMediator (Singleton pattern).
78
	 * @return An instance of the InterfaceMediator.
79
	 */
80
	public static InterfaceMediator getInstance() {
81
		if (instance_ == null)
82
			instance_ = new InterfaceMediator();
83
		return instance_;
84
	}
85
	
86
	/**
87
	 * Releases the instance of the InterfaceMediator.
88
	 */
89
	public static void releaseInstance() {
90
		instance_ = null;
91
	}
92
	
93
	/**
94
	 * Registers a graph view to be notified of updates.
95
	 * @param view The graph view to notify about updates.
96
	 */
97
	public void registerGraphView(GraphView view) {
98
		view.setViewHandler(this);
99
		graphViews_.add(view);
100
	}
101
	
102
	/**
103
	 * Registers a histogram view to be notified of updates.
104
	 * @param view The histogram view to notify about updates.
105
	 */
106
	public void registerHistogramView(HistogramView view) {
107
		view.setViewHandler(this);
108
		histogramViews_.add(view);
109
	}
110
	
111
	/**
112
	 * Unregisters the views from the mediator.
113
	 */
114
	public void unregisterViews() {
115
		// Unregister the InterfaceMediator as the view handler from the views.
116
		for (AbstractView view : graphViews_) {
117
			view.setViewHandler(null);
118
		}
119
		graphViews_.clear();
120
		
121
		// Unregister the InterfaceMediator as the view handler from the views.
122
		for (HistogramView view : histogramViews_) {
123
			view.setViewHandler(null);
124
		}
125
		histogramViews_.clear();
126
	}
127
	
128
	/**
129
	 * Clears the view.
130
	 */
131
	public void clearViews() {
132
		for (GraphView view : graphViews_) {
133
			view.clear();
134
			view.clearBackground();
135
		}
136
		for (HistogramView view : histogramViews_) {
137
			view.clear();
138
			view.clearBackground();
139
		}
140
	}
141
	
142
	
143
	/**
144
	 * Clears the point buffer.
145
	 */
146
	public void clearPointsBuffer() {
147
		graphPoints_ = new ChartPoint[Config.POINT_BUFFER_SIZE];
148
		
149
		pointCounter_ = 0;
150
	}
151
	
152
	/**
153
	 * Resets the histogram data points.
154
	 */
155
	public void clearHistogramData() {
156
		for (int i = 0; i < histogramViews_.size(); i++) {
157
			histogramViews_.get(i).clearPoints();
158
		}
159
	}
160
	
161
	/**
162
	 * Sets the horizontal axis values for the graph views.
163
	 * @param xMin The min x-axis value.
164
	 * @param xMax The max x-axis value.
165
	 */
166
	public void pushHorizontalAxisForGraph(long xMin, long xMax) {
167
		for (AbstractView view : graphViews_) {
168
			view.setXMin(xMin);
169
			view.setXMax(xMax);
170
		}
171
	}
172
	
173
	/**
174
	 * Sets the vertical axis values for the graph views.
175
	 * @param yMin The min y-axis value.
176
	 * @param yMax The max y-axis value.
177
	 */
178
	public void pushVerticalAxisForGraph(long yMin, long yMax) {
179
		for (AbstractView view : graphViews_) {
180
			view.setYMin(yMin);
181
			view.setYMax(yMax);
182
		}
183
	}
184
	
185
	/**
186
	 * Sets the horizontal axis values for the histogram views.
187
	 * @param xMin The min x-axis value.
188
	 * @param xMax The max x-axis value.
189
	 */
190
	public void pushHorizontalAxisForHistogram(long xMin, long xMax) {
191
		for (AbstractView view : histogramViews_) {
192
			view.setXMin(xMin);
193
			view.setXMax(xMax);
194
		}
195
	}
196
	
197
	/**
198
	 * Adds a point to the graph views.
199
	 * @param graphPoint The point to add to the graph views.
200
	 * @param histogramPoint The point to add to the histogram views.
201
	 */
202
	public void addPointToViews(ChartPoint graphPoint, Pair<Integer,ChartPoint> histogramPoint) {
203
		graphPoints_[pointCounter_] = graphPoint;
204
		histogramPoints_[histogramPoint.getFirst()] = histogramPoint.getSecond(); 
205
		pointCounter_++;
206
		
207
		if (Config.PRINT_INTERFACE_POINT_ADD)
208
			System.out.println("Adding a new point to the buffer (size = " + pointCounter_ + ") ; (x;y) = (" + graphPoint.getX() + ";" + graphPoint.getY() + ")");
209
		
210
		if (pointCounter_ == Config.POINT_BUFFER_SIZE) {
211
			pushPointsToViews();
212
			clearPointsBuffer();
213
		}
214
	}
215
	
216
	/**
217
	 * Pushes the point buffer to the views.
218
	 */
219
	public void pushPointsToViews() {
220
		if (pointCounter_ != 0) {
221
			for (AbstractView view : graphViews_) {
222
				view.addPoints(graphPoints_, pointCounter_);
223
			}
224
		}
225
		
226
		for (AbstractView view : histogramViews_) {
227
			view.addPoints(histogramPoints_, histogramPoints_.length);
228
		}
229
	}
230
231
	/**
232
	 * Push the standard latencies array to the histogram views.
233
	 * @param standardLatencies The standard latencies array to push to the views.
234
	 */
235
	public void pushStandardLatenciesToViews(double[] standardLatencies) {
236
		histogramPoints_ = new ChartPoint[standardLatencies.length];
237
		for (int i = 0; i < standardLatencies.length; i++) {
238
			histogramPoints_[i] = new ChartPoint((long)standardLatencies[i], 0L);
239
		}
240
	}
241
	
242
	/**
243
	 * Redraws the views.
244
	 */
245
	public void redrawViews() {
246
		for (int i = 0; i < graphViews_.size(); i++) {
247
			graphViews_.get(i).askForRedraw();
248
		}
249
		for (int i = 0; i < histogramViews_.size(); i++) {
250
			histogramViews_.get(i).askForRedraw();
251
		}
252
	}
253
	
254
	/**
255
	 * Returns the maximum number of bars in the histogram views.
256
	 * @return The maximum number of bars in the histogram views.
257
	 */
258
	public int getMaxBarNumberFromViews() {
259
		return nbBars_;
260
	}
261
	
262
	/**
263
	 * Analyses the latency for all event types.
264
	 */
265
	public void analyseLatencyForAllEvents() {
266
		Analyser.getInstance().analyseLatencyForAllEvents();
267
	}
268
269
	/**
270
	 * Sets the number of bars available in the histogram views.
271
	 * @param nbBars The number of bars available in the histogram views.
272
	 */
273
	@Override
274
	public void notifyNumberOfBars(int nbBars) {
275
		nbBars_ = nbBars;
276
	}
277
278
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/Analyser.java (+80 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser;
13
14
import org.eclipse.linuxtools.lttng.analysis.analyser.states.AnalyserState;
15
import org.eclipse.linuxtools.lttng.analysis.analyser.states.MinMaxLatencyState;
16
17
/**
18
 * Analyser class, computes latencies in a trace, following the State pattern.
19
 * 
20
 * @author Philippe Sawicki
21
 */
22
public class Analyser {
23
	
24
	/**
25
	 * Class instance (Singleton pattern).
26
	 */
27
	private static Analyser instance_;
28
	
29
	/**
30
	 * Analyser state (State pattern).
31
	 */
32
	private AnalyserState state_;
33
	
34
	
35
	/**
36
	 * Private constructor to defeat instantiation (Singleton pattern).
37
	 */
38
	private Analyser() {
39
		
40
	}
41
	
42
	/**
43
	 * Returns an instance of the Analyser.
44
	 * @return An instance of the Analyser.
45
	 */
46
	public static Analyser getInstance() {
47
		if (instance_ == null)
48
			instance_ = new Analyser();
49
		return instance_;
50
	}
51
	
52
	/**
53
	 * Releases the instance of the Analyser.
54
	 */
55
	public static void releaseInstance() {
56
		instance_ = null;
57
	}
58
	
59
	/**
60
	 * Changes the state of the analyser (State pattern).
61
	 * @param newState The new state of the analyser.
62
	 */
63
	public void changeState(AnalyserState newState) {
64
		state_ = newState;
65
		
66
		if (state_ != null)
67
			state_.process();
68
	}
69
	
70
	/**
71
	 * Analyses the latency for all types of events.
72
	 */
73
	public void analyseLatencyForAllEvents() {
74
		// If a state is currently active, cancel it before starting the new one
75
		if (state_ != null)
76
			state_.handleCancel();
77
		changeState( new MinMaxLatencyState() );
78
	}
79
	
80
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/EventMatcher.java (+491 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.matcher;
13
14
import java.util.Collection;
15
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.Map.Entry;
19
import java.util.Set;
20
import java.util.Stack;
21
import java.util.Vector;
22
23
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair;
24
import org.eclipse.linuxtools.lttng.event.LttngEvent;
25
26
27
/**
28
 * Event matching class. Saves events in a list a returns the previously saved
29
 * event if the currently processed one is its response, so that the latency
30
 * can be computed by subtracting their respective timestamps.
31
 * 
32
 * @author Philippe Sawicki
33
 */
34
public class EventMatcher {
35
	
36
	/**
37
	 * Class instance (Singleton pattern).
38
	 */
39
	private static EventMatcher instance_ = null;
40
	
41
	/**
42
	 * Stack abstraction, used to save the events in a list.
43
	 */
44
	private StackWrapper stack_;
45
	
46
	/**
47
	 * Match table, associates a request class to a response class.
48
	 */
49
	private HashMap<String,String> match_;
50
	/**
51
	 * Inverse match table, associates a response class to a request class.
52
	 */
53
	private HashMap<String,String> inverseMatch_;
54
	
55
	/**
56
	 * The number of events processed.
57
	 */
58
	private int processedEvents_;
59
	/**
60
	 * The number of events matched.
61
	 */
62
	private int matchedEvents_;
63
	
64
	/**
65
	 * Event types identification Strings.
66
	 */
67
	public static String
68
		ADD_TO_PAGE_CACHE         = "add_to_page_cache",
69
		BIO_BACKMERGE             = "bio_backmerge",
70
		BIO_FRONTMERGE            = "bio_frontmerge",
71
		BIO_QUEUE                 = "bio_queue",
72
		BUFFER_WAIT_END           = "buffer_wait_end",
73
		BUFFER_WAIT_START         = "buffer_wait_start",
74
		CALL                      = "call",
75
		CLOSE                     = "close",
76
		CORE_MARKER_FORMAT        = "core_marker_format",
77
		CORE_MARKER_ID            = "core_marker_id",
78
		DEV_RECEIVE               = "dev_receive",
79
		DEV_XMIT                  = "dev_xmit",
80
		END_COMMIT                = "end_commit",
81
		EXEC                      = "exec",
82
		FILE_DESCRIPTOR           = "file_descriptor",
83
		GETRQ                     = "getrq",
84
		GETRQ_BIO                 = "getrq_bio",
85
		IDT_TABLE                 = "idt_table",
86
		INTERRUPT                 = "interrupt",
87
		IOCTL                     = "ioctl",
88
		IRQ_ENTRY                 = "irq_entry",
89
		IRQ_EXIT                  = "irq_exit",
90
		LIST_MODULE               = "list_module",
91
		LLSEEK                    = "llseek",
92
		LSEEK                     = "lseek",
93
		NAPI_COMPLETE             = "napi_complete",
94
		NAPI_POLL                 = "napi_poll",
95
		NAPI_SCHEDULE             = "napi_schedule",
96
		NETWORK_IPV4_INTERFACE    = "network_ipv4_interface",
97
		NETWORK_IP_INTERFACE      = "network_ip_interface",
98
		OPEN                      = "open",
99
		PAGE_FAULT_ENTRY          = "page_fault_entry",
100
		PAGE_FAULT_EXIT           = "page_fault_exit",
101
		PAGE_FAULT_GET_USER_ENTRY = "page_fault_get_user_entry",
102
		PAGE_FAULT_GET_USER_EXIT  = "page_fault_get_user_exit",
103
		PAGE_FREE                 = "page_free",
104
		PLUG                      = "plug",
105
		POLLFD                    = "pollfd",
106
		PREAD64                   = "pread64",
107
		PRINTF                    = "printf",
108
		PRINTK                    = "printk",
109
		PROCESS_EXIT              = "process_exit",
110
		PROCESS_FORK              = "process_fork",
111
		PROCESS_FREE              = "process_free",
112
		PROCESS_STATE             = "process_state",
113
		PROCESS_WAIT              = "process_wait",
114
		READ                      = "read",
115
		REMAP                     = "remap",
116
		REMOVE_FROM_PAGE_CACHE    = "remove_from_page_cache",
117
		RQ_COMPLETE_FS            = "rq_complete_fs",
118
		RQ_COMPLETE_PC            = "rq_complete_pc",
119
		RQ_INSERT_FS              = "rq_insert_fs",
120
		RQ_INSERT_PC              = "rq_insert_pc",
121
		RQ_ISSUE_FS               = "rq_issue_fs",
122
		RQ_ISSUE_PC               = "rq_issue_pc",
123
		RQ_REQUEUE_PC             = "rq_requeue_pc",
124
		SCHED_MIGRATE_TASK        = "sched_migrate_task",
125
		SCHED_SCHEDULE            = "sched_schedule",
126
		SCHED_TRY_WAKEUP          = "sched_try_wakeup",
127
		SCHED_WAKEUP_NEW_TASK     = "sched_wakeup_new_task",
128
		SELECT                    = "select",
129
		SEM_CREATE                = "sem_create",
130
		SEND_SIGNAL               = "send_signal",
131
		SHM_CREATE                = "shm_create",
132
		SLEEPRQ_BIO               = "sleeprq_bio",
133
		SOCKET_ACCEPT             = "socket_accept",
134
		SOCKET_BIND               = "socket_bind",
135
		SOCKET_CALL               = "socket_call",
136
		SOCKET_CONNECT            = "socket_connect",
137
		SOCKET_CREATE             = "socket_create",
138
		SOCKET_GETPEERNAME        = "socket_getpeername",
139
		SOCKET_GETSOCKNAME        = "socket_getsockname",
140
		SOCKET_GETSOCKOPT         = "socket_getsockopt",
141
		SOCKET_LISTEN             = "socket_listen",
142
		SOCKET_SETSOCKOPT         = "socket_setsockopt",
143
		SOCKET_SHUTDOWN           = "socket_shutdown",
144
		SOCKET_SOCKETPAIR         = "socket_socketpair",
145
		SOFTIRQ_ENTRY             = "softirq_entry",
146
		SOFTIRQ_EXIT              = "softirq_exit",
147
		SOFTIRQ_RAISE             = "softirq_raise",
148
		SOFTIRQ_VEC               = "softirq_vec",
149
		START_COMMIT              = "start_commit",
150
		STATEDUMP_END             = "statedump_end",
151
		SYS_CALL_TABLE            = "sys_call_table",
152
	    SYSCALL_ENTRY             = "syscall_entry",
153
	    SYSCALL_EXIT              = "syscall_exit",
154
	    TASKLET_LOW_ENTRY         = "tasklet_low_entry",
155
	    TASKLET_LOW_EXIT          = "tasklet_low_exit",
156
	    TCPV4_RCV                 = "tcpv4_rcv",
157
	    TIMER_ITIMER_EXPIRED      = "timer_itimer_expired",
158
	    TIMER_ITIMER_SET          = "timer_itimer_set",
159
	    TIMER_SET                 = "timer_set",
160
	    TIMER_TIMEOUT             = "timer_timeout",
161
	    TIMER_UPDATE_TIME         = "timer_update_time",
162
	    UDPV4_RCV                 = "udpv4_rcv",
163
	    UNPLUG_IO                 = "unplug_io",
164
	    UNPLUG_TIMER              = "unplug_timer",
165
	    VM_MAP                    = "vm_map",
166
	    VPRINTK                   = "vprintk",
167
	    WAIT_ON_PAGE_END          = "wait_on_page_end",
168
	    WAIT_ON_PAGE_START        = "wait_on_page_start",
169
	    WRITE                     = "write",
170
	    WRITEV                    = "writev";
171
	
172
	
173
	/**
174
	 * Private constructor to defeat instantiation (Singleton pattern).
175
	 */
176
	private EventMatcher() {
177
		stack_ = new StackWrapper();
178
		match_ = new HashMap<String,String>();
179
		inverseMatch_ = new HashMap<String,String>();
180
		
181
		processedEvents_ = 0;
182
		matchedEvents_ = 0;
183
		
184
		createMatchTable();
185
	}
186
	
187
	/**
188
	 * Returns an instance to the EventMatcher class (Singleton pattern).
189
	 * @return An instance to the EventMatcher class (Singleton pattern).
190
	 */
191
	public static EventMatcher getInstance() {
192
		if (instance_ == null) 
193
			instance_ = new EventMatcher();
194
		return instance_;
195
	}
196
	
197
	/**
198
	 * Releases the instance to the EventMatcher class.
199
	 */
200
	public static void releaseInstance() {
201
		instance_ = null;		
202
	}
203
	
204
	/**
205
	 * Creates the event matching table, linking a response class to a 
206
	 * request class.
207
	 */
208
	private void createMatchTable() {
209
		// Build the default matches
210
		match_.put(PAGE_FAULT_GET_USER_EXIT, PAGE_FAULT_GET_USER_ENTRY);
211
		match_.put(TASKLET_LOW_EXIT, TASKLET_LOW_ENTRY);
212
		match_.put(PAGE_FAULT_EXIT, PAGE_FAULT_ENTRY);
213
		match_.put(SYSCALL_EXIT, SYSCALL_ENTRY);
214
		match_.put(IRQ_EXIT, IRQ_ENTRY);
215
		match_.put(WRITE, READ);
216
		match_.put(CLOSE, OPEN);
217
		match_.put(BUFFER_WAIT_END, BUFFER_WAIT_START);
218
		match_.put(END_COMMIT, START_COMMIT);
219
		match_.put(WAIT_ON_PAGE_END, WAIT_ON_PAGE_START);
220
		
221
		// Build the inverse matches based on the matches
222
		Set<Entry<String,String>> pairs = match_.entrySet();
223
		Iterator<Entry<String,String>> it = pairs.iterator();
224
		while (it.hasNext()) {
225
			Entry<String,String> pair = it.next();
226
			inverseMatch_.put(pair.getValue(), pair.getKey());
227
		}
228
	}
229
	
230
	/**
231
	 * Processes an event received: if it is identified as a response, try to
232
	 * get its request to remove it from the list. If no request was saved, 
233
	 * dismiss the current response. If it is a request, save it to the list of
234
	 * requests waiting for a response.
235
	 * @param event The event to identify, and maybe process if it is a response.
236
	 * @return The request event associated with the current event (a response), 
237
	 * or null if nothing was found (no request associated with this response, or
238
	 * the event to identify was a request that was added to the list).
239
	 */
240
	public LttngEvent process(LttngEvent event) {
241
		processedEvents_++;
242
		
243
		String markerName = event.getMarkerName();
244
		
245
		if (match_.containsKey(markerName)) {
246
			String startEventType = match_.get(markerName);
247
			Stack<LttngEvent> events = stack_.getStackOf(startEventType);
248
			
249
			if (events != null) {
250
				for (int i = events.size()-1; i >= 0; i--) {
251
					LttngEvent request = events.get(i);
252
					
253
					if (request.getCpuId() == event.getCpuId() &&
254
						event.getTimestamp().getValue() > request.getTimestamp().getValue()) {
255
						stack_.removeEvent(startEventType, request);
256
						matchedEvents_++;
257
						return request;
258
					}
259
				}
260
			}
261
			return null;
262
		} else {
263
			// Add only if there can later be a match for this request
264
			if (match_.containsValue(event.getMarkerName())) {
265
				stack_.put(event.clone());
266
			}
267
			return null;
268
		}
269
	}
270
	
271
	/**
272
	 * Clears the stack content.
273
	 */
274
	public void clearStack() {
275
		stack_.clear();
276
		
277
		// Reset the processed and matched events counter
278
		processedEvents_ = 0;
279
		matchedEvents_   = 0;
280
	}
281
	
282
	/**
283
	 * Resets all.
284
	 */
285
	public void resetMatches() {
286
		match_.clear();
287
		inverseMatch_.clear();
288
		
289
		stack_.clear();
290
		
291
		// Reset the processed and matched events counter
292
		processedEvents_ = 0;
293
		matchedEvents_   = 0;
294
	}
295
296
	/**
297
	 * Returns the list of start events.
298
	 * @return The list of start events.
299
	 */
300
	public Collection<String> getStartEvents() {
301
		return match_.values();
302
	}
303
304
	/**
305
	 * Returns the list of end events.
306
	 * @return The list of end events.
307
	 */
308
	public Set<String> getEndEvents() {
309
		return match_.keySet();
310
	}
311
	
312
	/**
313
	 * Returns the alphabetically-sorted list of start/end events pairs.
314
	 * @return The alphabetically-sorted list of start/end events pairs.
315
	 */
316
	public Pair<Vector<String>,Vector<String>> getEvents() {
317
		Vector<String> start = new Vector<String>( getStartEvents() );
318
		Vector<String> end   = new Vector<String>( match_.size() );
319
		
320
		Collections.sort(start);
321
		for (int i = 0; i < start.size(); i++) {
322
			end.add( inverseMatch_.get(start.get(i)) );
323
		}
324
		
325
		return new Pair<Vector<String>,Vector<String>>(start, end);
326
	}
327
	
328
	/**
329
	 * Adds a match to the list of events pairs.
330
	 * @param startType The start event type.
331
	 * @param endType The end event type.
332
	 */
333
	public void addMatch(String startType, String endType) {
334
		match_.put(endType, startType);
335
		inverseMatch_.put(startType, endType);
336
	}
337
338
	/**
339
	 * Removes a matched pair based on the their type.
340
	 * 
341
	 * <b>Note :</b> For now, only the pair's end type is used, since a type
342
	 * can only be either one start or one end. This function takes both types
343
	 * to account for the future, if a pairing process ever becomes more complex.
344
	 * 
345
	 * @param startType The type of the pair's start type.
346
	 * @param endType The type of the pair's end type.
347
	 */
348
	public void removeMatch(String startType, String endType) {
349
		match_.remove(endType);
350
		inverseMatch_.remove(startType);
351
	}
352
	
353
	/**
354
	 * Returns the list of all event possible types.
355
	 * @return The list of all event possible types.
356
	 */
357
	public Vector<String> getTypeList() {
358
		// Reserve some space for the 103 default event types.
359
		Vector<String> eventsList = new Vector<String>(103);
360
		
361
		eventsList.add(ADD_TO_PAGE_CACHE);
362
		eventsList.add(BIO_BACKMERGE);
363
		eventsList.add(BIO_FRONTMERGE);
364
		eventsList.add(BIO_QUEUE);
365
		eventsList.add(BUFFER_WAIT_END);
366
		eventsList.add(BUFFER_WAIT_START);
367
		eventsList.add(CALL);
368
		eventsList.add(CLOSE);
369
		eventsList.add(CORE_MARKER_FORMAT);
370
		eventsList.add(CORE_MARKER_ID);
371
		eventsList.add(DEV_RECEIVE);
372
		eventsList.add(DEV_XMIT);
373
		eventsList.add(END_COMMIT);
374
		eventsList.add(EXEC);
375
		eventsList.add(FILE_DESCRIPTOR);
376
		eventsList.add(GETRQ);
377
		eventsList.add(GETRQ_BIO);
378
		eventsList.add(IDT_TABLE);
379
		eventsList.add(INTERRUPT);
380
		eventsList.add(IOCTL);
381
		eventsList.add(IRQ_ENTRY);
382
		eventsList.add(IRQ_EXIT);
383
		eventsList.add(LIST_MODULE);
384
		eventsList.add(LLSEEK);
385
		eventsList.add(LSEEK);
386
		eventsList.add(NAPI_COMPLETE);
387
		eventsList.add(NAPI_POLL);
388
		eventsList.add(NAPI_SCHEDULE);
389
		eventsList.add(NETWORK_IPV4_INTERFACE);
390
		eventsList.add(NETWORK_IP_INTERFACE);
391
		eventsList.add(OPEN);
392
		eventsList.add(PAGE_FAULT_ENTRY);
393
		eventsList.add(PAGE_FAULT_EXIT);
394
		eventsList.add(PAGE_FAULT_GET_USER_ENTRY);
395
		eventsList.add(PAGE_FAULT_GET_USER_EXIT);
396
		eventsList.add(PAGE_FREE);
397
		eventsList.add(PLUG);
398
		eventsList.add(POLLFD);
399
		eventsList.add(PREAD64);
400
		eventsList.add(PRINTF);
401
		eventsList.add(PRINTK);
402
		eventsList.add(PROCESS_EXIT);
403
		eventsList.add(PROCESS_FORK);
404
		eventsList.add(PROCESS_FREE);
405
		eventsList.add(PROCESS_STATE);
406
		eventsList.add(PROCESS_WAIT);
407
		eventsList.add(READ);
408
		eventsList.add(REMAP);
409
		eventsList.add(REMOVE_FROM_PAGE_CACHE);
410
		eventsList.add(RQ_COMPLETE_FS);
411
		eventsList.add(RQ_COMPLETE_PC);
412
		eventsList.add(RQ_INSERT_FS);
413
		eventsList.add(RQ_INSERT_PC);
414
		eventsList.add(RQ_ISSUE_FS);
415
		eventsList.add(RQ_ISSUE_PC);
416
		eventsList.add(RQ_REQUEUE_PC);
417
		eventsList.add(SCHED_MIGRATE_TASK);
418
		eventsList.add(SCHED_SCHEDULE);
419
		eventsList.add(SCHED_TRY_WAKEUP);
420
		eventsList.add(SCHED_WAKEUP_NEW_TASK);
421
		eventsList.add(SELECT);
422
		eventsList.add(SEM_CREATE);
423
		eventsList.add(SEND_SIGNAL);
424
		eventsList.add(SHM_CREATE);
425
		eventsList.add(SLEEPRQ_BIO);
426
		eventsList.add(SOCKET_ACCEPT);
427
		eventsList.add(SOCKET_BIND);
428
		eventsList.add(SOCKET_CALL);
429
		eventsList.add(SOCKET_CONNECT);
430
		eventsList.add(SOCKET_CREATE);
431
		eventsList.add(SOCKET_GETPEERNAME);
432
		eventsList.add(SOCKET_GETSOCKNAME);
433
		eventsList.add(SOCKET_GETSOCKOPT);
434
		eventsList.add(SOCKET_LISTEN);
435
		eventsList.add(SOCKET_SETSOCKOPT);
436
		eventsList.add(SOCKET_SHUTDOWN);
437
		eventsList.add(SOCKET_SOCKETPAIR);
438
		eventsList.add(SOFTIRQ_ENTRY);
439
		eventsList.add(SOFTIRQ_EXIT);
440
		eventsList.add(SOFTIRQ_RAISE);
441
		eventsList.add(SOFTIRQ_VEC);
442
		eventsList.add(START_COMMIT);
443
		eventsList.add(STATEDUMP_END);
444
		eventsList.add(SYS_CALL_TABLE);
445
		eventsList.add(SYSCALL_ENTRY);
446
		eventsList.add(SYSCALL_EXIT);
447
		eventsList.add(TASKLET_LOW_ENTRY);
448
		eventsList.add(TASKLET_LOW_EXIT);
449
		eventsList.add(TCPV4_RCV);
450
		eventsList.add(TIMER_ITIMER_EXPIRED);
451
		eventsList.add(TIMER_ITIMER_SET);
452
		eventsList.add(TIMER_SET);
453
		eventsList.add(TIMER_TIMEOUT);
454
		eventsList.add(TIMER_UPDATE_TIME);
455
		eventsList.add(UDPV4_RCV);
456
		eventsList.add(UNPLUG_IO);
457
		eventsList.add(UNPLUG_TIMER);
458
		eventsList.add(VM_MAP);
459
		eventsList.add(VPRINTK);
460
		eventsList.add(WAIT_ON_PAGE_END);
461
		eventsList.add(WAIT_ON_PAGE_START);
462
		eventsList.add(WRITE);
463
		eventsList.add(WRITEV);
464
		
465
		return eventsList;
466
	}
467
	
468
	/**
469
	 * Returns the number of events processed.
470
	 * @return The number of events processed.
471
	 */
472
	public int getNBProcessedEvents() {
473
		return processedEvents_;
474
	}
475
	
476
	/**
477
	 * Returns the number of events matched.
478
	 * @return The number of events matched.
479
	 */
480
	public int getNBMatchedEvents() {
481
		return matchedEvents_;
482
	}
483
	
484
	/**
485
	 * Prints the stack content to the console.
486
	 */
487
	public void print() {
488
		stack_.printContent();
489
	}
490
	
491
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/matcher/StackWrapper.java (+141 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.matcher;
13
14
import java.util.Collection;
15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.Set;
18
import java.util.Stack;
19
20
import org.eclipse.linuxtools.lttng.event.LttngEvent;
21
22
23
/**
24
 * Stack pile.
25
 * 
26
 * TODO Change the types of the HashMaps from <String,String> to 
27
 * <Integer,Integer>, in order to take advantage of the compilation-time
28
 * String.hashCode() speedup over execution-time String hash computation.
29
 * 
30
 * @author Philippe Sawicki
31
 */
32
public class StackWrapper {
33
	
34
	/**
35
	 * Hash map of event stacks.
36
	 */
37
	private HashMap<String,Stack<LttngEvent>> stacks_ = null;
38
	
39
	
40
	/**
41
	 * Constructor.
42
	 */
43
	public StackWrapper() {
44
		stacks_ = new HashMap<String,Stack<LttngEvent>>();
45
	}
46
	
47
	/**
48
	 * Adds an event to the list of events of the same type.
49
	 * @param event The event to add to the list.
50
	 */
51
	public void put(LttngEvent event) {
52
		String key = event.getMarkerName();
53
		
54
		if (stacks_.containsKey(key)) {
55
			stacks_.get(key).add(event);
56
		} else {
57
			Stack<LttngEvent> newStack = new Stack<LttngEvent>();
58
			newStack.add(event);
59
			stacks_.put(key, newStack);
60
		}
61
	}
62
	
63
	/**
64
	 * Checks if the stack contains a list of events of the given type.
65
	 * @param key The type of events to check for.
66
	 * @return "true" if the stack contains events of the given type, "false" otherwise.
67
	 */
68
	public boolean containsKey(String key) {
69
		return stacks_.containsKey(key);
70
	}
71
	
72
	/**
73
	 * Returns the list of events of the given type.
74
	 * @param key The type of events to return.
75
	 * @return The list of events of the given type, or null.
76
	 */
77
	public Stack<LttngEvent> getStackOf(String key) {
78
		if (stacks_.containsKey(key)) {
79
			return stacks_.get(key);
80
		} else {
81
			return null;
82
		}
83
	}
84
	
85
	/**
86
	 * Removes the given event from the given stack list.
87
	 * @param key The given stack type.
88
	 * @param event The event to remove from the given stack type.
89
	 * @return "true" if the event was removed, "false" otherwise.
90
	 */
91
	public boolean removeEvent(String key, LttngEvent event) {
92
		Stack<LttngEvent> stack = stacks_.get(key);
93
		
94
		boolean removed = false;
95
96
		try {
97
			/**
98
			 * TODO Correct this...
99
			 * Here, no matter what CPU or other content field, we always 
100
			 * remove the last event added to the stack. Should be 
101
			 * something like :
102
			 * return stack.remove(event);
103
			 */
104
			stack.pop();
105
			removed = true;
106
		} catch (Exception e) {
107
			e.printStackTrace();
108
		}
109
110
		// Remove the stack from the stack list if it is empty
111
		if (stack.isEmpty()) {
112
			stacks_.remove(key);
113
		}
114
		
115
		return removed;
116
	}
117
	
118
	/**
119
	 * Clears the stack content.
120
	 */
121
	public void clear() {
122
		stacks_.clear();
123
	}
124
	
125
	/**
126
	 * Prints the content of the stack to the console.
127
	 */
128
	public void printContent() {
129
		Collection<Stack<LttngEvent>> values = stacks_.values();
130
		Iterator<Stack<LttngEvent>> valueIt = values.iterator();
131
		
132
		Set<String> keys = stacks_.keySet();
133
		Iterator<String> keyIt = keys.iterator();
134
		
135
		while ( valueIt.hasNext() && keyIt.hasNext() ) {
136
			Stack<LttngEvent> stack = valueIt.next();
137
			
138
			System.out.println( "   " + keyIt.next() + " [" + stack.size() + "] : " + stack );
139
		}
140
	}
141
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/states/AnalyserState.java (+91 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.states;
13
14
import org.eclipse.linuxtools.lttng.analysis.Config;
15
import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator;
16
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
17
import org.eclipse.linuxtools.lttng.analysis.facade.DataHandler;
18
19
20
/**
21
 * Abstract analyser state.
22
 * 
23
 * @author Philippe Sawicki
24
 */
25
public abstract class AnalyserState extends DataHandler {
26
	
27
	/**
28
	 * State name.
29
	 */
30
	protected String stateName_;
31
	
32
	/**
33
	 * The state's next state.
34
	 */
35
	protected AnalyserState nextState_;
36
	
37
	/**
38
	 * Is the state cancelled ?
39
	 */
40
	protected boolean isCancelled_ = false;
41
	
42
	
43
	/**
44
	 * Abstract analyser state constructor.
45
	 * @param stateName The state name.
46
	 * @param nextState The state's next state.
47
	 */
48
	public AnalyserState(String stateName, AnalyserState nextState) {
49
		stateName_ = stateName;
50
		nextState_ = nextState;
51
		
52
		if (Config.PRINT_STATE_CONSTRUCTOR)
53
			System.out.println("[" + stateName_ + "]");
54
	}
55
	
56
	/**
57
	 * Abstract analyser state constructor.
58
	 * @param stateName The state name.
59
	 */
60
	public AnalyserState(String stateName) {
61
		this(stateName, null);
62
		
63
		isCancelled_ = false;
64
	}
65
	
66
	/**
67
	 * Process the state.
68
	 */
69
	public abstract void process();
70
	
71
	/**
72
	 * Cancel the state's activity (i.e. clear the stack and redraw the views).
73
	 */
74
	public void handleCancel() {
75
		isCancelled_ = true;
76
		
77
		EventMatcher.getInstance().clearStack();
78
		InterfaceMediator.getInstance().clearHistogramData();
79
		InterfaceMediator.getInstance().clearPointsBuffer();
80
		InterfaceMediator.getInstance().clearViews();
81
	}
82
	
83
	/**
84
	 * Returns the state's name.
85
	 * @return The state's name.
86
	 */
87
	public String getName() {
88
		return stateName_;
89
	}
90
91
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/states/CounterState.java (+107 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.states;
13
14
import org.eclipse.linuxtools.lttng.analysis.Config;
15
import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator;
16
import org.eclipse.linuxtools.lttng.analysis.analyser.Analyser;
17
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
18
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.EventCountPerLatency;
19
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair;
20
import org.eclipse.linuxtools.lttng.analysis.facade.TraceFacade;
21
import org.eclipse.linuxtools.lttng.event.LttngEvent;
22
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
23
import org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView;
24
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
25
import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
26
27
28
/**
29
 * Counts the event latencies.
30
 * 
31
 * @author Philippe Sawicki
32
 */
33
public class CounterState extends AnalyserState {
34
	
35
	/**
36
	 * Event counter, used to generate bar graphs.
37
	 */
38
	private EventCountPerLatency eventCounter_;
39
	
40
	/**
41
	 * Min trace latency.
42
	 */
43
	private long minLatency_;
44
	/**
45
	 * Max trace latency.
46
	 */
47
	private long maxLatency_;
48
	
49
50
	/**
51
	 * Constructor.
52
	 * @param minLatency Min trace latency.
53
	 * @param maxLatency Max trace latency.
54
	 */
55
	public CounterState(long minLatency, long maxLatency) {
56
		super("Counter state");
57
		
58
		minLatency_ = minLatency;
59
		maxLatency_ = maxLatency;
60
		
61
		eventCounter_ = new EventCountPerLatency();
62
		
63
		int nbBars = InterfaceMediator.getInstance().getMaxBarNumberFromViews();
64
		eventCounter_.generateStandardLatencies(minLatency_, maxLatency_, nbBars);
65
		InterfaceMediator.getInstance().pushStandardLatenciesToViews( eventCounter_.getStandardLatencies() );
66
	}
67
68
	@Override
69
	public void process() {
70
		if (Config.PRINT_COUNTER_STATE_STATUS)
71
			System.out.println("  CounterState.process()");
72
73
		TmfExperiment<LttngEvent> experiment = LatencyView.getExperiment();
74
		
75
		TmfTimeRange timeRange = LatencyView.getTimeRange();
76
		
77
		TraceFacade.getInstance().getAllEvents(experiment, timeRange, this);
78
	}
79
80
	@Override
81
	public void handleData(LttngEvent event) {
82
		if (isCancelled_)
83
			return;
84
		
85
		LttngEvent startEvent = EventMatcher.getInstance().process(event);
86
		
87
		if (startEvent != null) {
88
			long latency = event.getTimestamp().getValue() - startEvent.getTimestamp().getValue();
89
			ChartPoint timeValue = new ChartPoint(startEvent.getTimestamp().getValue(), latency);
90
			Pair<Integer,ChartPoint> numberValue = eventCounter_.updateStandardCounter(latency);
91
			
92
			InterfaceMediator.getInstance().addPointToViews( timeValue, numberValue );
93
		}
94
	}
95
	
96
	public void handleCompleted() {
97
		if (isCancelled_)
98
			return;
99
		
100
		EventMatcher.getInstance().clearStack();
101
		InterfaceMediator.getInstance().pushPointsToViews();
102
		InterfaceMediator.getInstance().redrawViews();
103
		
104
		Analyser.getInstance().changeState( new EmptyState() );
105
	}
106
107
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/states/EmptyState.java (+45 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.states;
13
14
import org.eclipse.linuxtools.lttng.analysis.Config;
15
import org.eclipse.linuxtools.lttng.event.LttngEvent;
16
17
18
/**
19
 * Empty state, for demonstration only.
20
 * 
21
 * @author Philippe Sawicki
22
 */
23
public class EmptyState extends AnalyserState {
24
25
	/**
26
	 * Constructor.
27
	 */
28
	public EmptyState() {
29
		super("Empty state");
30
	}
31
32
	@Override
33
	public void process() {
34
		if (Config.PRINT_EMPTY_STATE_STATUS) 
35
			System.out.println("  EmptyState.process()");
36
		
37
		// Nothing to do here...
38
	}
39
40
	@Override
41
	public void handleData(LttngEvent event) {
42
		
43
	}
44
45
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/states/MinMaxLatencyState.java (+108 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.states;
13
14
import org.eclipse.linuxtools.lttng.analysis.Config;
15
import org.eclipse.linuxtools.lttng.analysis.InterfaceMediator;
16
import org.eclipse.linuxtools.lttng.analysis.analyser.Analyser;
17
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
18
import org.eclipse.linuxtools.lttng.analysis.facade.TraceFacade;
19
import org.eclipse.linuxtools.lttng.event.LttngEvent;
20
import org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView;
21
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
22
import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
23
24
/**
25
 * State used to find out the min an max values for the view's horizontal axis.
26
 * 
27
 * @author Philippe Sawicki
28
 */
29
public class MinMaxLatencyState extends AnalyserState {
30
	
31
	/**
32
	 * Min latency time.
33
	 */
34
	private long latencyMin_;
35
	/**
36
	 * Max latency time.
37
	 */
38
	private long latencyMax_;
39
	
40
	/**
41
	 * Min trace time.
42
	 */
43
	private long timeMin_;
44
	/**
45
	 * Max trace time.
46
	 */
47
	private long timeMax_;
48
	
49
50
	/**
51
	 * Constructor.
52
	 */
53
	public MinMaxLatencyState() {
54
		super("Min max latency state");
55
		
56
		// Initialise min and max latency times with some values
57
		latencyMin_ = Long.MAX_VALUE;
58
		latencyMax_ = Long.MIN_VALUE;
59
		
60
		// Initialise min and max trace times with some values
61
		timeMin_ = Long.MAX_VALUE;
62
		timeMax_ = Long.MIN_VALUE;
63
	}
64
65
	public void process() {
66
		if (Config.PRINT_TIMERANGE_STATE_STATUS)
67
			System.out.println("  MinMaxLatencyState()");
68
69
		TmfExperiment<LttngEvent> experiment = LatencyView.getExperiment();
70
		
71
		TmfTimeRange timeRange = LatencyView.getTimeRange();
72
		
73
		TraceFacade.getInstance().getAllEvents(experiment, timeRange, this);
74
	}
75
76
	@Override
77
	public void handleData(LttngEvent event) {
78
		if (isCancelled_)
79
			return;
80
		
81
		LttngEvent startEvent = EventMatcher.getInstance().process(event);
82
		
83
		if (startEvent != null) {
84
			long latency = event.getTimestamp().getValue() - startEvent.getTimestamp().getValue();
85
			
86
			latencyMax_ = Math.max(latencyMax_, latency);
87
			latencyMin_ = Math.min(latencyMin_, latency);
88
		}
89
		
90
		
91
		timeMin_ = Math.min(timeMin_, event.getTimestamp().getValue());
92
		timeMax_ = Math.max(timeMax_, event.getTimestamp().getValue());
93
	}
94
	
95
	public void handleCompleted() {
96
		if (isCancelled_)
97
			return;
98
		
99
		EventMatcher.getInstance().clearStack();
100
		
101
		InterfaceMediator.getInstance().pushHorizontalAxisForGraph(timeMin_, timeMax_);
102
		InterfaceMediator.getInstance().pushVerticalAxisForGraph(latencyMin_, latencyMax_);
103
		InterfaceMediator.getInstance().pushHorizontalAxisForHistogram(latencyMin_, latencyMax_);
104
		
105
		Analyser.getInstance().changeState( new CounterState(latencyMin_, latencyMax_) );
106
	}
107
108
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/EventCountPerLatency.java (+135 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Ali Jawar - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.utilities;
13
14
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
15
16
17
/**
18
 * This class generates dynamically the standard latencies and updates the 
19
 * event count for each bin/bucket.
20
 * 
21
 * Standards latencies values are generated dynamically and depend to three 
22
 * variables: minLatency, maxLatency, nbBar.
23
 * 
24
 * <ul>
25
 * <li><em>minLatency</em> is the smallest latency value</li>
26
 * <li><em>maxLatency</em> is the biggest latency value</li>
27
 * <li><em>nbBar</em> is the number of divisions along the axis of latencies</li>
28
 * </ul>
29
 * 
30
 * Algorithm complexity: O(1)... actually O(<em>nbBar</em>) but <em>nbBar</em> 
31
 * is limited to a constant.
32
 * 
33
 * @author Ali Jawhar
34
 * @author Philippe Sawicki
35
 */
36
public class EventCountPerLatency {
37
	
38
	/**
39
	 * Standard latencies values.
40
	 */
41
	private double[] standardLatencies_;
42
	
43
	/**
44
	 * One counter for each standard latency.
45
	 */
46
	private int[] standardCounter_;
47
	
48
	/**
49
	 * Distance between each latency.
50
	 */
51
	private double delta_;
52
	
53
	/**
54
	 * Minimum latency.
55
	 */
56
	private long minLatency_;
57
	
58
	
59
	/**
60
	 * Constructor.
61
	 */
62
	public EventCountPerLatency() {
63
		
64
	}
65
	
66
	/**
67
	 * Method to generate the standard latencies table.
68
	 * 
69
	 * @param minLatency Latency min.
70
	 * @param maxLatency Latency max.
71
	 * @param nbBars Number of bars in the histogram graph.
72
	 */
73
	public void generateStandardLatencies(long minLatency, long maxLatency, int nbBars) {
74
		delta_ = (double)(maxLatency-minLatency) / nbBars;
75
		minLatency_ = minLatency;
76
		
77
		// Initialisation of standard counter table
78
		standardCounter_ = new int[nbBars+1]; // one counter for each standard latency
79
		for (int i = 0; i < standardCounter_.length; i++) { // initiate counters values
80
			standardCounter_[i] = 0;
81
		}
82
		
83
		// Create standard latencies table
84
		standardLatencies_ = new double[nbBars+1];
85
		
86
		for (int i = 0 ; i < standardLatencies_.length; i++) {
87
			standardLatencies_[i] = minLatency + (i * delta_);
88
		}
89
	}
90
	
91
	/**
92
	 * Updates the standard latencies counter.
93
	 * @param latency The latency to add to the counter.
94
	 * @return The new updates values (index of standard latency ; new counter value).
95
	 */
96
	public Pair<Integer,ChartPoint> updateStandardCounter(long latency) {
97
		int index = 0;
98
		index = (int)((latency - minLatency_) / delta_);
99
		standardCounter_[index]++;
100
		ChartPoint point = new ChartPoint((long)standardLatencies_[index], standardCounter_[index]);
101
		return new Pair<Integer,ChartPoint>(index, point);
102
	}
103
104
	/**
105
	 * Prints the standard latencies table.
106
	 */
107
	public void printStandardLatencies() {
108
		System.out.print("The standard latencies table is: ");
109
		
110
		for (int i = 0; i < standardLatencies_.length; i++) {
111
			System.out.print(standardLatencies_[i] + " ");
112
		}
113
		System.out.println();
114
	}
115
	
116
	/**
117
	 * Prints the event count per standard latency.
118
	 */
119
	public void printEventCountPerStandardLatency() {
120
		System.out.println("here is the Event count per standard latency: "); 
121
		
122
		for (int j = 0; j < standardLatencies_.length; j++) {			
123
			System.out.println("latency = " + standardLatencies_[j] + "  EventCount = " + standardCounter_[j]);	
124
		}
125
	}
126
127
	/**
128
	 * Returns the standard latencies table.
129
	 * @return The standard latencies table.
130
	 */
131
	public double[] getStandardLatencies() {
132
		return standardLatencies_;
133
	}
134
135
}
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/utilities/Pair.java (+119 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.analyser.utilities;
13
14
15
/**
16
 * Pair utility class, encapsulates a pair of objects.
17
 * 
18
 * @author Philippe Sawicki
19
 *
20
 * @param <A> The type of the first object.
21
 * @param <B> The type of the second object.
22
 */
23
public class Pair<A,B> {
24
	
25
	/**
26
	 * A reference to the first object.
27
	 */
28
	protected A first_;
29
	/**
30
	 * A reference to the second object.
31
	 */
32
	protected B second_;
33
	
34
	
35
	/**
36
	 * Constructor.
37
	 * @param first The pair's first object.
38
	 * @param second The pair's second object.
39
	 */
40
	public Pair(A first, B second) {
41
		first_  = first;
42
		second_ = second;
43
	}
44
	
45
	/**
46
	 * Constructor.
47
	 */
48
	public Pair() {
49
		this(null, null);
50
	}
51
	
52
	/**
53
	 * Pair hash code.
54
	 */
55
	public int hashCode() {
56
		int hashFirst = first_ != null ? first_.hashCode() : 0;
57
		int hashSecond = second_ != null ? second_.hashCode() : 0;
58
		
59
		return (hashFirst + hashSecond) * hashSecond + hashFirst;
60
	}
61
	
62
	/**
63
	 * Object comparison.
64
	 */
65
	@SuppressWarnings("unchecked")
66
	public boolean equals(Object other) {
67
		if (other instanceof Pair) {
68
			Pair<A,B> otherPair = (Pair<A,B>) other;
69
			return (
70
				( first_ == otherPair.first_ ||
71
					( first_ != null && otherPair.first_ != null &&
72
					  first_.equals(otherPair.first_))) &&
73
				( second_ == otherPair.second_ ||
74
					( second_ != null && otherPair.second_ != null &&
75
					  second_.equals(otherPair.second_)))
76
			);
77
		}
78
		return false;
79
	}
80
	
81
	/**
82
	 * Object to string.
83
	 */
84
	public String toString() {
85
		return "(" + first_ + ", " + second_ + ")";
86
	}
87
	
88
	/**
89
	 * Returns a reference to the pair's first object.
90
	 * @return A reference to the pair's first object.
91
	 */
92
	public A getFirst() {
93
		return first_;
94
	}
95
	
96
	/**
97
	 * Sets the pair's first object.
98
	 * @param first The pair's first object.
99
	 */
100
	public void setFirst(A first) {
101
		first_ = first;
102
	}
103
	
104
	/**
105
	 * Returns a reference to the pair's second object.
106
	 * @return A reference to the pair's second object.
107
	 */
108
	public B getSecond() {
109
		return second_;
110
	}
111
	
112
	/**
113
	 * Sets the pair's second object.
114
	 * @param second The pair's second object.
115
	 */
116
	public void setSecond(B second) {
117
		second_ = second;
118
	}
119
}
(-)src/org/eclipse/linuxtools/lttng/analysis/facade/DataHandler.java (+51 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.facade;
13
14
import org.eclipse.linuxtools.lttng.event.LttngEvent;
15
16
/**
17
 * Data handler interface.
18
 *
19
 * Classes who want to register to the TraceFacade to receive data must implement
20
 * this class's interface.
21
 *
22
 * @author Philippe Sawicki
23
 */
24
public abstract class DataHandler {
25
26
    /**
27
     * Handles the data received from TraceFacade.
28
     */
29
    public abstract void handleData(LttngEvent event);
30
    
31
    /**
32
     * Handles transaction completion.
33
     */
34
    public void handleCompleted() { }
35
    
36
    /**
37
     * Handles transaction success.
38
     */
39
    public void handleSuccess() { }
40
    
41
    /**
42
     * Handles transaction failure.
43
     */
44
    public void handleFailure() { }
45
    
46
    /**
47
     * Handles transaction cancellation.
48
     */
49
    public void handleCancel() { }
50
51
}
(-)src/org/eclipse/linuxtools/lttng/analysis/facade/TraceFacade.java (+140 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Ericsson
3
 * 
4
 * All rights reserved. This program and the accompanying materials are
5
 * made available under the terms of the Eclipse Public License v1.0 which
6
 * accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *   Philippe Sawicki (INF4990.A2010@gmail.com) - Initial API and implementation
11
 *******************************************************************************/
12
package org.eclipse.linuxtools.lttng.analysis.facade;
13
14
import org.eclipse.linuxtools.lttng.event.LttngEvent;
15
import org.eclipse.linuxtools.tmf.event.TmfEvent;
16
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
17
import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
18
import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
19
import org.eclipse.linuxtools.tmf.request.TmfEventRequest;
20
21
22
/**
23
 * Facade for obtaining traced events through TMF given their type and/or timerange.
24
 *
25
 * @author Philippe Sawicki
26
 */
27
public class TraceFacade {
28
29
    /**
30
     * TraceFacade instance (Singleton pattern).
31
     */
32
    private static TraceFacade instance_ = null;
33
    
34
    /**
35
     * Private constructor to defeat instantiation (Singleton pattern).
36
     */
37
    private TraceFacade() { }
38
39
    /**
40
     * Returns an instance of the TraceFacade (Singleton pattern).
41
     *
42
     * @return An instance of the TraceFacade (Singleton pattern).
43
     */
44
    public static TraceFacade getInstance() {
45
        if (instance_ == null)
46
            instance_ = new TraceFacade();
47
        return instance_;
48
    }
49
    
50
    /**
51
     * Returns all the trace events between the given time range.
52
     * @param experiment The current experiment.
53
     * @param timeRange The considered time range.
54
     * @param handler The object that will receive the trace events.
55
     */
56
    public void getAllEvents(TmfExperiment<LttngEvent> experiment, TmfTimeRange timeRange, DataHandler handler) {
57
    	UnfilteredRequest request = new UnfilteredRequest(LttngEvent.class, timeRange, handler);
58
    	experiment.sendRequest(request);
59
    }
60
    
61
    
62
    
63
    /**
64
     * TmfEventRequest extension to forward data handling to a designated object, unfiltered by type(s).
65
     * 
66
     * @author Philippe Sawicki
67
     */
68
    private class UnfilteredRequest extends TmfEventRequest<LttngEvent> {
69
    	
70
    	/**
71
    	 * Data handler.
72
    	 */
73
    	private DataHandler handler_ = null;
74
    	
75
    	/**
76
    	 * Start of considered time range.
77
    	 */
78
    	private TmfTimestamp startTime_ = null;
79
    	/**
80
    	 * End of considered time range.
81
    	 */
82
    	private TmfTimestamp endTime_   = null;
83
    	
84
85
    	@SuppressWarnings("unchecked")
86
		public UnfilteredRequest(Class<? extends TmfEvent> dataType, TmfTimeRange timeRange, DataHandler handler, int nbRequested) {
87
            super((Class<LttngEvent>)dataType, timeRange, nbRequested, 1);
88
            handler_ = handler;
89
            
90
            startTime_ = timeRange.getStartTime();
91
            endTime_   = timeRange.getEndTime();
92
        }
93
    	
94
    	@SuppressWarnings("unchecked")
95
		public UnfilteredRequest(Class<? extends TmfEvent> dataType, TmfTimeRange timeRange, DataHandler handler) {
96
            super((Class<LttngEvent>)dataType, timeRange, Integer.MAX_VALUE, 1);
97
            handler_ = handler;
98
            
99
            startTime_ = timeRange.getStartTime();
100
            endTime_   = timeRange.getEndTime();
101
        }
102
103
		public void handleData(LttngEvent event) {
104
			if ( event != null 
105
					&& event.getTimestamp().getValue() >= startTime_.getValue() 
106
					&& event.getTimestamp().getValue() <= endTime_.getValue() ) {
107
		        handler_.handleData(event);
108
			}
109
	    }
110
		
111
		/**
112
		 * Forward completion notification to the handler.
113
		 */
114
		public void handleCompleted() {
115
			handler_.handleCompleted();
116
		}
117
		
118
		/**
119
		 * Forward success notification to the handler.
120
		 */
121
		public void handleSuccess() {
122
			handler_.handleSuccess();
123
		}
124
		
125
		/**
126
		 * Forward failure notification to the handler.
127
		 */
128
		public void handleFailure() {
129
	    	handler_.handleFailure();
130
	    }
131
		
132
		/**
133
		 * Forward cancellation notification to the handler.
134
		 */
135
		public void handleCancel() {
136
			handler_.handleCancel();
137
		}
138
    }
139
140
}
(-)plugin.xml (+9 lines)
Lines 90-95 Link Here
90
            name="%histogram.view.name"
90
            name="%histogram.view.name"
91
            restorable="true">
91
            restorable="true">
92
      </view>
92
      </view>
93
      <view
94
            allowMultiple="false"
95
            category="org.eclipse.linuxtools.lttng.ui.views.category"
96
            class="org.eclipse.linuxtools.lttng.ui.views.latency.LatencyView"
97
            icon="icons/graph.gif"
98
            id="org.eclipse.linuxtools.lttng.ui.views.latency"
99
            name="%latency.view.name"
100
            restorable="true">
101
      </view>
93
   </extension>
102
   </extension>
94
   <extension
103
   <extension
95
         point="org.eclipse.ui.newWizards">
104
         point="org.eclipse.ui.newWizards">
(-)plugin.properties (+1 lines)
Lines 14-19 Link Here
14
resources.view.name = Resources
14
resources.view.name = Resources
15
statistics.view.name = Statistics
15
statistics.view.name = Statistics
16
histogram.view.name = Histogram
16
histogram.view.name = Histogram
17
latency.view.name = Latency View
17
18
18
wizard.category.name = LTTng
19
wizard.category.name = LTTng
19
project.new.wizard.name = LTTng Project
20
project.new.wizard.name = LTTng Project
(-)src/org/eclipse/linuxtools/lttng/AllLTTngTests.java (+3 lines)
Lines 3-8 Link Here
3
import junit.framework.Test;
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
4
import junit.framework.TestSuite;
5
5
6
import org.eclipse.linuxtools.lttng.analysis.analyser.test.AnalysisTests;
6
import org.eclipse.linuxtools.lttng.control.LTTngSyntheticEventProviderTest;
7
import org.eclipse.linuxtools.lttng.control.LTTngSyntheticEventProviderTest;
7
import org.eclipse.linuxtools.lttng.model.LTTngTreeNodeTest;
8
import org.eclipse.linuxtools.lttng.model.LTTngTreeNodeTest;
8
import org.eclipse.linuxtools.lttng.state.resource.LTTngStateResourceTest;
9
import org.eclipse.linuxtools.lttng.state.resource.LTTngStateResourceTest;
Lines 45-50 Link Here
45
		suite.addTestSuite(LTTngTreeNodeTest.class);
46
		suite.addTestSuite(LTTngTreeNodeTest.class);
46
//		suite.addTestSuite(StateExperimentManagerTextTest.class);
47
//		suite.addTestSuite(StateExperimentManagerTextTest.class);
47
		suite.addTestSuite(LTTngStateResourceTest.class);
48
		suite.addTestSuite(LTTngStateResourceTest.class);
49
		
50
		suite.addTestSuite(AnalysisTests.class);
48
51
49
		//$JUnit-END$
52
		//$JUnit-END$
50
		return suite;
53
		return suite;
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/test/AnalysisTests.java (+281 lines)
Line 0 Link Here
1
package org.eclipse.linuxtools.lttng.analysis.analyser.test;
2
3
4
import junit.framework.TestCase;
5
import org.junit.After;
6
import org.junit.Before;
7
8
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.EventMatcher;
9
import org.eclipse.linuxtools.lttng.analysis.analyser.matcher.StackWrapper;
10
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.EventCountPerLatency;
11
import org.eclipse.linuxtools.lttng.analysis.analyser.utilities.Pair;
12
import org.eclipse.linuxtools.lttng.event.LttngEvent;
13
import org.eclipse.linuxtools.lttng.ui.views.latency.ChartPoint;
14
15
16
/**
17
 * Define the class test
18
 * this class initialize the variables test in the setup() method, free all variables of data in tesrDown(), and 
19
 * define the preparation of each test, define also the case test, 
20
 * and finally execute all test cases in testGlobalAnalyser() method.
21
 * 
22
 * @author Abdelhaq Saoudi
23
 */
24
25
public class AnalysisTests extends TestCase{
26
	
27
		/**
28
		 * Variables for test
29
		 */
30
	
31
		private LttngEvent eventAsked_1= null;
32
		private LttngEvent eventAsked_2= null;
33
		private LttngEvent newEvent = null;
34
		private LttngEvent newEvent1 = null;
35
		private static int matched = 0;
36
		private static int processed = 0;
37
		
38
		private String key_1 = null;
39
		private String key_2 = null;
40
		private String type1 = null;
41
		private String type2 = null;
42
		private StackWrapper stw = null;
43
		
44
		private EventCountPerLatency ecpl= null;
45
		private  long minLatency =  10;
46
		private  long maxLatency =  30;
47
		private int nbBar = 10;
48
		private Pair<Integer,ChartPoint> pair;
49
		private Pair<String,String> eventType;
50
	
51
	    /**
52
	     * Constructor of the class test
53
	     */
54
	    
55
		public AnalysisTests(final String name){
56
			super(name);
57
			
58
			/**
59
			 * search all event and registration in the vector traceEvents
60
			 */
61
			RequestsEvents.getInstance().findEvents();
62
		}
63
		
64
		/**
65
		 * preparation for test of Event data received
66
		 */
67
		public void preparationtoTestDataEvent(){
68
			eventAsked_1 = RequestsEvents.traceEvents.elementAt(0);
69
			eventAsked_2 = RequestsEvents.traceEvents.elementAt(1);
70
		}	
71
		
72
	    /**
73
	     *  preparation for test of EventMatcher class
74
	     */
75
		public void preparationtoTestProcess(){
76
			//eventAsked_1 = RequestsEvents.traceEvents.elementAt(0);
77
			//eventAsked_2 = RequestsEvents.traceEvents.elementAt(1);
78
			newEvent = EventMatcher.getInstance().process(eventAsked_1);
79
			newEvent1 = EventMatcher.getInstance().process(eventAsked_2);
80
			processed = EventMatcher.getInstance().getNBProcessedEvents();
81
			matched = EventMatcher.getInstance().getNBMatchedEvents();
82
		}
83
		
84
		/**
85
	     *  preparation to test of clearStack method in EventMatcher class.
86
	     */
87
		public void preparationtoTestClearStack(){
88
			EventMatcher.getInstance().clearStack();	
89
		}
90
		
91
	     /**
92
	     *  preparation for test of stackWrraper class
93
	     */
94
		public void preparationtoTestStack(){
95
			//eventAsked_1 = RequestsEvents.traceEvents.elementAt(0);
96
			//eventAsked_2 = RequestsEvents.traceEvents.elementAt(1);
97
			key_1 = 	eventAsked_1.getMarkerName();
98
			key_2 = 	eventAsked_2.getMarkerName();
99
			stw = new StackWrapper();
100
			int size = RequestsEvents.traceEvents.size();
101
			
102
			// for all requests event, we put it in the stack.
103
		    for(int i = 0 ; i < size -1; i++)
104
		    	 stw.put(RequestsEvents.traceEvents.elementAt(i));
105
		}
106
		
107
	     /**
108
	     *  preparation for test of EventCountPerLatency class
109
	     */
110
		public void preparationtoTestEventCountPerLatency(){
111
		    ecpl = new EventCountPerLatency();
112
		    ecpl.generateStandardLatencies(minLatency, maxLatency, nbBar);
113
		    pair = ecpl.updateStandardCounter(18);
114
		}   
115
		
116
	    /**
117
	     *  preparation for test of Pair class
118
	     */
119
		public void preparationtoTestPairClass(){
120
			eventType = new Pair<String, String>(eventAsked_1.getMarkerName(), eventAsked_2.getMarkerName());
121
			type1 = 	eventAsked_1.getMarkerName();
122
			type2 = 	eventAsked_2.getMarkerName();
123
		}   
124
		/**
125
		 * this method let us to initializes the variables.  
126
		 * */
127
		@Before
128
		public void setUp() throws Exception {
129
			super.setUp();
130
			preparationtoTestDataEvent(); 
131
			preparationtoTestProcess();
132
			preparationtoTestStack();
133
			preparationtoTestEventCountPerLatency();
134
			preparationtoTestPairClass();
135
		}
136
	   
137
		/**
138
		 * this method let us to free the variables.  
139
		 * */
140
		@After
141
		public void tearDown() throws Exception {
142
			super.setUp();
143
			eventAsked_1 = null; 
144
			eventAsked_2 = null;
145
			newEvent = null;
146
			newEvent1= null;
147
			stw = null;
148
			ecpl = null;
149
			pair = null;
150
			eventType = null;
151
		}
152
		
153
		/**
154
		 * test the data of event
155
		 */	
156
		public void EventDataTestT0() {
157
		     System.out.println("test T0 of good data event"); 
158
		     //System.out.println("ev 1 : " +  eventAsked_1);
159
		     //System.out.println("ev 2 : " + eventAsked_2);
160
		     assertEquals(0|1, eventAsked_1.getCpuId());
161
		     assertEquals(0|1, eventAsked_2.getCpuId());
162
			 assertNotSame(eventAsked_1.getTimestamp().getValue(), eventAsked_2.getTimestamp().getValue());
163
			 assertNotSame(eventAsked_1.getContent(), eventAsked_2.getContent());
164
			 assertNotSame(eventAsked_1.getMarkerName(), eventAsked_2.getMarkerName());
165
			 assertNotSame(eventAsked_1, eventAsked_2);
166
		}		
167
	
168
		
169
		public void EventDataTestT1() {
170
		     System.out.println("test T1 of errone data event");
171
		     assertNotSame("not exist marker",eventAsked_1.getMarkerName());
172
		     assertNotSame("not exist marker",eventAsked_2.getMarkerName());
173
		     assertNotSame(1345679853422L ,eventAsked_1.getTimestamp().getValue());
174
		     assertNotSame(1345679853422L ,eventAsked_2.getTimestamp().getValue());
175
		}	
176
		
177
		/**
178
		 * test process() method of EventMacher class 
179
		 */
180
		
181
		public void EventMatcherProcessTestT10() {
182
		     System.out.println("test T10 of good process method");
183
		     assertEquals(2,processed);
184
			 assertNotNull(matched);	
185
			
186
		}		
187
		public void EventMatcherProcessTestT11() {
188
			System.out.println("test T11 of errone process method");
189
			assertNotSame(3,processed);
190
			assertNotSame(3,matched);
191
		}		
192
		
193
			
194
		public void EventMatcherClearStackTestT101() {
195
		     System.out.println("test T101 of good clear Stack methode");
196
		     preparationtoTestClearStack();
197
		     assertSame(0,EventMatcher.getInstance().getNBProcessedEvents());
198
		     assertSame(0,EventMatcher.getInstance().getNBMatchedEvents());
199
		}	
200
		 
201
		
202
		/**
203
		 * test the key of event in the stack WRraper. 
204
		 */
205
		public void StackTestT13() {
206
		    System.out.println("test T13 of errone content stack");
207
		    assertTrue(stw.containsKey(key_2));
208
		    stw.removeEvent(key_2, eventAsked_2);
209
		    assertFalse(stw.containsKey(key_2));   
210
		}
211
		
212
		
213
		/**
214
		 * test of EventCounterPerLatency. 
215
		 */
216
		
217
		public void GetStandardLatencyTestT14() {
218
		    System.out.println("test T14 of good event counter");
219
		    for(int i = 0; i < ecpl.getStandardLatencies().length; i++)
220
		    	System.out.println(ecpl.getStandardLatencies()[i]);
221
		    //System.out.println(pair.getFirst());
222
		    assertSame(4, pair.getFirst());
223
		    assertEquals(nbBar + 1, ecpl.getStandardLatencies().length);
224
		    
225
		}
226
		
227
		public void GetStandardLatencyTestT15() {
228
		    System.out.println("test T15 of errone event counter");
229
		    assertNotSame(0&1&2&3&5&6&7&8&9&10, pair.getFirst());
230
		    assertNotSame(20, ecpl.getStandardLatencies().length);
231
		    
232
		}
233
		
234
		
235
		/**
236
		 * test of Pair Class. 
237
		 */
238
		public void PairTestT16() {
239
		    System.out.println(" test T16 for good job of Pair");
240
		    assertEquals(type1, eventType.getFirst());
241
		    assertEquals(type2, eventType.getSecond());
242
		    assertNotSame(eventType.getFirst(), eventType.getSecond());
243
		    assertNotNull(eventType.hashCode());
244
		    assertFalse(eventType.equals(pair));
245
		    assertTrue(eventType.equals(eventType)); 
246
		}
247
		
248
		
249
		public void PairTestT17() {
250
		    System.out.println("test T17 for errone job of Pair ");
251
		    assertNotSame(type1, eventType.getSecond());
252
		    assertNotSame(type2, eventType.getFirst());
253
		    assertNotSame("event", eventType.getFirst());
254
		    assertNotSame("something", eventType.getSecond());
255
		    assertNotSame(0,eventType.hashCode());
256
		    assertNotSame("OBJECT",eventType.equals(pair)); 
257
		}
258
		
259
		/**
260
		 * this method execute all test cases,
261
		 * 
262
		 * because, if we start the test individual and number of test upper than one, 
263
		 * we have the error message in the console " ** (process: number): DEBUG (recursed) "
264
		 * 
265
		 */
266
		public void testGlobalAnalyser(){
267
			EventDataTestT0();
268
			EventDataTestT1();
269
			EventMatcherProcessTestT10();
270
			EventMatcherProcessTestT11();
271
			EventMatcherClearStackTestT101();
272
			StackTestT13();
273
			GetStandardLatencyTestT14();
274
			GetStandardLatencyTestT15();
275
			PairTestT16();
276
			PairTestT17();
277
		}
278
}
279
280
281
(-)src/org/eclipse/linuxtools/lttng/analysis/analyser/test/RequestsEvents.java (+92 lines)
Line 0 Link Here
1
package org.eclipse.linuxtools.lttng.analysis.analyser.test;
2
3
import java.util.Vector;
4
5
import org.eclipse.linuxtools.lttng.analysis.facade.DataHandler;
6
import org.eclipse.linuxtools.lttng.analysis.facade.TraceFacade;
7
import org.eclipse.linuxtools.lttng.event.LttngEvent;
8
import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
9
import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
10
import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
11
import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
12
13
14
/**
15
 * this class find all event from TMF by Trace Facade, 
16
 * and register it in the static Vector traceEvents.
17
 * 
18
 * @author Abdelhaq Saoudi
19
 */
20
21
public  class RequestsEvents extends DataHandler {
22
	
23
	   /**
24
	    *  (class implemented as Singleton).
25
	    */
26
	
27
	   private static RequestsEvents instance_ = null;
28
	    
29
	    
30
	    private RequestsEvents() { }
31
 
32
	    public static RequestsEvents getInstance() {
33
	        if (instance_ == null)
34
	            instance_ = new RequestsEvents();
35
	        return instance_;
36
	    }
37
38
		
39
		private final String TRACE_PATH = "/home/l3819/Bureau/traces/trace_0";
40
		
41
		public static Vector<LttngEvent> traceEvents = new Vector<LttngEvent>();
42
		
43
		private TmfExperiment<LttngEvent> experiment = null;
44
		
45
		private TmfTimeRange timeRange = null;
46
		
47
		/**
48
		 * this method findEvent() retrieves all event fromTMF by traceFacade, the received event pass in the handler "this"
49
		 */
50
		public void findEvents(){
51
			
52
			try {
53
				ITmfTrace[] traces = new ITmfTrace[1];
54
				traces[0] = new LTTngTrace(TRACE_PATH);
55
				
56
				// Create our new experiment
57
				experiment = new TmfExperiment<LttngEvent>(LttngEvent.class, "firstExperiment", traces);
58
				//long x=experiment.getStartTime().getValue();
59
				//long y=experiment.getEndTime().getValue();
60
				//System.out.println("valeur de x: "+  x +" y: "+ y +"y-x :"+ (y-x));
61
				timeRange = experiment.getTimeRange();
62
				TraceFacade.getInstance().getAllEvents(experiment, timeRange, this);
63
			}
64
			
65
			catch (NullPointerException e) {
66
			}
67
			catch (Exception e) {
68
			    e.printStackTrace();
69
			 }
70
			
71
		}  
72
	
73
		/**
74
		 * this handler register the event in the vector.
75
		 */
76
		public void handleData(LttngEvent event) {
77
			//System.out.println("start handler");
78
			traceEvents.add(event.clone());
79
		}
80
		
81
		/**
82
		 * Forward completion notification to the handler.
83
		 */
84
		public void handleCompleted() {
85
			
86
		}
87
			
88
	
89
}
90
91
	
92
(-).classpath (+1 lines)
Lines 3-7 Link Here
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.linuxtools.lttng.ui"/>
6
	<classpathentry kind="output" path="bin"/>
7
	<classpathentry kind="output" path="bin"/>
7
</classpath>
8
</classpath>

Return to bug 331467