Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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: | |
b59134e1 | 10 | * William Bourque - Initial API and implementation |
3e9fdb8b FC |
11 | * |
12 | * Modifications: | |
13 | * 2010-06-10 Yuriy Vashchuk - GUI reorganisation, simplification and some | |
14 | * related code improvements. | |
f05aabed FC |
15 | * 2010-06-20 Yuriy Vashchuk - Histograms optimisation. |
16 | * 2010-07-16 Yuriy Vashchuk - Histogram Canvas Heritage correction | |
6e512b93 | 17 | *******************************************************************************/ |
3e9fdb8b | 18 | |
6e512b93 ASL |
19 | package org.eclipse.linuxtools.lttng.ui.views.histogram; |
20 | ||
b59134e1 WB |
21 | import org.eclipse.linuxtools.lttng.event.LttngEvent; |
22 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; | |
550d787e | 23 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
b59134e1 | 24 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
833a21aa | 25 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; |
b59134e1 | 26 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; |
550d787e FC |
27 | import org.eclipse.linuxtools.tmf.request.ITmfDataRequest; |
28 | import org.eclipse.linuxtools.tmf.request.ITmfDataRequest.ExecutionType; | |
ff4ed569 | 29 | import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal; |
ed4b3b9f | 30 | import org.eclipse.linuxtools.tmf.signal.TmfRangeSynchSignal; |
b59134e1 WB |
31 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
32 | import org.eclipse.linuxtools.tmf.signal.TmfTimeSynchSignal; | |
550d787e FC |
33 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; |
34 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
b59134e1 WB |
35 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
36 | import org.eclipse.swt.SWT; | |
7ef9ae3f WB |
37 | import org.eclipse.swt.events.ControlEvent; |
38 | import org.eclipse.swt.events.ControlListener; | |
6cf16d22 | 39 | import org.eclipse.swt.graphics.Font; |
833a21aa | 40 | import org.eclipse.swt.graphics.FontData; |
b59134e1 | 41 | import org.eclipse.swt.layout.GridData; |
252ae4bd | 42 | import org.eclipse.swt.layout.GridLayout; |
6e512b93 | 43 | import org.eclipse.swt.widgets.Composite; |
833a21aa | 44 | import org.eclipse.swt.widgets.Text; |
6e512b93 | 45 | |
544fe9b7 WB |
46 | /** |
47 | * <b><u>HistogramView</u></b> | |
48 | * <p> | |
49 | * View that contain an visual approach to the window that control the request. | |
50 | * This is intended to replace the TimeFrameView | |
51 | * <p> | |
52 | * This view is composed of 2 canvas, one for the whole experiment and one for the selectionned window in the experiment. | |
53 | * It also contain a certain number of controls to print or change informations about the experiment. | |
54 | */ | |
7ef9ae3f | 55 | public class HistogramView extends TmfView implements ControlListener { |
544fe9b7 WB |
56 | |
57 | // *** TODO *** | |
58 | // Here is what's left to do in this view | |
59 | // | |
3e9fdb8b | 60 | // 1- Make sure the interval time is small enough on very big trace (bug 311930) |
1155ca9f WB |
61 | // The interval time of the content is dynamically assigned from the screen width and trace duration. |
62 | // However, on very big trace (more than 1 hour), we could end up with time interval that are > 1 seconds, | |
63 | // which is not very precise. | |
64 | // An algorithm need to be implemented to make sure we "increase" the number of interval in the content if | |
65 | // their precision is getting too bad. | |
66 | // | |
67 | // 2- Make sure all control are thread safe (bug 309348) | |
544fe9b7 WB |
68 | // Right now, all the basic controls (i.e. Text and Label) are sensible to "Thread Access Exception" if |
69 | // updated from different threads; we need to carefully decide when/where to redraw them. | |
70 | // This is a real problem since there is a lot of thread going on in this view. | |
71 | // All basic control should be subclassed to offer "Asynchronous" functions. | |
1155ca9f WB |
72 | // |
73 | // 3- Implement a "preferences view" for the HistogramView (bug 311935) | |
3e9fdb8b | 74 | // There is a lot of adjustable preferences in the view, however there is no way to adjust them right now |
1155ca9f WB |
75 | // at run time. There should be a view of some kind of "menu" to allow the user to change them while executing. |
76 | // Most of the pertinent values are in HistogramConstant.java or in this file. | |
544fe9b7 | 77 | |
62d1696a | 78 | public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.histogram"; |
b59134e1 | 79 | |
7c1540ab WB |
80 | // "Minimum" screen width size. On smaller screen, we will apply several space saving technique |
81 | private static final int SCREEN_SMALL_IF_SMALLER_THAN = 1600; | |
82 | ||
3e9fdb8b FC |
83 | /* |
84 | // 2010-06-20 Yuriy: We will use the dynamic height. | |
85 | // Size of the "full trace" canvas | |
833a21aa | 86 | private static final int FULL_TRACE_CANVAS_HEIGHT = 25; |
3e9fdb8b | 87 | */ |
833a21aa | 88 | private static final int FULL_TRACE_BAR_WIDTH = 1; |
7ef9ae3f | 89 | private static final double FULL_TRACE_DIFFERENCE_TO_AVERAGE = 1.5; |
833a21aa | 90 | |
544fe9b7 | 91 | // Size of the "Selected Window" canvas |
3e9fdb8b FC |
92 | /* |
93 | // 2010-06-20 Yuriy | |
544fe9b7 | 94 | private static final int SELECTED_WINDOW_CANVAS_WIDTH = 300; |
7ef9ae3f | 95 | private static final int SMALL_SELECTED_WINDOW_CANVAS_WIDTH = 200; |
544fe9b7 | 96 | private static final int SELECTED_WINDOW_CANVAS_HEIGHT = 60; |
3e9fdb8b | 97 | */ |
833a21aa WB |
98 | private static final int SELECTED_WINDOW_BAR_WIDTH = 1; |
99 | private static final double SELECTED_WINDOW_DIFFERENCE_TO_AVERAGE = 10.0; | |
100 | ||
3e9fdb8b | 101 | // For the two "events" label (Max and Min number of events in the selection), we force a width |
833a21aa | 102 | // This will prevent the control from moving horizontally if the number of events in the selection varies |
3fda53ab | 103 | private static final int NB_EVENTS_FIXED_WIDTH = 50; |
833a21aa | 104 | |
833a21aa WB |
105 | // The "small font" height used to display time will be "default font" minus this constant |
106 | private static final int SMALL_FONT_MODIFIER = 2; | |
7c1540ab | 107 | private static final int VERY_SMALL_FONT_MODIFIER = 4; |
ecfd1d41 WB |
108 | |
109 | // *** TODO *** | |
110 | // This need to be changed as soon the framework implement a "window" | |
f6b14ce2 FC |
111 | // private static long DEFAULT_WINDOW_SIZE = (10L * 100 * 1000 * 1000); // 1sec |
112 | private static long DEFAULT_WINDOW_SIZE = (1L * 100 * 1000 * 1000); // .1sec | |
ecfd1d41 | 113 | |
544fe9b7 | 114 | // The last experiment received/used by the view |
ecfd1d41 | 115 | private TmfExperiment<LttngEvent> lastUsedExperiment = null; |
b59134e1 | 116 | |
7c1540ab WB |
117 | // Parent of the view |
118 | private Composite parent = null; | |
119 | ||
544fe9b7 | 120 | // Request and canvas for the "full trace" part |
b59134e1 | 121 | private HistogramRequest dataBackgroundFullRequest = null; |
f05aabed | 122 | private static ParentHistogramCanvas fullExperimentCanvas = null; |
b59134e1 | 123 | |
544fe9b7 | 124 | // Request and canvas for the "selected window" |
ecfd1d41 | 125 | private HistogramRequest selectedWindowRequest = null; |
f05aabed | 126 | private static ChildrenHistogramCanvas selectedWindowCanvas = null; |
b59134e1 | 127 | |
544fe9b7 WB |
128 | // Content of the timeTextGroup |
129 | // Since the user can modify them with erroneous value, | |
130 | // we will keep track of the value internally | |
1406f802 | 131 | private long currentEventTime = 0L; |
7c1540ab | 132 | |
544fe9b7 WB |
133 | // *** All the UI control below |
134 | // | |
135 | // NOTE : All textboxes will be READ_ONLY. | |
136 | // So the user will be able to select/copy the value in them but not to change it | |
833a21aa WB |
137 | private Text txtExperimentStartTime = null; |
138 | private Text txtExperimentStopTime = null; | |
139 | ||
140 | private Text txtWindowStartTime = null; | |
141 | private Text txtWindowStopTime = null; | |
7c1540ab WB |
142 | private Text txtWindowMaxNbEvents = null; |
143 | private Text txtWindowMinNbEvents = null; | |
833a21aa | 144 | |
3e9fdb8b FC |
145 | // We move the time label to header from TimeTextGroup.java |
146 | protected static final String NANOSEC_LABEL = "(sec)"; | |
147 | private static final String WINDOW_TIMERANGE_LABEL_TEXT = "Window Timerange, " + NANOSEC_LABEL; | |
148 | private static final String WINDOW_CURRENT_TIME_LABEL_TEXT = "Cursor Centered on, " + NANOSEC_LABEL; | |
149 | private static final String EVENT_CURRENT_TIME_LABEL_TEXT = "Current Event Time, " + NANOSEC_LABEL; | |
088c1d4e WB |
150 | private TimeTextGroup ntgTimeRangeWindow = null; |
151 | private TimeTextGroup ntgCurrentWindowTime = null; | |
152 | private TimeTextGroup ntgCurrentEventTime = null; | |
153 | ||
544fe9b7 WB |
154 | /** |
155 | * Default contructor of the view | |
156 | */ | |
6e512b93 | 157 | public HistogramView() { |
b59134e1 | 158 | super(ID); |
6e512b93 | 159 | } |
b59134e1 | 160 | |
544fe9b7 WB |
161 | /** |
162 | * Create the UI controls of this view | |
163 | * | |
164 | * @param parent The composite parent of this view | |
165 | */ | |
6e512b93 | 166 | @Override |
7c1540ab WB |
167 | public void createPartControl(Composite newParent) { |
168 | // Save the parent | |
169 | parent = newParent; | |
b59134e1 | 170 | |
833a21aa | 171 | // Default font |
6cf16d22 | 172 | Font font = parent.getFont(); |
833a21aa | 173 | FontData tmpFontData = font.getFontData()[0]; |
833a21aa WB |
174 | |
175 | ||
7c1540ab WB |
176 | Font smallFont = null; |
177 | int nbEventWidth = -1; | |
7ef9ae3f | 178 | int selectedCanvasWidth = -1; |
7c1540ab WB |
179 | boolean doesTimeTextGroupNeedAdjustment = false; |
180 | ||
181 | // Calculate if we need "small screen" fixes | |
182 | if ( parent.getDisplay().getBounds().width < SCREEN_SMALL_IF_SMALLER_THAN ) { | |
3e9fdb8b | 183 | |
7c1540ab WB |
184 | // A lot smaller font for timstampe |
185 | smallFont = new Font(font.getDevice(), tmpFontData.getName(), tmpFontData.getHeight() - VERY_SMALL_FONT_MODIFIER, tmpFontData.getStyle()); | |
186 | ||
3e9fdb8b FC |
187 | /* |
188 | // 2010-06-20 Yuriy | |
7ef9ae3f WB |
189 | // Smaller selection window canvas |
190 | selectedCanvasWidth = SMALL_SELECTED_WINDOW_CANVAS_WIDTH; | |
3e9fdb8b | 191 | */ |
7c1540ab WB |
192 | // Smaller event number text field |
193 | nbEventWidth = NB_EVENTS_FIXED_WIDTH/2; | |
194 | ||
195 | // Tell the text group to ajust | |
196 | doesTimeTextGroupNeedAdjustment = true; | |
3e9fdb8b FC |
197 | |
198 | } else { | |
199 | ||
7c1540ab WB |
200 | // Slightly smaller font for timestamp |
201 | smallFont = new Font(font.getDevice(), tmpFontData.getName(), tmpFontData.getHeight() - SMALL_FONT_MODIFIER, tmpFontData.getStyle()); | |
202 | // Usual size for selected window and event number text field | |
203 | nbEventWidth = NB_EVENTS_FIXED_WIDTH; | |
3e9fdb8b FC |
204 | /* |
205 | // 2010-06-20 Yuriy | |
7c1540ab | 206 | selectedCanvasWidth = SELECTED_WINDOW_CANVAS_WIDTH; |
3e9fdb8b | 207 | */ |
7c1540ab WB |
208 | // No ajustement needed by the text group |
209 | doesTimeTextGroupNeedAdjustment = false; | |
3e9fdb8b | 210 | |
7c1540ab | 211 | } |
3e9fdb8b | 212 | |
7c1540ab | 213 | |
3e9fdb8b | 214 | ///////////////////////////////////////////////////////////////////////////////////// |
833a21aa WB |
215 | // Layout for the whole view, other elements will be in a child composite of this one |
216 | // Contains : | |
217 | // Composite layoutSelectionWindow | |
218 | // Composite layoutTimesSpinner | |
219 | // Composite layoutExperimentHistogram | |
3e9fdb8b FC |
220 | ///////////////////////////////////////////////////////////////////////////////////// |
221 | Composite layoutFullView = new Composite(parent, SWT.FILL); | |
833a21aa WB |
222 | GridLayout gridFullView = new GridLayout(); |
223 | gridFullView.numColumns = 2; | |
544fe9b7 WB |
224 | gridFullView.horizontalSpacing = 0; |
225 | gridFullView.verticalSpacing = 0; | |
833a21aa WB |
226 | gridFullView.marginHeight = 0; |
227 | gridFullView.marginWidth = 0; | |
228 | layoutFullView.setLayout(gridFullView); | |
3e9fdb8b | 229 | |
833a21aa | 230 | |
3e9fdb8b | 231 | ///////////////////////////////////////////////////////////////////////////////////// |
833a21aa WB |
232 | // Layout that contain the time spinner |
233 | // Contains : | |
234 | // NanosecTextGroup spTimeRangeWindow | |
235 | // NanosecTextGroup spCurrentWindowTime | |
236 | // NanosecTextGroup spCurrentEventTime | |
3e9fdb8b | 237 | ///////////////////////////////////////////////////////////////////////////////////// |
833a21aa WB |
238 | Composite layoutTimesSpinner = new Composite(layoutFullView, SWT.NONE); |
239 | GridLayout gridTimesSpinner = new GridLayout(); | |
544fe9b7 | 240 | gridTimesSpinner.numColumns = 3; |
833a21aa WB |
241 | gridTimesSpinner.marginHeight = 0; |
242 | gridTimesSpinner.marginWidth = 0; | |
544fe9b7 WB |
243 | gridTimesSpinner.horizontalSpacing = 0; |
244 | gridTimesSpinner.verticalSpacing = 0; | |
833a21aa | 245 | layoutTimesSpinner.setLayout(gridTimesSpinner); |
833a21aa | 246 | |
3e9fdb8b FC |
247 | GridData gridDataCurrentEvent = new GridData(); |
248 | gridDataCurrentEvent.horizontalAlignment = SWT.LEFT; | |
249 | gridDataCurrentEvent.verticalAlignment = SWT.CENTER; | |
250 | ntgCurrentEventTime = new TimeTextGroup(this, layoutTimesSpinner, SWT.BORDER, SWT.BORDER, EVENT_CURRENT_TIME_LABEL_TEXT, HistogramConstant.formatNanoSecondsTime( 0L ), doesTimeTextGroupNeedAdjustment); | |
251 | ntgCurrentEventTime.setLayoutData(gridDataCurrentEvent); | |
833a21aa | 252 | |
3e9fdb8b FC |
253 | GridData gridDataTimeRange = new GridData(); |
254 | gridDataCurrentEvent.horizontalAlignment = SWT.CENTER; | |
255 | gridDataCurrentEvent.verticalAlignment = SWT.CENTER; | |
256 | ntgTimeRangeWindow = new TimeTextGroup(this, layoutTimesSpinner, SWT.BORDER, SWT.BORDER, WINDOW_TIMERANGE_LABEL_TEXT, HistogramConstant.formatNanoSecondsTime( 0L ), doesTimeTextGroupNeedAdjustment); | |
257 | ntgTimeRangeWindow.setLayoutData(gridDataTimeRange); | |
258 | ||
259 | GridData gridDataCurrentWindow = new GridData(); | |
260 | gridDataCurrentEvent.horizontalAlignment = SWT.RIGHT; | |
261 | gridDataCurrentEvent.verticalAlignment = SWT.CENTER; | |
262 | ntgCurrentWindowTime = new TimeTextGroup(this, layoutTimesSpinner, SWT.BORDER, SWT.BORDER, WINDOW_CURRENT_TIME_LABEL_TEXT, HistogramConstant.formatNanoSecondsTime( 0L ), doesTimeTextGroupNeedAdjustment); | |
263 | ntgCurrentWindowTime.setLayoutData(gridDataCurrentWindow); | |
833a21aa WB |
264 | |
265 | ||
3e9fdb8b FC |
266 | ///////////////////////////////////////////////////////////////////////////////////// |
267 | // Layout that contain the SelectionWindow | |
268 | // Contains : | |
269 | // Label txtWindowStartTime | |
270 | // Label txtWindowStopTime | |
271 | // Label txtWindowMaxNbEvents | |
272 | // Label txtWindowMinNbEvents | |
273 | // ChildrenHistogramCanvas selectedWindowCanvas | |
274 | ///////////////////////////////////////////////////////////////////////////////////// | |
275 | Composite layoutSelectionWindow = new Composite(layoutFullView, SWT.FILL); | |
276 | GridLayout gridSelectionWindow = new GridLayout(); | |
277 | gridSelectionWindow.numColumns = 3; | |
278 | gridSelectionWindow.marginHeight = 0; | |
279 | gridSelectionWindow.marginWidth = 0; | |
280 | gridSelectionWindow.horizontalSpacing = 0; | |
281 | gridSelectionWindow.verticalSpacing = 0; | |
282 | layoutSelectionWindow.setLayout(gridSelectionWindow); | |
283 | ||
284 | GridData gridDataSelectionWindow = new GridData(); | |
285 | gridDataSelectionWindow.horizontalAlignment = SWT.FILL; | |
286 | gridDataSelectionWindow.verticalAlignment = SWT.FILL; | |
287 | layoutSelectionWindow.setLayoutData(gridDataSelectionWindow); | |
833a21aa | 288 | |
3e9fdb8b FC |
289 | GridData gridDataSelectionWindowCanvas = new GridData(); |
290 | gridDataSelectionWindowCanvas.horizontalSpan = 2; | |
291 | gridDataSelectionWindowCanvas.verticalSpan = 2; | |
292 | gridDataSelectionWindowCanvas.horizontalAlignment = SWT.FILL; | |
293 | gridDataSelectionWindowCanvas.grabExcessHorizontalSpace = true; | |
294 | gridDataSelectionWindowCanvas.verticalAlignment = SWT.FILL; | |
295 | /* | |
296 | // 2010-06-20 Yuriy | |
833a21aa WB |
297 | gridDataSelectionWindowCanvas.heightHint = SELECTED_WINDOW_CANVAS_HEIGHT; |
298 | gridDataSelectionWindowCanvas.minimumHeight = SELECTED_WINDOW_CANVAS_HEIGHT; | |
3e9fdb8b | 299 | */ |
7c1540ab WB |
300 | gridDataSelectionWindowCanvas.widthHint = selectedCanvasWidth; |
301 | gridDataSelectionWindowCanvas.minimumWidth = selectedCanvasWidth; | |
833a21aa WB |
302 | selectedWindowCanvas = new ChildrenHistogramCanvas(this, layoutSelectionWindow, SWT.BORDER); |
303 | selectedWindowCanvas.setLayoutData(gridDataSelectionWindowCanvas); | |
304 | ||
3e9fdb8b FC |
305 | GridData gridDataWindowMaxEvents = new GridData(); |
306 | gridDataWindowMaxEvents.horizontalAlignment = SWT.RIGHT; | |
307 | gridDataWindowMaxEvents.verticalAlignment = SWT.TOP; | |
833a21aa | 308 | // Force a width, to avoid the control to enlarge if the number of events change |
7c1540ab WB |
309 | gridDataWindowMaxEvents.minimumWidth = nbEventWidth; |
310 | txtWindowMaxNbEvents = new Text(layoutSelectionWindow, SWT.READ_ONLY); | |
311 | txtWindowMaxNbEvents.setFont(smallFont); | |
312 | txtWindowMaxNbEvents.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); | |
313 | txtWindowMaxNbEvents.setEditable(false); | |
3e9fdb8b | 314 | txtWindowMaxNbEvents.setText("0"); |
7c1540ab | 315 | txtWindowMaxNbEvents.setLayoutData(gridDataWindowMaxEvents); |
833a21aa | 316 | |
3e9fdb8b FC |
317 | GridData gridDataWindowMinEvents = new GridData(); |
318 | gridDataWindowMinEvents.horizontalAlignment = SWT.RIGHT; | |
319 | gridDataWindowMinEvents.verticalAlignment = SWT.BOTTOM; | |
833a21aa | 320 | // Force a width, to avoid the control to enlarge if the number of events change |
7c1540ab WB |
321 | gridDataWindowMinEvents.minimumWidth = nbEventWidth; |
322 | txtWindowMinNbEvents = new Text(layoutSelectionWindow, SWT.READ_ONLY); | |
323 | txtWindowMinNbEvents.setFont(smallFont); | |
324 | txtWindowMinNbEvents.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); | |
325 | txtWindowMinNbEvents.setEditable(false); | |
3e9fdb8b | 326 | txtWindowMinNbEvents.setText("0"); |
7c1540ab | 327 | txtWindowMinNbEvents.setLayoutData(gridDataWindowMinEvents); |
833a21aa | 328 | |
3e9fdb8b FC |
329 | GridData gridDataWindowStart = new GridData(); |
330 | gridDataWindowStart.horizontalAlignment = SWT.LEFT; | |
331 | gridDataWindowStart.verticalAlignment = SWT.BOTTOM; | |
833a21aa WB |
332 | txtWindowStartTime = new Text(layoutSelectionWindow, SWT.READ_ONLY); |
333 | txtWindowStartTime.setFont(smallFont); | |
334 | txtWindowStartTime.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); | |
335 | txtWindowStartTime.setEditable(false); | |
3e9fdb8b | 336 | txtWindowStartTime.setText("0.000000000"); |
833a21aa WB |
337 | txtWindowStartTime.setLayoutData(gridDataWindowStart); |
338 | ||
3e9fdb8b FC |
339 | GridData gridDataWindowStop = new GridData(); |
340 | gridDataWindowStop.horizontalAlignment = SWT.RIGHT; | |
341 | gridDataWindowStop.verticalAlignment = SWT.BOTTOM; | |
833a21aa WB |
342 | txtWindowStopTime = new Text(layoutSelectionWindow, SWT.READ_ONLY); |
343 | txtWindowStopTime.setFont(smallFont); | |
344 | txtWindowStopTime.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); | |
345 | txtWindowStopTime.setEditable(false); | |
3e9fdb8b | 346 | txtWindowStopTime.setText("0.000000000"); |
833a21aa WB |
347 | txtWindowStopTime.setLayoutData(gridDataWindowStop); |
348 | ||
3e9fdb8b FC |
349 | |
350 | /* | |
351 | // 2010-06-10 Yuriy: NOT NEEDED AFTER GUI IMPROVEMENTS. WORK FINE WITOUT THIS HACK | |
7ef9ae3f WB |
352 | // *** HACK *** |
353 | // To align properly AND to make sure the canvas size is fixed, we NEED to make sure all "section" of the | |
354 | // gridlayout are taken (and if possible of a fixed size). | |
355 | // However, SWT is VERY VERY DUMB and won't consider griddata that contain no control. | |
356 | // Since there will be missing a section, the SelectedWindowCanvas + NbEventsText will take 3 spaces, but | |
357 | // startTimeText + stopTimeText will take only 2 (as if empty the other griddata of 1 will get ignored). | |
358 | // StopTime will then take over the missing space; I want to align "stopTime" right on the end of canvas, so | |
359 | // the added space to stop time would make it being aligned improperly | |
360 | // So I NEED the empty griddata to be considered! | |
361 | // Visually : | |
362 | // |---------------|---------------|-----------| | |
363 | // |SelectionCanvas SelectionCanvas|NbEventText| | |
364 | // |SelectionCanvas SelectionCanvas|NbEventText| | |
365 | // |---------------|---------------|-----------| | |
366 | // |StartTime | StopTime| ??? | | |
367 | // |---------------|---------------|-----------| | |
368 | // | |
369 | // So since SWT will only consider griddata with control, | |
370 | // I need to create a totally useless control in the ??? section. | |
1155ca9f | 371 | // That's ugly, useless and it is generally a bad practice. |
7ef9ae3f WB |
372 | // |
373 | // *** SUB-HACK *** | |
374 | // Other interesting fact about SWT : the way it draws (Fill/Expand control in grid) will change if | |
1406f802 | 375 | // the control is a Text or a Label. |
7ef9ae3f WB |
376 | // A Label here will be "pushed" by startTime/stopTime Text and won't fill the full space as NbEventText. |
377 | // A Text here will NOT be "pushed" and would give a nice visual output. | |
378 | // (NB : No, I am NOT kidding, try it for yourself!) | |
379 | // | |
380 | // Soooooo I guess I will use a Text here. Way to go SWT! | |
1155ca9f WB |
381 | // Downside is that disabled textbox has a slightly different color (even if you force it yourself) so if I want |
382 | // to make the text "invisible", I have to keep it enabled (but read only), so it can be clicked on. | |
7ef9ae3f WB |
383 | // |
384 | // Label uselessControlToByPassSWTStupidBug = new Label(layoutSelectionWindow, SWT.BORDER); // WON'T align correctly!!! | |
3e9fdb8b FC |
385 | //GridData gridDataSpacer = new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1); |
386 | GridData gridDataSpacer = new GridData(); | |
387 | gridDataWindowStop.horizontalAlignment = SWT.FILL; | |
388 | gridDataWindowStop.verticalAlignment = SWT.TOP; | |
389 | gridDataSpacer.minimumWidth = nbEventWidth; | |
7ef9ae3f WB |
390 | Text uselessControlToByPassSWTStupidBug = new Text(layoutSelectionWindow, SWT.READ_ONLY); // WILL align correctly!!! |
391 | uselessControlToByPassSWTStupidBug.setEditable(false); | |
392 | uselessControlToByPassSWTStupidBug.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); | |
393 | uselessControlToByPassSWTStupidBug.setLayoutData(gridDataSpacer); | |
3e9fdb8b | 394 | */ |
7ef9ae3f WB |
395 | |
396 | ||
3e9fdb8b FC |
397 | ///////////////////////////////////////////////////////////////////////////////////// |
398 | // Layout that contain the complete experiment histogram and related controls. | |
399 | // Contains : | |
400 | // ParentHistogramCanvas fullExperimentCanvas | |
401 | // Text txtExperimentStartTime | |
402 | // Text txtExperimentStopTime | |
403 | ///////////////////////////////////////////////////////////////////////////////////// | |
404 | Composite layoutExperimentHistogram = new Composite(layoutFullView, SWT.FILL); | |
7ef9ae3f | 405 | |
3e9fdb8b FC |
406 | GridLayout gridExperimentHistogram = new GridLayout(); |
407 | gridExperimentHistogram.numColumns = 2; | |
408 | gridExperimentHistogram.marginHeight = 0; | |
409 | gridExperimentHistogram.marginWidth = 0; | |
410 | gridExperimentHistogram.horizontalSpacing = 0; | |
411 | gridExperimentHistogram.verticalSpacing = 0; | |
412 | layoutExperimentHistogram.setLayout(gridExperimentHistogram); | |
833a21aa | 413 | |
3e9fdb8b FC |
414 | /* |
415 | // 2010-06-10 Yuriy: NOT NEEDED AFTER GUI IMPROVEMENTS | |
416 | GridData gridDataExperimentHistogram = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); | |
417 | layoutExperimentHistogram.setLayoutData(gridDataExperimentHistogram); | |
418 | */ | |
833a21aa | 419 | |
544fe9b7 | 420 | // *** Everything related to the experiment canvas is below |
3e9fdb8b FC |
421 | GridData gridDataExperimentCanvas = new GridData(); |
422 | gridDataExperimentCanvas.horizontalSpan = 2; | |
423 | gridDataExperimentCanvas.horizontalAlignment = SWT.FILL; | |
424 | gridDataExperimentCanvas.grabExcessHorizontalSpace = true; | |
425 | gridDataExperimentCanvas.verticalAlignment = SWT.FILL; | |
426 | gridDataExperimentCanvas.grabExcessVerticalSpace = true; | |
427 | /* | |
428 | // 2010-06-20 Yuriy: We use the dynamic height. | |
833a21aa WB |
429 | gridDataExperimentCanvas.heightHint = FULL_TRACE_CANVAS_HEIGHT; |
430 | gridDataExperimentCanvas.minimumHeight = FULL_TRACE_CANVAS_HEIGHT; | |
3e9fdb8b | 431 | */ |
544fe9b7 WB |
432 | fullExperimentCanvas = new ParentHistogramCanvas(this, layoutExperimentHistogram, SWT.BORDER); |
433 | fullExperimentCanvas.setLayoutData(gridDataExperimentCanvas); | |
3e9fdb8b | 434 | layoutExperimentHistogram.setLayoutData(gridDataExperimentCanvas); |
833a21aa | 435 | |
3e9fdb8b FC |
436 | GridData gridDataExperimentStart = new GridData(); |
437 | gridDataExperimentStart.horizontalAlignment = SWT.LEFT; | |
438 | gridDataExperimentStart.verticalAlignment = SWT.BOTTOM; | |
833a21aa WB |
439 | txtExperimentStartTime = new Text(layoutExperimentHistogram, SWT.READ_ONLY); |
440 | txtExperimentStartTime.setFont(smallFont); | |
3e9fdb8b | 441 | txtExperimentStartTime.setText("0.000000000"); |
833a21aa WB |
442 | txtExperimentStartTime.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); |
443 | txtExperimentStartTime.setEditable(false); | |
444 | txtExperimentStartTime.setLayoutData(gridDataExperimentStart); | |
445 | ||
3e9fdb8b FC |
446 | GridData gridDataExperimentStop = new GridData(); |
447 | gridDataExperimentStop.horizontalAlignment = SWT.RIGHT; | |
448 | gridDataExperimentStop.verticalAlignment = SWT.BOTTOM; | |
833a21aa WB |
449 | txtExperimentStopTime = new Text(layoutExperimentHistogram, SWT.READ_ONLY); |
450 | txtExperimentStopTime.setFont(smallFont); | |
3e9fdb8b | 451 | txtExperimentStopTime.setText("0.000000000"); |
833a21aa WB |
452 | txtExperimentStopTime.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); |
453 | txtExperimentStopTime.setEditable(false); | |
454 | txtExperimentStopTime.setLayoutData(gridDataExperimentStop); | |
6e512b93 | 455 | } |
b59134e1 | 456 | |
544fe9b7 WB |
457 | // *** FIXME *** |
458 | // This is mainly used because of a because in the "experimentSelected()" notification, we shouldn't need this | |
459 | /** | |
460 | * Method called when the view receive the focus.<p> | |
461 | * If ExperimentSelected didn't send us a request yet, get the current Experiment and fire requests | |
462 | */ | |
b59134e1 | 463 | @SuppressWarnings("unchecked") |
6e512b93 ASL |
464 | @Override |
465 | public void setFocus() { | |
544fe9b7 | 466 | // WARNING : This does not seem to be thread safe |
b59134e1 WB |
467 | TmfExperiment<LttngEvent> tmpExperiment = (TmfExperiment<LttngEvent>)TmfExperiment.getCurrentExperiment(); |
468 | ||
469 | if ( (dataBackgroundFullRequest == null) && (tmpExperiment != null) ) { | |
ecfd1d41 | 470 | createCanvasAndRequests(tmpExperiment); |
b59134e1 | 471 | } |
7ef9ae3f WB |
472 | |
473 | // Call a redraw for everything | |
474 | parent.redraw(); | |
6e512b93 | 475 | } |
b59134e1 | 476 | |
544fe9b7 WB |
477 | /** |
478 | * Method called when the user select (double-click on) an experiment.<p> | |
479 | * We will create the needed canvas and fire the requests. | |
480 | * | |
481 | * @param signal Signal received from the framework. Contain the experiment. | |
482 | */ | |
b59134e1 WB |
483 | @SuppressWarnings("unchecked") |
484 | @TmfSignalHandler | |
485 | public void experimentSelected(TmfExperimentSelectedSignal<LttngEvent> signal) { | |
ecfd1d41 WB |
486 | TmfExperiment<LttngEvent> tmpExperiment = (TmfExperiment<LttngEvent>)signal.getExperiment(); |
487 | createCanvasAndRequests(tmpExperiment); | |
488 | } | |
489 | ||
3e9fdb8b | 490 | |
088c1d4e WB |
491 | // *** VERIFY *** |
492 | // Not sure what this should do since I don't know when it will be called | |
493 | // Let's do the same thing as experimentSelected for now | |
494 | // | |
544fe9b7 WB |
495 | /** |
496 | * Method called when an experiment is updated (??).<p> | |
7c1540ab | 497 | * ...for now, do nothing, as udating an experiment running in the background might cause crash |
544fe9b7 WB |
498 | * |
499 | * @param signal Signal received from the framework. Contain the experiment. | |
500 | */ | |
3e9fdb8b FC |
501 | /* |
502 | @SuppressWarnings("unchecked") | |
088c1d4e | 503 | @TmfSignalHandler |
833a21aa | 504 | public void experimentUpdated(TmfExperimentUpdatedSignal signal) { |
3e9fdb8b FC |
505 | |
506 | TmfExperiment<LttngEvent> tmpExperiment = (TmfExperiment<LttngEvent>)signal.getExperiment(); | |
507 | ||
508 | // Make sure the UI object are sane | |
509 | resetControlsContent(); | |
510 | ||
511 | // Redraw the canvas right away to have something "clean" as soon as we can | |
512 | fullExperimentCanvas.redraw(); | |
513 | selectedWindowCanvas.redraw(); | |
514 | ||
515 | // Recreate the request | |
516 | createCanvasAndRequests(tmpExperiment); | |
833a21aa | 517 | } |
3e9fdb8b | 518 | */ |
833a21aa | 519 | |
544fe9b7 WB |
520 | /** |
521 | * Method called when synchonization is active and that the user select an event.<p> | |
522 | * We update the current event timeTextGroup and move the selected window if needed. | |
523 | * | |
524 | * @param signal Signal received from the framework. Contain the event. | |
525 | */ | |
833a21aa WB |
526 | @TmfSignalHandler |
527 | public void currentTimeUpdated(TmfTimeSynchSignal signal) { | |
544fe9b7 | 528 | // In case we received our own signal |
3e9fdb8b | 529 | if ( (signal != null) && (signal.getSource() != this) ) { |
833a21aa | 530 | TmfTimestamp currentTime = signal.getCurrentTime(); |
833a21aa | 531 | |
544fe9b7 | 532 | // Update the current event controls |
088c1d4e WB |
533 | currentEventTime = currentTime.getValue(); |
534 | updateSelectedEventTime(); | |
535 | ||
544fe9b7 WB |
536 | // If the given event is outside the selection window, recenter the window |
537 | if ( isGivenTimestampInSelectedWindow( currentEventTime ) == false) { | |
1406f802 | 538 | fullExperimentCanvas.setWindowCenterPosition( fullExperimentCanvas.getHistogramContent().getClosestXPositionFromTimestamp(currentEventTime) ); |
544fe9b7 | 539 | // Notify control that the window changed |
833a21aa | 540 | windowChangedNotification(); |
1406f802 WB |
541 | // Send a broadcast to the framework about the window change |
542 | sendTmfRangeSynchSignalBroadcast(); | |
833a21aa | 543 | } |
833a21aa WB |
544 | } |
545 | } | |
546 | ||
1406f802 WB |
547 | @TmfSignalHandler |
548 | public void synchToTimeRange(TmfRangeSynchSignal signal) { | |
549 | if ( (signal != null) && (signal.getSource() != this) ) { | |
550 | if ( lastUsedExperiment != null ) { | |
551 | long currentTime = signal.getCurrentTime().getValue(); | |
552 | long windowStart = signal.getCurrentRange().getStartTime().getValue(); | |
553 | long windowEnd = signal.getCurrentRange().getEndTime().getValue(); | |
554 | long windowTimeWidth = (windowEnd - windowStart); | |
555 | ||
556 | // Recenter the window | |
1406f802 | 557 | fullExperimentCanvas.setSelectedWindowSize(windowTimeWidth); |
f05aabed | 558 | fullExperimentCanvas.setWindowCenterPosition( fullExperimentCanvas.getHistogramContent().getClosestXPositionFromTimestamp(windowStart + (windowTimeWidth/2)) ); |
1406f802 WB |
559 | |
560 | // *** HACK *** | |
561 | // Views could send us incorrect current event value (event outside the current window) | |
562 | // Here we make sure the value is sane, otherwise, we force it as the left border of the window | |
563 | if ( isGivenTimestampInSelectedWindow( currentTime ) == false ) { | |
564 | currentTime = windowStart; | |
565 | } | |
566 | currentEventTime = currentTime; | |
567 | ||
568 | // Notify control that the window changed | |
569 | windowChangedNotification(); | |
570 | ||
16511734 | 571 | // Make sure we redraw the change |
1406f802 | 572 | fullExperimentCanvas.redraw(); |
1406f802 WB |
573 | } |
574 | } | |
575 | } | |
576 | ||
577 | ||
544fe9b7 WB |
578 | /* |
579 | * Create the canvas needed and issue the requests | |
580 | * | |
581 | * @param newExperiment Experiment we will use for the request | |
582 | */ | |
583 | private void createCanvasAndRequests(TmfExperiment<LttngEvent> newExperiment) { | |
16511734 | 584 | // Save the experiment we are about to use |
3cd34850 WB |
585 | lastUsedExperiment = newExperiment; |
586 | ||
550d787e FC |
587 | // // Create a copy of the trace that will be use only by the full experiment request |
588 | // TmfExperiment<LttngEvent> experimentCopy = newExperiment.createTraceCopy(); | |
c1877796 | 589 | |
3fda53ab WB |
590 | // Create the content for the full experiment. |
591 | // This NEED to be created first, as we use it in the selectedWindowCanvas | |
3e9fdb8b FC |
592 | fullExperimentCanvas.createNewHistogramContent( |
593 | fullExperimentCanvas.getSize().x, | |
594 | FULL_TRACE_BAR_WIDTH, | |
595 | /* | |
596 | // 2010-06-20 Yuriy: We will use the dynamic height. | |
597 | FULL_TRACE_CANVAS_HEIGHT | |
598 | */ | |
599 | fullExperimentCanvas.getSize().y / 2, | |
600 | FULL_TRACE_DIFFERENCE_TO_AVERAGE | |
f05aabed | 601 | ); |
550d787e FC |
602 | |
603 | TmfTimeRange timeRange = getExperimentTimeRange(newExperiment); | |
f05aabed FC |
604 | |
605 | // We will take the half of the full experiment length in case of bigger window size than the full experiment length | |
606 | if(timeRange.getEndTime().getValue() - timeRange.getStartTime().getValue() > DEFAULT_WINDOW_SIZE ) { | |
607 | fullExperimentCanvas.createNewSelectedWindow( | |
608 | timeRange.getStartTime().getValue(), | |
609 | DEFAULT_WINDOW_SIZE | |
610 | ); | |
611 | } else { | |
612 | fullExperimentCanvas.createNewSelectedWindow( | |
613 | timeRange.getStartTime().getValue(), | |
614 | (timeRange.getEndTime().getValue() - timeRange.getStartTime().getValue() ) / 2 | |
615 | ); | |
616 | } | |
617 | ||
550d787e FC |
618 | currentEventTime = timeRange.getStartTime().getValue(); |
619 | ||
620 | // Set the window of the fullTrace canvas visible. | |
7c1540ab | 621 | fullExperimentCanvas.getCurrentWindow().setSelectedWindowVisible(true); |
550d787e | 622 | fullExperimentCanvas.getHistogramContent().resetTable(timeRange.getStartTime().getValue(), timeRange.getEndTime().getValue()); |
f05aabed | 623 | |
7c1540ab | 624 | // Create the content for the selected window. |
f05aabed FC |
625 | selectedWindowCanvas.createNewHistogramContent( |
626 | selectedWindowCanvas.getSize().x, | |
627 | SELECTED_WINDOW_BAR_WIDTH, | |
628 | selectedWindowCanvas.getSize().y, | |
629 | SELECTED_WINDOW_DIFFERENCE_TO_AVERAGE | |
630 | ); | |
1155ca9f | 631 | selectedWindowCanvas.getHistogramContent().resetTable(fullExperimentCanvas.getCurrentWindow().getTimestampOfLeftPosition(), fullExperimentCanvas.getCurrentWindow().getTimestampOfRightPosition()); |
6cf16d22 | 632 | |
1406f802 | 633 | // Make sure the UI object are sane |
544fe9b7 | 634 | resetControlsContent(); |
833a21aa | 635 | |
6cf16d22 WB |
636 | // Redraw the canvas right away to have something "clean" as soon as we can |
637 | if ( dataBackgroundFullRequest != null ) { | |
544fe9b7 | 638 | fullExperimentCanvas.redraw(); |
6cf16d22 WB |
639 | selectedWindowCanvas.redraw(); |
640 | } | |
544fe9b7 WB |
641 | // Nullify the (possible) old request to be sure we start we something clean |
642 | // Note : this is very important for the order of the request below, | |
643 | // see "TODO" in performSelectedWindowEventsRequest | |
644 | dataBackgroundFullRequest = null; | |
645 | selectedWindowRequest = null; | |
ecfd1d41 | 646 | |
544fe9b7 WB |
647 | // Perform both request. |
648 | // Order is important here, the small/synchronous request for the selection window should go first | |
ecfd1d41 | 649 | performSelectedWindowEventsRequest(newExperiment); |
550d787e | 650 | performAllTraceEventsRequest(newExperiment); |
ecfd1d41 | 651 | } |
550d787e FC |
652 | |
653 | // Before completing its indexing, the experiment doesn't know start/end time. | |
654 | // However, LTTng individual traces have this knowledge so we should ask them | |
655 | // directly. | |
656 | private TmfTimeRange getExperimentTimeRange(TmfExperiment<LttngEvent> experiment) { | |
657 | // Before completing its indexing, the experiment doesn't know start/end time. | |
658 | // However, LTTng individual traces have this knowledge so we should ask them | |
659 | // directly. | |
660 | TmfTimestamp startTime = TmfTimestamp.BigCrunch; | |
661 | TmfTimestamp endTime = TmfTimestamp.BigBang; | |
662 | for (ITmfTrace trace : experiment.getTraces()) { | |
663 | TmfContext context = trace.seekLocation(null); | |
664 | context.setRank(0); | |
665 | TmfEvent event = trace.getNextEvent(context); | |
666 | TmfTimestamp traceStartTime = event.getTimestamp(); | |
667 | if (traceStartTime.compareTo(startTime, true) < 0) | |
668 | startTime = traceStartTime; | |
669 | TmfTimestamp traceEndTime = trace.getEndTime(); | |
670 | if (traceEndTime.compareTo(endTime, true) > 0) | |
671 | endTime = traceEndTime; | |
672 | } | |
673 | TmfTimeRange tmpRange = new TmfTimeRange(startTime, endTime); | |
674 | return tmpRange; | |
675 | } | |
676 | ||
544fe9b7 WB |
677 | /** |
678 | * Perform a new request for the Selection window.<p> | |
679 | * This assume the full experiment canvas has correct information about the selected window; | |
680 | * we need the fullExperimentCanvas' HistogramContent to be created and a selection window to be set. | |
681 | * | |
682 | * @param experiment The experiment we will select from | |
683 | */ | |
ecfd1d41 | 684 | public void performSelectedWindowEventsRequest(TmfExperiment<LttngEvent> experiment) { |
252ae4bd | 685 | |
3e9fdb8b FC |
686 | if(fullExperimentCanvas != null) { |
687 | HistogramSelectedWindow curSelectedWindow = fullExperimentCanvas.getCurrentWindow(); | |
688 | ||
f05aabed FC |
689 | TmfTimeRange timeRange = getExperimentTimeRange(experiment); |
690 | ||
3e9fdb8b FC |
691 | // If no selection window exists, we will try to create one; |
692 | // however this will most likely fail as the content is probably not created either | |
693 | if ( curSelectedWindow == null ) { | |
f05aabed FC |
694 | // We will take the half of the full experiment length in case of bigger window size than the full experiment length |
695 | if(timeRange.getEndTime().getValue() - timeRange.getStartTime().getValue() > DEFAULT_WINDOW_SIZE ) { | |
696 | fullExperimentCanvas.createNewSelectedWindow( | |
697 | timeRange.getStartTime().getValue(), | |
698 | DEFAULT_WINDOW_SIZE | |
699 | ); | |
700 | } else { | |
701 | fullExperimentCanvas.createNewSelectedWindow( | |
702 | timeRange.getStartTime().getValue(), | |
703 | (timeRange.getEndTime().getValue() - timeRange.getStartTime().getValue() ) / 2 | |
704 | ); | |
705 | } | |
3e9fdb8b FC |
706 | curSelectedWindow = fullExperimentCanvas.getCurrentWindow(); |
707 | } | |
708 | ||
709 | // The request will go from the Left timestamp of the window to the Right timestamp | |
710 | // This assume that out-of-bound value are handled by the SelectionWindow itself | |
711 | LttngTimestamp ts1 = new LttngTimestamp( curSelectedWindow.getTimestampOfLeftPosition() ); | |
712 | LttngTimestamp ts2 = new LttngTimestamp( curSelectedWindow.getTimestampOfRightPosition() ); | |
713 | TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2); | |
714 | ||
715 | // Set a (dynamic) time interval | |
716 | long intervalTime = ( (ts2.getValue() - ts1.getValue()) / selectedWindowCanvas.getHistogramContent().getNbElement() ); | |
717 | ||
718 | selectedWindowRequest = performRequest(experiment, selectedWindowCanvas, tmpRange, intervalTime, | |
f6b14ce2 | 719 | ExecutionType.FOREGROUND); |
3e9fdb8b | 720 | selectedWindowCanvas.redrawAsynchronously(); |
ecfd1d41 WB |
721 | } |
722 | ||
ecfd1d41 WB |
723 | } |
724 | ||
544fe9b7 WB |
725 | /** |
726 | * Perform a new request for the full experiment.<p> | |
727 | * NOTE : this is very long, we need to implement a way to run this in parallel (see TODO) | |
728 | * | |
729 | * @param experiment The experiment we will select from | |
730 | */ | |
ecfd1d41 | 731 | public void performAllTraceEventsRequest(TmfExperiment<LttngEvent> experiment) { |
b59134e1 WB |
732 | // Create a new time range from "start" to "end" |
733 | // That way, we will get "everything" in the trace | |
550d787e FC |
734 | // LttngTimestamp ts1 = new LttngTimestamp( experiment.getStartTime() ); |
735 | // LttngTimestamp ts2 = new LttngTimestamp( experiment.getEndTime() ); | |
736 | // TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2); | |
737 | ||
738 | TmfTimeRange tmpRange = getExperimentTimeRange(experiment); | |
739 | TmfTimestamp startTime = tmpRange.getStartTime(); | |
740 | TmfTimestamp endTime = tmpRange.getEndTime(); | |
b59134e1 | 741 | |
ecfd1d41 | 742 | // Set a (dynamic) time interval |
550d787e | 743 | long intervalTime = ( (endTime.getValue() - startTime.getValue()) / fullExperimentCanvas.getHistogramContent().getNbElement() ); |
b59134e1 | 744 | |
544fe9b7 WB |
745 | // *** VERIFY *** |
746 | // This would enable "fixed interval" instead of dynamic one. | |
747 | // ... we don't need it, do we? | |
748 | // | |
749 | // long intervalTime = ((long)(0.001 * (double)1000000000)); | |
750 | ||
751 | // *** TODO *** | |
752 | // It would be interesting if there was a way to tell the framework to run the request "in parallel" here. | |
753 | // Mean a completetly independant copy of the Expereiment would be done and we would proceed on that. | |
754 | // | |
f6b14ce2 | 755 | dataBackgroundFullRequest = performRequest(experiment, fullExperimentCanvas, tmpRange, intervalTime, ExecutionType.BACKGROUND); |
f05aabed FC |
756 | |
757 | ||
758 | fullExperimentCanvas.getCurrentWindow().setWindowXPositionLeft(fullExperimentCanvas.getHistogramContent().getClosestXPositionFromTimestamp(fullExperimentCanvas.getCurrentWindow().getTimestampOfLeftPosition())); | |
759 | fullExperimentCanvas.getCurrentWindow().setWindowXPositionCenter(fullExperimentCanvas.getHistogramContent().getClosestXPositionFromTimestamp(fullExperimentCanvas.getCurrentWindow().getTimestampOfCenterPosition())); | |
760 | fullExperimentCanvas.getCurrentWindow().setWindowXPositionRight(fullExperimentCanvas.getHistogramContent().getClosestXPositionFromTimestamp(fullExperimentCanvas.getCurrentWindow().getTimestampOfRightPosition())); | |
761 | ||
544fe9b7 | 762 | fullExperimentCanvas.redrawAsynchronously(); |
b59134e1 WB |
763 | } |
764 | ||
765 | // *** VERIFY *** | |
544fe9b7 WB |
766 | // This function is synchronized, is it a good idea? |
767 | // Tis is done to make sure requests arrive somewhat in order, | |
768 | // this is especially important when request are issued from different thread. | |
769 | /** | |
770 | * Create a new request from the given data and send it to the framework.<p> | |
771 | * The request will be queued and processed later. | |
772 | * | |
773 | * @param experiment The experiment we will process the request on | |
774 | * @param targetCanvas The canvas that will received the result | |
775 | * @param newRange The range of the request | |
776 | * @param newInterval The interval of time we use to store the result into the HistogramContent | |
777 | */ | |
550d787e | 778 | private synchronized HistogramRequest performRequest(TmfExperiment<LttngEvent> experiment, HistogramCanvas targetCanvas, TmfTimeRange newRange, long newInterval, ITmfDataRequest.ExecutionType execType) { |
b59134e1 WB |
779 | HistogramRequest returnedRequest = null; |
780 | ||
ecfd1d41 WB |
781 | // *** FIXME *** |
782 | // EVIL BUG! | |
1406f802 | 783 | // We use int.MAX_VALUE because we want every events BUT we don't know the number inside the range. |
ecfd1d41 WB |
784 | // HOWEVER, this would cause the request to run forever (or until it reach the end of trace). |
785 | // Seeting an EndTime does not seems to stop the request | |
550d787e | 786 | returnedRequest = new HistogramRequest(newRange, Integer.MAX_VALUE, targetCanvas, newInterval, execType ); |
544fe9b7 WB |
787 | |
788 | // Send the request to the framework : it will be queued and processed later | |
b59134e1 WB |
789 | experiment.sendRequest(returnedRequest); |
790 | ||
791 | return returnedRequest; | |
792 | } | |
088c1d4e | 793 | |
544fe9b7 WB |
794 | /** |
795 | * Function used to warn that the selection window changed.<p> | |
796 | * This might be called because the window moved or because its size changed.<p> | |
797 | * | |
798 | * We will update the different control related to the selection window. | |
799 | */ | |
ecfd1d41 | 800 | public void windowChangedNotification() { |
833a21aa | 801 | |
ecfd1d41 | 802 | if ( lastUsedExperiment != null ) { |
544fe9b7 | 803 | // If a request is ongoing, try to stop it |
550d787e | 804 | if ( selectedWindowRequest != null && selectedWindowRequest.isCompleted() == false ) { |
6cf16d22 WB |
805 | selectedWindowRequest.cancel(); |
806 | } | |
833a21aa | 807 | |
3e9fdb8b | 808 | if(fullExperimentCanvas != null) { |
3e9fdb8b FC |
809 | // If the current event time is outside the new window, change the current event |
810 | // The new current event will be the one closest to the LEFT side of the new window | |
811 | if ( isGivenTimestampInSelectedWindow(currentEventTime) == false ) { | |
812 | currentEventChangeNotification( fullExperimentCanvas.getCurrentWindow().getTimestampOfLeftPosition() ); | |
813 | } | |
814 | } | |
088c1d4e | 815 | |
544fe9b7 | 816 | // Perform a new request to read data about the new window |
ecfd1d41 WB |
817 | performSelectedWindowEventsRequest(lastUsedExperiment); |
818 | } | |
819 | } | |
820 | ||
544fe9b7 WB |
821 | /** |
822 | * Function used to tell that the current event changed.<p> | |
823 | * This might be called because the user changed the current event or | |
824 | * because the last current event is now outside the selection window.<p> | |
825 | * | |
826 | * We update the related control and send a signal to notify other views of the new current event. | |
827 | * | |
828 | * @param newCurrentEventTime | |
829 | */ | |
1406f802 WB |
830 | public void currentEventChangeNotification(long newCurrentEventTime) { |
831 | ||
088c1d4e WB |
832 | // Notify other views in the framework |
833 | if (currentEventTime != newCurrentEventTime) { | |
834 | currentEventTime = newCurrentEventTime; | |
835 | ||
544fe9b7 | 836 | // Update the UI control |
088c1d4e | 837 | updateSelectedEventTime(); |
088c1d4e WB |
838 | } |
839 | } | |
840 | ||
1406f802 WB |
841 | public void sendTmfTimeSynchSignalBroadcast() { |
842 | ||
843 | // System.out.println("sendTmfTimeSynchSignalBroadcast " + System.currentTimeMillis()); | |
844 | ||
845 | // Send a signal to the framework | |
846 | LttngTimestamp tmpTimestamp = new LttngTimestamp(currentEventTime); | |
847 | broadcast(new TmfTimeSynchSignal(this, tmpTimestamp)); | |
848 | } | |
849 | ||
ed4b3b9f WB |
850 | /** |
851 | * Function used to tell that the timerange (window) changed.<p> | |
852 | * This will most likely be called if the time window is resized. | |
853 | * | |
854 | * We send a signal to notify other views of the new timerange. | |
855 | */ | |
1406f802 WB |
856 | public void sendTmfRangeSynchSignalBroadcast() { |
857 | ||
9b635e61 FC |
858 | if (TmfExperiment.getCurrentExperiment() == null) |
859 | return; | |
860 | ||
3e9fdb8b | 861 | long startTime = fullExperimentCanvas.getCurrentWindow().getTimestampOfLeftPosition(); |
1406f802 WB |
862 | if ( startTime < fullExperimentCanvas.getHistogramContent().getStartTime() ) { |
863 | startTime = fullExperimentCanvas.getHistogramContent().getStartTime(); | |
864 | } | |
865 | LttngTimestamp tmpStartTime = new LttngTimestamp(startTime); | |
866 | ||
3e9fdb8b | 867 | long endTime = fullExperimentCanvas.getCurrentWindow().getTimestampOfRightPosition(); |
1406f802 WB |
868 | if ( endTime > fullExperimentCanvas.getHistogramContent().getEndTime() ) { |
869 | endTime = fullExperimentCanvas.getHistogramContent().getEndTime(); | |
870 | } | |
871 | LttngTimestamp tmpEndTime = new LttngTimestamp(endTime); | |
1406f802 | 872 | |
ed4b3b9f WB |
873 | TmfTimeRange tmpTimeRange = new TmfTimeRange(tmpStartTime, tmpEndTime); |
874 | LttngTimestamp tmpEventTime = new LttngTimestamp(currentEventTime); | |
1406f802 | 875 | |
ed4b3b9f WB |
876 | // Send a signal to the framework |
877 | broadcast(new TmfRangeSynchSignal(this, tmpTimeRange, tmpEventTime)); | |
878 | } | |
879 | ||
544fe9b7 WB |
880 | /** |
881 | * Function that will be called when one of the time text group value is changed.<p> | |
882 | * Since we don't (and can't unless we subclass them) know which one, we check them all. | |
883 | */ | |
088c1d4e WB |
884 | public void timeTextGroupChangeNotification() { |
885 | ||
3e9fdb8b FC |
886 | if(ntgCurrentEventTime != null) { |
887 | // If the user changed the current event time, call the notification | |
888 | long newCurrentTime = ntgCurrentEventTime.getValue(); | |
889 | if ( newCurrentTime != currentEventTime ) { | |
890 | currentEventChangeNotification( newCurrentTime ); | |
891 | // Send a broadcast to the framework about the window change | |
892 | sendTmfTimeSynchSignalBroadcast(); | |
893 | } | |
894 | } | |
088c1d4e | 895 | |
3e9fdb8b FC |
896 | if(ntgCurrentWindowTime != null && fullExperimentCanvas != null) { |
897 | // If the user changed the selected window time, recenter the window and call the notification | |
898 | long newSelectedWindowTime = ntgCurrentWindowTime.getValue(); | |
f05aabed FC |
899 | if ( newSelectedWindowTime != fullExperimentCanvas.getCurrentWindow().getTimestampOfCenterPosition() ) { |
900 | fullExperimentCanvas.setWindowCenterPosition(newSelectedWindowTime); | |
3e9fdb8b FC |
901 | windowChangedNotification(); |
902 | // Send a broadcast to the framework about the window change | |
903 | sendTmfRangeSynchSignalBroadcast(); | |
904 | } | |
088c1d4e WB |
905 | } |
906 | ||
3e9fdb8b FC |
907 | if(ntgTimeRangeWindow != null && fullExperimentCanvas != null) { |
908 | // If the user changed the selected window size, resize the window and call the notification | |
909 | long newSelectedWindowTimeRange = ntgTimeRangeWindow.getValue(); | |
f05aabed FC |
910 | if ( newSelectedWindowTimeRange != fullExperimentCanvas.getCurrentWindow().getWindowTimeWidth() ) { |
911 | fullExperimentCanvas.resizeWindowByAbsoluteTime(newSelectedWindowTimeRange); | |
3e9fdb8b FC |
912 | windowChangedNotification(); |
913 | // Send a broadcast to the framework about the window change | |
914 | sendTmfRangeSynchSignalBroadcast(); | |
915 | } | |
088c1d4e WB |
916 | } |
917 | ||
918 | } | |
919 | ||
544fe9b7 WB |
920 | /** |
921 | * Getter for the last used experiment.<p> | |
922 | * This might be different than the current experiment or even null. | |
923 | * | |
924 | * @return the last experiment we used in this view | |
925 | */ | |
ecfd1d41 WB |
926 | public TmfExperiment<LttngEvent> getLastUsedExperiment() { |
927 | return lastUsedExperiment; | |
928 | } | |
929 | ||
544fe9b7 WB |
930 | /** |
931 | * Check if a given timestamp is inside the selection window.<p> | |
932 | * This assume fullExperimentCanvas contain a valid HistogramContent | |
933 | * | |
934 | * @param timestamp the timestamp to check | |
935 | * | |
936 | * @return if the time is inside the selection window or not | |
937 | */ | |
1406f802 | 938 | public boolean isGivenTimestampInSelectedWindow(long timestamp) { |
088c1d4e WB |
939 | boolean returnedValue = true; |
940 | ||
544fe9b7 | 941 | // If the content is not set correctly, this will return weird (or even null) result |
1155ca9f WB |
942 | if ( (timestamp < fullExperimentCanvas.getCurrentWindow().getTimestampOfLeftPosition() ) || |
943 | (timestamp > fullExperimentCanvas.getCurrentWindow().getTimestampOfRightPosition() ) ) | |
088c1d4e WB |
944 | { |
945 | returnedValue = false; | |
946 | } | |
947 | ||
948 | return returnedValue; | |
949 | } | |
950 | ||
544fe9b7 WB |
951 | /** |
952 | * Reset the content of all Controls.<p> | |
953 | * WARNING : Calls in there are not thread safe and can't be called from different thread than "main" | |
954 | */ | |
955 | public void resetControlsContent() { | |
833a21aa WB |
956 | |
957 | TmfExperiment<LttngEvent> tmpExperiment = getLastUsedExperiment(); | |
958 | ||
544fe9b7 | 959 | // Use the previous Start and End time, or default if they are not available |
833a21aa WB |
960 | String startTime = null; |
961 | String stopTime = null; | |
962 | if ( tmpExperiment != null ) { | |
963 | startTime = HistogramConstant.formatNanoSecondsTime( tmpExperiment.getStartTime().getValue() ); | |
964 | stopTime = HistogramConstant.formatNanoSecondsTime( tmpExperiment.getEndTime().getValue() ); | |
6cf16d22 | 965 | } |
833a21aa WB |
966 | else { |
967 | startTime = HistogramConstant.formatNanoSecondsTime( 0L ); | |
968 | stopTime = HistogramConstant.formatNanoSecondsTime( 0L ); | |
969 | } | |
970 | ||
971 | txtExperimentStartTime.setText( startTime ); | |
972 | txtExperimentStopTime.setText( stopTime ); | |
973 | txtExperimentStartTime.getParent().layout(); | |
974 | ||
7c1540ab WB |
975 | txtWindowMaxNbEvents.setText("" + 0); |
976 | txtWindowMinNbEvents.setText("" + 0); | |
833a21aa WB |
977 | txtWindowStartTime.setText( HistogramConstant.formatNanoSecondsTime( 0L ) ); |
978 | txtWindowStopTime.setText( HistogramConstant.formatNanoSecondsTime( 0L ) ); | |
979 | txtWindowStartTime.getParent().layout(); | |
378e7718 | 980 | |
833a21aa WB |
981 | ntgCurrentWindowTime.setValue( HistogramConstant.formatNanoSecondsTime( 0L ) ); |
982 | ntgTimeRangeWindow.setValue( HistogramConstant.formatNanoSecondsTime( 0L ) ); | |
16511734 WB |
983 | |
984 | // Using "startTime" here can avoid an useless TmfTimeSynchSignal here | |
985 | // However it look ugly to have only this time | |
833a21aa | 986 | ntgCurrentEventTime.setValue( HistogramConstant.formatNanoSecondsTime( 0L ) ); |
378e7718 WB |
987 | } |
988 | ||
544fe9b7 WB |
989 | /** |
990 | * Update the content of the controls related to the full experiment canvas<p> | |
991 | * WARNING : Calls in there are not thread safe and can't be called from different thread than "main" | |
992 | */ | |
993 | public void updateFullExperimentInformation() { | |
378e7718 | 994 | |
3e9fdb8b FC |
995 | if(fullExperimentCanvas != null) { |
996 | String startTime = HistogramConstant.formatNanoSecondsTime( fullExperimentCanvas.getHistogramContent().getStartTime() ); | |
997 | String stopTime = HistogramConstant.formatNanoSecondsTime( fullExperimentCanvas.getHistogramContent().getEndTime() ); | |
998 | ||
999 | txtExperimentStartTime.setText( startTime ); | |
1000 | txtExperimentStopTime.setText( stopTime ); | |
1001 | } | |
833a21aa WB |
1002 | |
1003 | // Take one of the parent and call its layout to update control size | |
1004 | // Since both control have the same parent, only one call is needed | |
1005 | txtExperimentStartTime.getParent().layout(); | |
1006 | ||
1007 | // Update the selected window, just in case | |
1008 | // This should give a better user experience and it is low cost | |
1009 | updateSelectedWindowInformation(); | |
378e7718 WB |
1010 | } |
1011 | ||
544fe9b7 WB |
1012 | /** |
1013 | * Update the content of the controls related to the selection window canvas<p> | |
1014 | * WARNING : Calls in there are not thread safe and can't be called from different thread than "main" | |
1015 | */ | |
378e7718 | 1016 | public void updateSelectedWindowInformation() { |
833a21aa WB |
1017 | // Update the timestamp as well |
1018 | updateSelectedWindowTimestamp(); | |
1019 | ||
3e9fdb8b FC |
1020 | if(selectedWindowCanvas != null) { |
1021 | txtWindowMaxNbEvents.setText( Long.toString(selectedWindowCanvas.getHistogramContent().getHeighestEventCount()) ); | |
1022 | txtWindowMinNbEvents.setText(Long.toString(0)); | |
1023 | } | |
833a21aa WB |
1024 | |
1025 | // Refresh the layout | |
7c1540ab | 1026 | txtWindowMaxNbEvents.getParent().layout(); |
ecfd1d41 | 1027 | } |
6cf16d22 | 1028 | |
544fe9b7 WB |
1029 | /** |
1030 | * Update the content of the controls related to the timestamp of the selection window<p> | |
1031 | * WARNING : Calls in there are not thread safe and can't be called from different thread than "main" | |
1032 | */ | |
833a21aa | 1033 | public void updateSelectedWindowTimestamp() { |
833a21aa | 1034 | |
3e9fdb8b FC |
1035 | if(selectedWindowCanvas != null) { |
1036 | String startTime = HistogramConstant.formatNanoSecondsTime( selectedWindowCanvas.getHistogramContent().getStartTime() ); | |
1037 | String stopTime = HistogramConstant.formatNanoSecondsTime( selectedWindowCanvas.getHistogramContent().getEndTime() ); | |
1038 | txtWindowStartTime.setText( startTime ); | |
1039 | txtWindowStopTime.setText( stopTime ); | |
1040 | } | |
833a21aa | 1041 | |
3e9fdb8b FC |
1042 | if(fullExperimentCanvas != null) { |
1043 | ntgCurrentWindowTime.setValue( fullExperimentCanvas.getCurrentWindow().getTimestampOfCenterPosition() ); | |
1044 | ntgTimeRangeWindow.setValue( fullExperimentCanvas.getCurrentWindow().getWindowTimeWidth() ); | |
1045 | ||
1046 | // If the current event time is outside the selection window, recenter our window | |
1047 | if ( isGivenTimestampInSelectedWindow(ntgCurrentEventTime.getValue()) == false ) { | |
1048 | currentEventChangeNotification( fullExperimentCanvas.getCurrentWindow().getTimestampOfCenterPosition() ); | |
1049 | } | |
088c1d4e WB |
1050 | } |
1051 | ||
833a21aa WB |
1052 | // Take one control in each group to call to refresh the layout |
1053 | // Since both control have the same parent, only one call is needed | |
1054 | txtWindowStartTime.getParent().layout(); | |
1055 | ntgCurrentWindowTime.getParent().layout(); | |
1056 | } | |
378e7718 | 1057 | |
544fe9b7 WB |
1058 | /** |
1059 | * Update the controls related current event.<p> | |
1060 | * The call here SHOULD be thread safe and can be call from any threads. | |
1061 | */ | |
088c1d4e WB |
1062 | public void updateSelectedEventTime() { |
1063 | ntgCurrentEventTime.setValueAsynchronously(currentEventTime); | |
544fe9b7 WB |
1064 | // Tell the selection canvas which event is currently selected |
1065 | // This give a nice graphic output | |
088c1d4e WB |
1066 | selectedWindowCanvas.getHistogramContent().setSelectedEventTimeInWindow(currentEventTime); |
1067 | selectedWindowCanvas.redrawAsynchronously(); | |
1068 | } | |
1069 | ||
7ef9ae3f WB |
1070 | /** |
1071 | * Method called when the view is moved.<p> | |
1072 | * | |
1073 | * Just redraw everything... | |
1074 | * | |
1075 | * @param event The controle event generated by the move. | |
1076 | */ | |
1077 | public void controlMoved(ControlEvent event) { | |
1078 | parent.redraw(); | |
1079 | } | |
1080 | ||
1081 | /** | |
1082 | * Method called when the view is resized.<p> | |
1083 | * | |
1084 | * We will make sure that the size didn't change more than the content size.<p> | |
1085 | * Otherwise we need to perform a new request for the full experiment because we are missing data). | |
1086 | * | |
1087 | * @param event The control event generated by the resize. | |
1088 | */ | |
1089 | public void controlResized(ControlEvent event) { | |
1090 | ||
1091 | // Ouch! The screen enlarged (screen resolution changed?) so far that we miss content to fill the space. | |
7ef9ae3f WB |
1092 | if ( parent.getDisplay().getBounds().width > fullExperimentCanvas.getHistogramContent().getNbElement() ) { |
1093 | if ( lastUsedExperiment != null ) { | |
1406f802 | 1094 | createCanvasAndRequests(lastUsedExperiment); |
7ef9ae3f WB |
1095 | } |
1096 | } | |
1097 | ||
1098 | } | |
f05aabed FC |
1099 | |
1100 | /* | |
1101 | * Getter of FullExperimentCanvas | |
1102 | * | |
1103 | * @return FullExperimentCanvas object | |
1104 | */ | |
1105 | public static ParentHistogramCanvas getFullExperimentCanvas() { | |
1106 | return fullExperimentCanvas; | |
1107 | } | |
1108 | ||
1109 | /* | |
1110 | * Getter of SelectedWindowCanvas | |
1111 | * | |
1112 | * @return SelectedWindowCanvas object | |
1113 | */ | |
1114 | public static ChildrenHistogramCanvas getSelectedWindowCanvas() { | |
1115 | return selectedWindowCanvas; | |
1116 | } | |
1117 | ||
1118 | ||
1119 | /* | |
1120 | * Getter of DEFAULT_WINDOW_SIZE | |
1121 | * | |
1122 | * @return DEFAULT_WINDOW_SIZE value | |
1123 | */ | |
1124 | public static long getDEFAULT_WINDOW_SIZE() { | |
1125 | return DEFAULT_WINDOW_SIZE; | |
1126 | } | |
1127 | ||
1128 | /** | |
1129 | * Getter for dataBackgroundFullRequest variable | |
1130 | * @return the dataBackgroundFullRequest instance | |
1131 | */ | |
1132 | public HistogramRequest getDataBackgroundFullRequest() { | |
1133 | return dataBackgroundFullRequest; | |
1134 | } | |
1135 | ||
1136 | /** | |
1137 | * Getter for selectedWindowRequest variable | |
1138 | * @return the selectedWindowRequest instance | |
1139 | */ | |
1140 | public HistogramRequest getSelectedWindowRequest() { | |
1141 | return selectedWindowRequest; | |
1142 | } | |
1143 | ||
6e512b93 | 1144 | } |