Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2009, 2013 Ericsson |
1b055dfa | 3 | * |
6e512b93 ASL |
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 | |
1b055dfa | 8 | * |
6e512b93 | 9 | * Contributors: |
b59134e1 | 10 | * William Bourque - Initial API and implementation |
c392540b | 11 | * Yuriy Vashchuk - GUI reorganisation, simplification and some related code improvements. |
1b055dfa | 12 | * Yuriy Vashchuk - Histograms optimisation. |
c392540b FC |
13 | * Yuriy Vashchuk - Histogram Canvas Heritage correction |
14 | * Francois Chouinard - Cleanup and refactoring | |
e0752744 | 15 | * Francois Chouinard - Moved from LTTng to TMF |
65cdf787 | 16 | * Patrick Tasse - Update for mouse wheel zoom |
2fc582d2 | 17 | * Xavier Raynaud - Support multi-trace coloring |
6e512b93 | 18 | *******************************************************************************/ |
3e9fdb8b | 19 | |
e0752744 | 20 | package org.eclipse.linuxtools.tmf.ui.views.histogram; |
6e512b93 | 21 | |
dab5f596 | 22 | import org.eclipse.jdt.annotation.NonNull; |
95aa81ef JCK |
23 | import org.eclipse.jface.action.Action; |
24 | import org.eclipse.jface.action.IAction; | |
25 | import org.eclipse.jface.action.Separator; | |
26 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; | |
27 | import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants; | |
2740e05c | 28 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; |
fd3f1eff | 29 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType; |
6c13869b FC |
30 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; |
31 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
38df2c82 | 32 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler; |
6c13869b | 33 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; |
faa38350 PT |
34 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; |
35 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
36 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal; | |
37 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; | |
38 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; | |
3bd46eef AM |
39 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
40 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
41 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
faa38350 | 42 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
2fc582d2 | 43 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; |
b59134e1 WB |
44 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
45 | import org.eclipse.swt.SWT; | |
2fc582d2 | 46 | import org.eclipse.swt.custom.CLabel; |
720d67cb PT |
47 | import org.eclipse.swt.events.MouseAdapter; |
48 | import org.eclipse.swt.events.MouseEvent; | |
65cdf787 | 49 | import org.eclipse.swt.events.MouseWheelListener; |
720d67cb PT |
50 | import org.eclipse.swt.events.PaintEvent; |
51 | import org.eclipse.swt.events.PaintListener; | |
2fc582d2 | 52 | import org.eclipse.swt.graphics.GC; |
720d67cb PT |
53 | import org.eclipse.swt.graphics.Image; |
54 | import org.eclipse.swt.graphics.Rectangle; | |
b59134e1 | 55 | import org.eclipse.swt.layout.GridData; |
252ae4bd | 56 | import org.eclipse.swt.layout.GridLayout; |
2fc582d2 | 57 | import org.eclipse.swt.layout.RowLayout; |
6e512b93 | 58 | import org.eclipse.swt.widgets.Composite; |
2fc582d2 | 59 | import org.eclipse.swt.widgets.Control; |
80c930fa | 60 | import org.eclipse.swt.widgets.Display; |
720d67cb | 61 | import org.eclipse.swt.widgets.Label; |
95aa81ef | 62 | import org.eclipse.ui.IActionBars; |
6e512b93 | 63 | |
544fe9b7 | 64 | /** |
faa38350 | 65 | * The purpose of this view is to provide graphical time distribution statistics about the trace events. |
544fe9b7 | 66 | * <p> |
c392540b FC |
67 | * The view is composed of two histograms and two controls: |
68 | * <ul> | |
faa38350 | 69 | * <li>an event distribution histogram for the whole trace; |
c392540b FC |
70 | * <li>an event distribution histogram for current time window (window span); |
71 | * <li>the timestamp of the currently selected event; | |
72 | * <li>the window span (size of the time window of the smaller histogram). | |
73 | * </ul> | |
74 | * The histograms x-axis show their respective time range. | |
abbdd66a | 75 | * |
f8177ba2 | 76 | * @version 2.0 |
2af7df97 | 77 | * @author Francois Chouinard |
544fe9b7 | 78 | */ |
c392540b FC |
79 | public class HistogramView extends TmfView { |
80 | ||
81 | // ------------------------------------------------------------------------ | |
82 | // Constants | |
83 | // ------------------------------------------------------------------------ | |
84 | ||
b544077e BH |
85 | /** |
86 | * The view ID as defined in plugin.xml | |
87 | */ | |
dab5f596 | 88 | public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.ui.views.histogram"; //$NON-NLS-1$ |
c392540b | 89 | |
720d67cb PT |
90 | private static final Image LINK_IMG = Activator.getDefault().getImageFromPath("/icons/etool16/link.gif"); //$NON-NLS-1$ |
91 | ||
c392540b FC |
92 | // ------------------------------------------------------------------------ |
93 | // Attributes | |
94 | // ------------------------------------------------------------------------ | |
95 | ||
96 | // Parent widget | |
97 | private Composite fParent; | |
98 | ||
faa38350 PT |
99 | // The current trace |
100 | private ITmfTrace fTrace; | |
c392540b | 101 | |
f8177ba2 | 102 | // Current timestamp/time window - everything in the TIME_SCALE |
faa38350 PT |
103 | private long fTraceStartTime; |
104 | private long fTraceEndTime; | |
c392540b FC |
105 | private long fWindowStartTime; |
106 | private long fWindowEndTime; | |
d7ee91bb | 107 | private long fWindowSpan; |
0fcf3b09 PT |
108 | private long fSelectionBeginTime; |
109 | private long fSelectionEndTime; | |
c392540b FC |
110 | |
111 | // Time controls | |
720d67cb PT |
112 | private HistogramTextControl fSelectionStartControl; |
113 | private HistogramTextControl fSelectionEndControl; | |
c392540b FC |
114 | private HistogramTextControl fTimeSpanControl; |
115 | ||
720d67cb PT |
116 | // Link |
117 | private Label fLinkButton; | |
118 | private boolean fLinkState; | |
119 | ||
c392540b FC |
120 | // Histogram/request for the full trace range |
121 | private static FullTraceHistogram fFullTraceHistogram; | |
122 | private HistogramRequest fFullTraceRequest; | |
123 | ||
124 | // Histogram/request for the selected time range | |
125 | private static TimeRangeHistogram fTimeRangeHistogram; | |
126 | private HistogramRequest fTimeRangeRequest; | |
127 | ||
2fc582d2 XR |
128 | // Legend area |
129 | private Composite fLegendArea; | |
130 | private Image[] fLegendImages; | |
131 | ||
38df2c82 AM |
132 | // Throttlers for the time sync and time-range sync signals |
133 | private final TmfSignalThrottler fTimeSyncThrottle; | |
134 | private final TmfSignalThrottler fTimeRangeSyncThrottle; | |
135 | ||
95aa81ef JCK |
136 | // Action for toggle showing the lost events |
137 | private Action hideLostEventsAction; | |
2fc582d2 XR |
138 | // Action for toggle showing the traces |
139 | private Action showTraceAction; | |
95aa81ef | 140 | |
c392540b FC |
141 | // ------------------------------------------------------------------------ |
142 | // Constructor | |
143 | // ------------------------------------------------------------------------ | |
144 | ||
b544077e BH |
145 | /** |
146 | * Default constructor | |
147 | */ | |
c392540b FC |
148 | public HistogramView() { |
149 | super(ID); | |
38df2c82 AM |
150 | fTimeSyncThrottle = new TmfSignalThrottler(this, 200); |
151 | fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200); | |
c392540b FC |
152 | } |
153 | ||
6a13fa07 | 154 | @Override |
c392540b | 155 | public void dispose() { |
1b055dfa | 156 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
4dc47e28 FC |
157 | fTimeRangeRequest.cancel(); |
158 | } | |
1b055dfa | 159 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
4dc47e28 FC |
160 | fFullTraceRequest.cancel(); |
161 | } | |
6a13fa07 FC |
162 | fFullTraceHistogram.dispose(); |
163 | fTimeRangeHistogram.dispose(); | |
720d67cb PT |
164 | fSelectionStartControl.dispose(); |
165 | fSelectionEndControl.dispose(); | |
f8177ba2 | 166 | fTimeSpanControl.dispose(); |
4dc47e28 | 167 | super.dispose(); |
c392540b FC |
168 | } |
169 | ||
170 | // ------------------------------------------------------------------------ | |
171 | // TmfView | |
172 | // ------------------------------------------------------------------------ | |
173 | ||
174 | @Override | |
c392540b FC |
175 | public void createPartControl(Composite parent) { |
176 | ||
177 | fParent = parent; | |
178 | ||
179 | // Control labels | |
720d67cb PT |
180 | final String selectionStartLabel = Messages.HistogramView_selectionStartLabel; |
181 | final String selectionEndLabel = Messages.HistogramView_selectionEndLabel; | |
c392540b FC |
182 | final String windowSpanLabel = Messages.HistogramView_windowSpanLabel; |
183 | ||
184 | // -------------------------------------------------------------------- | |
185 | // Set the HistogramView layout | |
186 | // -------------------------------------------------------------------- | |
187 | ||
188 | Composite viewComposite = new Composite(fParent, SWT.FILL); | |
189 | GridLayout gridLayout = new GridLayout(); | |
190 | gridLayout.numColumns = 2; | |
191 | gridLayout.horizontalSpacing = 5; | |
192 | gridLayout.verticalSpacing = 0; | |
193 | gridLayout.marginHeight = 0; | |
194 | gridLayout.marginWidth = 0; | |
195 | viewComposite.setLayout(gridLayout); | |
196 | ||
c392540b FC |
197 | // -------------------------------------------------------------------- |
198 | // Time controls | |
199 | // -------------------------------------------------------------------- | |
200 | ||
720d67cb | 201 | Composite controlsComposite = new Composite(viewComposite, SWT.NONE); |
c392540b FC |
202 | gridLayout = new GridLayout(); |
203 | gridLayout.numColumns = 2; | |
204 | gridLayout.marginHeight = 0; | |
205 | gridLayout.marginWidth = 0; | |
206 | gridLayout.horizontalSpacing = 5; | |
720d67cb | 207 | gridLayout.verticalSpacing = 1; |
f8177ba2 | 208 | gridLayout.makeColumnsEqualWidth = false; |
c392540b | 209 | controlsComposite.setLayout(gridLayout); |
720d67cb PT |
210 | GridData gridData = new GridData(SWT.FILL, SWT.CENTER, false, false); |
211 | controlsComposite.setLayoutData(gridData); | |
212 | ||
213 | Composite selectionGroup = new Composite(controlsComposite, SWT.BORDER); | |
214 | gridLayout = new GridLayout(); | |
215 | gridLayout.marginHeight = 0; | |
216 | gridLayout.marginWidth = 0; | |
217 | gridLayout.horizontalSpacing = 0; | |
218 | gridLayout.verticalSpacing = 0; | |
219 | selectionGroup.setLayout(gridLayout); | |
c392540b | 220 | |
720d67cb | 221 | // Selection start control |
c392540b | 222 | gridData = new GridData(); |
720d67cb PT |
223 | gridData.horizontalAlignment = SWT.FILL; |
224 | gridData.verticalAlignment = SWT.CENTER; | |
225 | fSelectionStartControl = new HistogramSelectionStartControl(this, selectionGroup, selectionStartLabel, 0L); | |
226 | fSelectionStartControl.setLayoutData(gridData); | |
227 | fSelectionStartControl.setValue(Long.MIN_VALUE); | |
228 | ||
229 | // Selection end control | |
230 | gridData = new GridData(); | |
231 | gridData.horizontalAlignment = SWT.FILL; | |
c392540b | 232 | gridData.verticalAlignment = SWT.CENTER; |
720d67cb PT |
233 | fSelectionEndControl = new HistogramSelectionEndControl(this, selectionGroup, selectionEndLabel, 0L); |
234 | fSelectionEndControl.setLayoutData(gridData); | |
235 | fSelectionEndControl.setValue(Long.MIN_VALUE); | |
236 | ||
237 | // Link button | |
238 | gridData = new GridData(); | |
239 | fLinkButton = new Label(controlsComposite, SWT.NONE); | |
240 | fLinkButton.setImage(LINK_IMG); | |
241 | fLinkButton.setLayoutData(gridData); | |
242 | addLinkButtonListeners(); | |
c392540b FC |
243 | |
244 | // Window span time control | |
245 | gridData = new GridData(); | |
720d67cb | 246 | gridData.horizontalAlignment = SWT.FILL; |
c392540b | 247 | gridData.verticalAlignment = SWT.CENTER; |
f8177ba2 | 248 | fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L); |
c392540b | 249 | fTimeSpanControl.setLayoutData(gridData); |
da7bdcbc | 250 | fTimeSpanControl.setValue(Long.MIN_VALUE); |
c392540b FC |
251 | |
252 | // -------------------------------------------------------------------- | |
253 | // Time range histogram | |
254 | // -------------------------------------------------------------------- | |
255 | ||
720d67cb | 256 | Composite timeRangeComposite = new Composite(viewComposite, SWT.NONE); |
c392540b FC |
257 | gridLayout = new GridLayout(); |
258 | gridLayout.numColumns = 1; | |
259 | gridLayout.marginHeight = 0; | |
260 | gridLayout.marginWidth = 0; | |
261 | gridLayout.marginTop = 5; | |
262 | gridLayout.horizontalSpacing = 0; | |
263 | gridLayout.verticalSpacing = 0; | |
264 | gridLayout.marginLeft = 5; | |
265 | gridLayout.marginRight = 5; | |
266 | timeRangeComposite.setLayout(gridLayout); | |
267 | ||
268 | // Use remaining horizontal space | |
269 | gridData = new GridData(); | |
270 | gridData.horizontalAlignment = SWT.FILL; | |
271 | gridData.verticalAlignment = SWT.FILL; | |
272 | gridData.grabExcessHorizontalSpace = true; | |
3a790c10 | 273 | gridData.grabExcessVerticalSpace = true; |
c392540b FC |
274 | timeRangeComposite.setLayoutData(gridData); |
275 | ||
276 | // Histogram | |
277 | fTimeRangeHistogram = new TimeRangeHistogram(this, timeRangeComposite); | |
278 | ||
279 | // -------------------------------------------------------------------- | |
280 | // Full range histogram | |
281 | // -------------------------------------------------------------------- | |
282 | ||
283 | Composite fullRangeComposite = new Composite(viewComposite, SWT.FILL); | |
284 | gridLayout = new GridLayout(); | |
285 | gridLayout.numColumns = 1; | |
286 | gridLayout.marginHeight = 0; | |
287 | gridLayout.marginWidth = 0; | |
288 | gridLayout.marginTop = 5; | |
289 | gridLayout.horizontalSpacing = 0; | |
290 | gridLayout.verticalSpacing = 0; | |
291 | gridLayout.marginLeft = 5; | |
292 | gridLayout.marginRight = 5; | |
293 | fullRangeComposite.setLayout(gridLayout); | |
294 | ||
295 | // Use remaining horizontal space | |
296 | gridData = new GridData(); | |
297 | gridData.horizontalAlignment = SWT.FILL; | |
298 | gridData.verticalAlignment = SWT.FILL; | |
299 | gridData.horizontalSpan = 2; | |
300 | gridData.grabExcessHorizontalSpace = true; | |
3a790c10 | 301 | gridData.grabExcessVerticalSpace = true; |
c392540b FC |
302 | fullRangeComposite.setLayoutData(gridData); |
303 | ||
304 | // Histogram | |
305 | fFullTraceHistogram = new FullTraceHistogram(this, fullRangeComposite); | |
306 | ||
2fc582d2 XR |
307 | fLegendArea = new Composite(viewComposite, SWT.FILL); |
308 | fLegendArea.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1)); | |
309 | fLegendArea.setLayout(new RowLayout()); | |
310 | ||
65cdf787 PT |
311 | // Add mouse wheel listener to time span control |
312 | MouseWheelListener listener = fFullTraceHistogram.getZoom(); | |
313 | fTimeSpanControl.addMouseWheelListener(listener); | |
314 | ||
95aa81ef JCK |
315 | |
316 | // View Action Handling | |
317 | contributeToActionBars(); | |
318 | ||
3ac5721a AM |
319 | ITmfTrace trace = getActiveTrace(); |
320 | if (trace != null) { | |
321 | traceSelected(new TmfTraceSelectedSignal(this, trace)); | |
1b055dfa | 322 | } |
ecfd1d41 | 323 | } |
c392540b FC |
324 | |
325 | @Override | |
c392540b | 326 | public void setFocus() { |
faa38350 | 327 | fFullTraceHistogram.fCanvas.setFocus(); |
833a21aa | 328 | } |
c392540b | 329 | |
f8177ba2 FC |
330 | void refresh() { |
331 | fParent.layout(true); | |
332 | } | |
333 | ||
c392540b FC |
334 | // ------------------------------------------------------------------------ |
335 | // Accessors | |
336 | // ------------------------------------------------------------------------ | |
337 | ||
faa38350 PT |
338 | /** |
339 | * Returns the current trace handled by the view | |
340 | * | |
341 | * @return the current trace | |
342 | * @since 2.0 | |
343 | */ | |
344 | public ITmfTrace getTrace() { | |
345 | return fTrace; | |
346 | } | |
347 | ||
b544077e BH |
348 | /** |
349 | * Returns the time range of the current selected window (base on default time scale). | |
abbdd66a | 350 | * |
b544077e | 351 | * @return the time range of current selected window. |
3bd46eef | 352 | * @since 2.0 |
b544077e | 353 | */ |
c392540b | 354 | public TmfTimeRange getTimeRange() { |
f8177ba2 FC |
355 | return new TmfTimeRange( |
356 | new TmfTimestamp(fWindowStartTime, ITmfTimestamp.NANOSECOND_SCALE), | |
357 | new TmfTimestamp(fWindowEndTime, ITmfTimestamp.NANOSECOND_SCALE)); | |
c392540b FC |
358 | } |
359 | ||
95aa81ef JCK |
360 | /** |
361 | * get the show lost events action | |
362 | * | |
363 | * @return The action object | |
46a59db7 | 364 | * @since 2.2 |
95aa81ef JCK |
365 | */ |
366 | public Action getShowLostEventsAction() { | |
367 | if (hideLostEventsAction == null) { | |
368 | /* show lost events */ | |
369 | hideLostEventsAction = new Action(Messages.HistogramView_hideLostEvents, IAction.AS_CHECK_BOX) { | |
370 | @Override | |
371 | public void run() { | |
372 | HistogramScaledData.hideLostEvents = hideLostEventsAction.isChecked(); | |
373 | long maxNbEvents = HistogramScaledData.hideLostEvents ? fFullTraceHistogram.fScaledData.fMaxValue : fFullTraceHistogram.fScaledData.fMaxCombinedValue; | |
3311a6ca | 374 | fFullTraceHistogram.setMaxNbEvents(maxNbEvents); |
95aa81ef | 375 | maxNbEvents = HistogramScaledData.hideLostEvents ? fTimeRangeHistogram.fScaledData.fMaxValue : fTimeRangeHistogram.fScaledData.fMaxCombinedValue; |
3311a6ca | 376 | fTimeRangeHistogram.setMaxNbEvents(maxNbEvents); |
95aa81ef JCK |
377 | } |
378 | }; | |
379 | hideLostEventsAction.setText(Messages.HistogramView_hideLostEvents); | |
380 | hideLostEventsAction.setToolTipText(Messages.HistogramView_hideLostEvents); | |
381 | hideLostEventsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LOST_EVENTS)); | |
382 | } | |
383 | return hideLostEventsAction; | |
384 | } | |
385 | ||
2fc582d2 XR |
386 | /** |
387 | * get the show trace action | |
388 | * | |
389 | * @return The action object | |
390 | * @since 3.0 | |
391 | */ | |
392 | public Action getShowTraceAction() { | |
393 | if (showTraceAction == null) { | |
394 | /* show lost events */ | |
395 | showTraceAction = new Action(Messages.HistogramView_showTraces, IAction.AS_CHECK_BOX) { | |
396 | @Override | |
397 | public void run() { | |
398 | Histogram.showTraces = showTraceAction.isChecked(); | |
399 | fFullTraceHistogram.fCanvas.redraw(); | |
400 | fTimeRangeHistogram.fCanvas.redraw(); | |
401 | updateLegendArea(); | |
402 | } | |
403 | }; | |
404 | showTraceAction.setChecked(true); | |
405 | showTraceAction.setText(Messages.HistogramView_showTraces); | |
406 | showTraceAction.setToolTipText(Messages.HistogramView_showTraces); | |
407 | showTraceAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_HIST_TRACES)); | |
408 | } | |
409 | return showTraceAction; | |
410 | } | |
411 | ||
c392540b FC |
412 | // ------------------------------------------------------------------------ |
413 | // Operations | |
414 | // ------------------------------------------------------------------------ | |
415 | ||
b544077e | 416 | /** |
0fcf3b09 PT |
417 | * Broadcast TmfSignal about new current selection time range. |
418 | * @param beginTime the begin time of current selection. | |
419 | * @param endTime the end time of current selection. | |
b544077e | 420 | */ |
0fcf3b09 PT |
421 | void updateSelectionTime(long beginTime, long endTime) { |
422 | updateDisplayedSelectionTime(beginTime, endTime); | |
423 | TmfTimestamp beginTs = new TmfTimestamp(beginTime, ITmfTimestamp.NANOSECOND_SCALE); | |
424 | TmfTimestamp endTs = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE); | |
425 | TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, beginTs, endTs); | |
426 | fTimeSyncThrottle.queue(signal); | |
c392540b FC |
427 | } |
428 | ||
720d67cb PT |
429 | /** |
430 | * Get selection begin time | |
431 | * @return the begin time of current selection | |
432 | */ | |
433 | long getSelectionBegin() { | |
434 | return fSelectionBeginTime; | |
435 | } | |
436 | ||
437 | /** | |
438 | * Get selection end time | |
439 | * @return the end time of current selection | |
440 | */ | |
441 | long getSelectionEnd() { | |
442 | return fSelectionEndTime; | |
443 | } | |
444 | ||
445 | /** | |
446 | * Get the link state | |
447 | * @return true if begin and end selection time should be linked | |
448 | */ | |
449 | boolean getLinkState() { | |
450 | return fLinkState; | |
451 | } | |
452 | ||
b544077e | 453 | /** |
0fcf3b09 | 454 | * Broadcast TmfSignal about new selection time range. |
b544077e BH |
455 | * @param startTime the new start time |
456 | * @param endTime the new end time | |
457 | */ | |
f8177ba2 | 458 | void updateTimeRange(long startTime, long endTime) { |
faa38350 | 459 | if (fTrace != null) { |
c392540b | 460 | // Build the new time range; keep the current time |
f8177ba2 FC |
461 | TmfTimeRange timeRange = new TmfTimeRange( |
462 | new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE), | |
463 | new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE)); | |
c392540b FC |
464 | fTimeSpanControl.setValue(endTime - startTime); |
465 | ||
38df2c82 AM |
466 | updateDisplayedTimeRange(startTime, endTime); |
467 | ||
c392540b | 468 | // Send the FW signal |
0fcf3b09 | 469 | TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange); |
38df2c82 | 470 | fTimeRangeSyncThrottle.queue(signal); |
c392540b FC |
471 | } |
472 | } | |
473 | ||
b544077e BH |
474 | /** |
475 | * Broadcast TmfSignal about new selected time range. | |
476 | * @param newDuration new duration (relative to current start time) | |
477 | */ | |
c392540b | 478 | public synchronized void updateTimeRange(long newDuration) { |
faa38350 | 479 | if (fTrace != null) { |
6a13fa07 | 480 | long delta = newDuration - fWindowSpan; |
1c6a842a | 481 | long newStartTime = fWindowStartTime - (delta / 2); |
6a13fa07 | 482 | setNewRange(newStartTime, newDuration); |
c392540b FC |
483 | } |
484 | } | |
485 | ||
486 | private void setNewRange(long startTime, long duration) { | |
41b5c37f AM |
487 | long realStart = startTime; |
488 | ||
489 | if (realStart < fTraceStartTime) { | |
490 | realStart = fTraceStartTime; | |
1b055dfa | 491 | } |
c392540b | 492 | |
41b5c37f | 493 | long endTime = realStart + duration; |
faa38350 PT |
494 | if (endTime > fTraceEndTime) { |
495 | endTime = fTraceEndTime; | |
1c6a842a | 496 | if ((endTime - duration) > fTraceStartTime) { |
41b5c37f | 497 | realStart = endTime - duration; |
1b055dfa | 498 | } else { |
41b5c37f | 499 | realStart = fTraceStartTime; |
6a13fa07 | 500 | } |
c392540b | 501 | } |
41b5c37f | 502 | updateTimeRange(realStart, endTime); |
833a21aa | 503 | } |
c392540b FC |
504 | |
505 | // ------------------------------------------------------------------------ | |
506 | // Signal handlers | |
507 | // ------------------------------------------------------------------------ | |
508 | ||
b544077e | 509 | /** |
faa38350 | 510 | * Handles trace opened signal. Loads histogram if new trace time range is not |
b544077e | 511 | * equal <code>TmfTimeRange.NULL_RANGE</code> |
fec1ac0b | 512 | * @param signal the trace opened signal |
faa38350 | 513 | * @since 2.0 |
b544077e | 514 | */ |
1406f802 | 515 | @TmfSignalHandler |
faa38350 | 516 | public void traceOpened(TmfTraceOpenedSignal signal) { |
c392540b | 517 | assert (signal != null); |
faa38350 PT |
518 | fTrace = signal.getTrace(); |
519 | loadTrace(); | |
ecfd1d41 | 520 | } |
550d787e | 521 | |
faa38350 PT |
522 | /** |
523 | * Handles trace selected signal. Loads histogram if new trace time range is not | |
524 | * equal <code>TmfTimeRange.NULL_RANGE</code> | |
525 | * @param signal the trace selected signal | |
526 | * @since 2.0 | |
527 | */ | |
528 | @TmfSignalHandler | |
529 | public void traceSelected(TmfTraceSelectedSignal signal) { | |
530 | assert (signal != null); | |
531 | if (fTrace != signal.getTrace()) { | |
532 | fTrace = signal.getTrace(); | |
533 | loadTrace(); | |
534 | } | |
535 | } | |
536 | ||
537 | private void loadTrace() { | |
c392540b FC |
538 | initializeHistograms(); |
539 | fParent.redraw(); | |
550d787e FC |
540 | } |
541 | ||
ea279a69 | 542 | /** |
faa38350 PT |
543 | * Handles trace closed signal. Clears the view and data model and cancels requests. |
544 | * @param signal the trace closed signal | |
ea279a69 FC |
545 | * @since 2.0 |
546 | */ | |
547 | @TmfSignalHandler | |
faa38350 PT |
548 | public void traceClosed(TmfTraceClosedSignal signal) { |
549 | ||
550 | if (signal.getTrace() != fTrace) { | |
551 | return; | |
552 | } | |
ea279a69 FC |
553 | |
554 | // Kill any running request | |
555 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { | |
556 | fTimeRangeRequest.cancel(); | |
557 | } | |
558 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { | |
559 | fFullTraceRequest.cancel(); | |
560 | } | |
561 | ||
562 | // Initialize the internal data | |
faa38350 PT |
563 | fTrace = null; |
564 | fTraceStartTime = 0L; | |
565 | fTraceEndTime = 0L; | |
f8177ba2 FC |
566 | fWindowStartTime = 0L; |
567 | fWindowEndTime = 0L; | |
d7ee91bb | 568 | fWindowSpan = 0L; |
0fcf3b09 PT |
569 | fSelectionBeginTime = 0L; |
570 | fSelectionEndTime = 0L; | |
ea279a69 FC |
571 | |
572 | // Clear the UI widgets | |
573 | fFullTraceHistogram.clear(); | |
574 | fTimeRangeHistogram.clear(); | |
720d67cb PT |
575 | fSelectionStartControl.setValue(Long.MIN_VALUE); |
576 | fSelectionEndControl.setValue(Long.MIN_VALUE); | |
f8177ba2 | 577 | |
da7bdcbc | 578 | fTimeSpanControl.setValue(Long.MIN_VALUE); |
2fc582d2 XR |
579 | |
580 | for (Control c: fLegendArea.getChildren()) { | |
581 | c.dispose(); | |
582 | } | |
583 | if (fLegendImages != null) { | |
584 | for (Image i: fLegendImages) { | |
585 | i.dispose(); | |
586 | } | |
587 | } | |
588 | fLegendImages = null; | |
589 | fLegendArea.layout(); | |
590 | fLegendArea.getParent().layout(); | |
ea279a69 FC |
591 | } |
592 | ||
b544077e | 593 | /** |
faa38350 | 594 | * Handles trace range updated signal. Extends histogram according to the new time range. If a |
b544077e BH |
595 | * HistogramRequest is already ongoing, it will be cancelled and a new request with the new range |
596 | * will be issued. | |
abbdd66a | 597 | * |
faa38350 PT |
598 | * @param signal the trace range updated signal |
599 | * @since 2.0 | |
b544077e | 600 | */ |
74237cc3 | 601 | @TmfSignalHandler |
faa38350 | 602 | public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) { |
74237cc3 | 603 | |
faa38350 | 604 | if (signal.getTrace() != fTrace) { |
09d11238 PT |
605 | return; |
606 | } | |
607 | ||
74237cc3 FC |
608 | TmfTimeRange fullRange = signal.getRange(); |
609 | ||
faa38350 PT |
610 | fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
611 | fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
74237cc3 | 612 | |
faa38350 PT |
613 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
614 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); | |
74237cc3 | 615 | |
74237cc3 FC |
616 | sendFullRangeRequest(fullRange); |
617 | } | |
c392540b | 618 | |
b544077e | 619 | /** |
faa38350 PT |
620 | * Handles the trace updated signal. Used to update time limits (start and end time) |
621 | * @param signal the trace updated signal | |
622 | * @since 2.0 | |
b544077e | 623 | */ |
a28d503d | 624 | @TmfSignalHandler |
faa38350 PT |
625 | public void traceUpdated(TmfTraceUpdatedSignal signal) { |
626 | if (signal.getTrace() != fTrace) { | |
a28d503d PT |
627 | return; |
628 | } | |
faa38350 PT |
629 | TmfTimeRange fullRange = signal.getTrace().getTimeRange(); |
630 | fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
631 | fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
a28d503d | 632 | |
faa38350 PT |
633 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
634 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); | |
635 | ||
636 | if ((fFullTraceRequest != null) && fFullTraceRequest.getRange().getEndTime().compareTo(signal.getRange().getEndTime()) < 0) { | |
637 | sendFullRangeRequest(fullRange); | |
638 | } | |
639 | } | |
a28d503d | 640 | |
b544077e BH |
641 | /** |
642 | * Handles the current time updated signal. Sets the current time in the time range | |
643 | * histogram as well as the full histogram. | |
abbdd66a | 644 | * |
b544077e BH |
645 | * @param signal the signal to process |
646 | */ | |
c392540b | 647 | @TmfSignalHandler |
80c930fa PT |
648 | public void currentTimeUpdated(final TmfTimeSynchSignal signal) { |
649 | if (Display.getCurrent() == null) { | |
650 | // Make sure the signal is handled in the UI thread | |
651 | Display.getDefault().asyncExec(new Runnable() { | |
652 | @Override | |
653 | public void run() { | |
654 | if (fParent.isDisposed()) { | |
655 | return; | |
656 | } | |
657 | currentTimeUpdated(signal); | |
658 | } | |
659 | }); | |
660 | return; | |
661 | } | |
c392540b | 662 | |
0fcf3b09 PT |
663 | // Update the selected time range |
664 | ITmfTimestamp beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); | |
665 | ITmfTimestamp endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); | |
666 | updateDisplayedSelectionTime(beginTime.getValue(), endTime.getValue()); | |
ecfd1d41 | 667 | } |
f05aabed | 668 | |
b544077e BH |
669 | /** |
670 | * Updates the current time range in the time range histogram and full range histogram. | |
671 | * @param signal the signal to process | |
672 | */ | |
c392540b | 673 | @TmfSignalHandler |
80c930fa PT |
674 | public void timeRangeUpdated(final TmfRangeSynchSignal signal) { |
675 | if (Display.getCurrent() == null) { | |
676 | // Make sure the signal is handled in the UI thread | |
677 | Display.getDefault().asyncExec(new Runnable() { | |
678 | @Override | |
679 | public void run() { | |
680 | if (fParent.isDisposed()) { | |
681 | return; | |
682 | } | |
683 | timeRangeUpdated(signal); | |
684 | } | |
685 | }); | |
686 | return; | |
687 | } | |
c392540b | 688 | |
faa38350 | 689 | if (fTrace != null) { |
1c6a842a PT |
690 | // Validate the time range |
691 | TmfTimeRange range = signal.getCurrentRange().getIntersection(fTrace.getTimeRange()); | |
692 | if (range == null) { | |
693 | return; | |
694 | } | |
695 | ||
38df2c82 AM |
696 | updateDisplayedTimeRange( |
697 | range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(), | |
698 | range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue()); | |
c392540b | 699 | |
38df2c82 | 700 | // Send the event request to populate the small histogram |
c392540b | 701 | sendTimeRangeRequest(fWindowStartTime, fWindowEndTime); |
f8177ba2 | 702 | |
c392540b FC |
703 | fTimeSpanControl.setValue(fWindowSpan); |
704 | } | |
b59134e1 | 705 | } |
c392540b FC |
706 | |
707 | // ------------------------------------------------------------------------ | |
708 | // Helper functions | |
709 | // ------------------------------------------------------------------------ | |
710 | ||
711 | private void initializeHistograms() { | |
faa38350 | 712 | TmfTimeRange fullRange = updateTraceTimeRange(); |
0fcf3b09 PT |
713 | long selectionBeginTime = fTraceManager.getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
714 | long selectionEndTime = fTraceManager.getSelectionEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
248af329 AM |
715 | long startTime = fTraceManager.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
716 | long duration = fTraceManager.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue() - startTime; | |
74237cc3 | 717 | |
faa38350 PT |
718 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
719 | fTimeRangeRequest.cancel(); | |
720 | } | |
74237cc3 | 721 | fTimeRangeHistogram.clear(); |
faa38350 | 722 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
d7ee91bb | 723 | fTimeRangeHistogram.setTimeRange(startTime, duration); |
0fcf3b09 | 724 | fTimeRangeHistogram.setSelection(selectionBeginTime, selectionEndTime); |
2fc582d2 | 725 | fTimeRangeHistogram.fDataModel.setTrace(fTrace); |
c392540b | 726 | |
faa38350 PT |
727 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
728 | fFullTraceRequest.cancel(); | |
729 | } | |
74237cc3 | 730 | fFullTraceHistogram.clear(); |
faa38350 | 731 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
d7ee91bb | 732 | fFullTraceHistogram.setTimeRange(startTime, duration); |
0fcf3b09 | 733 | fFullTraceHistogram.setSelection(selectionBeginTime, selectionEndTime); |
2fc582d2 | 734 | fFullTraceHistogram.fDataModel.setTrace(fTrace); |
c392540b | 735 | |
d7ee91bb PT |
736 | fWindowStartTime = startTime; |
737 | fWindowSpan = duration; | |
738 | fWindowEndTime = startTime + duration; | |
6a13fa07 | 739 | |
0fcf3b09 PT |
740 | fSelectionBeginTime = selectionBeginTime; |
741 | fSelectionEndTime = selectionEndTime; | |
720d67cb PT |
742 | fSelectionStartControl.setValue(fSelectionBeginTime); |
743 | fSelectionEndControl.setValue(fSelectionEndTime); | |
f8177ba2 | 744 | |
d7ee91bb | 745 | fTimeSpanControl.setValue(duration); |
6a13fa07 | 746 | |
2fc582d2 XR |
747 | ITmfTrace[] traces = TmfTraceManager.getTraceSet(fTrace); |
748 | if (traces != null) { | |
749 | this.showTraceAction.setEnabled(traces.length < fFullTraceHistogram.getMaxNbTraces()); | |
750 | } | |
751 | updateLegendArea(); | |
752 | ||
2af7df97 | 753 | if (!fullRange.equals(TmfTimeRange.NULL_RANGE)) { |
d7ee91bb | 754 | sendTimeRangeRequest(startTime, startTime + duration); |
2af7df97 FC |
755 | sendFullRangeRequest(fullRange); |
756 | } | |
74237cc3 FC |
757 | } |
758 | ||
2fc582d2 XR |
759 | private void updateLegendArea() { |
760 | for (Control c: fLegendArea.getChildren()) { | |
761 | c.dispose(); | |
762 | } | |
763 | if (fLegendImages != null) { | |
764 | for (Image i: fLegendImages) { | |
765 | i.dispose(); | |
766 | } | |
767 | } | |
768 | fLegendImages = null; | |
769 | if (fFullTraceHistogram.showTraces()) { | |
770 | ITmfTrace[] traces = TmfTraceManager.getTraceSet(fTrace); | |
771 | fLegendImages = new Image[traces.length]; | |
772 | int traceIndex = 0; | |
773 | for (ITmfTrace trace : traces) { | |
774 | fLegendImages[traceIndex] = new Image(fLegendArea.getDisplay(), 16, 16); | |
775 | GC gc = new GC(fLegendImages[traceIndex]); | |
776 | gc.setBackground(fFullTraceHistogram.getTraceColor(traceIndex)); | |
777 | gc.fillRectangle(0, 0, 15, 15); | |
778 | gc.setForeground(fLegendArea.getDisplay().getSystemColor(SWT.COLOR_BLACK)); | |
779 | gc.drawRectangle(0, 0, 15, 15); | |
780 | gc.dispose(); | |
781 | ||
782 | CLabel label = new CLabel(fLegendArea, SWT.NONE); | |
783 | label.setText(trace.getName()); | |
784 | label.setImage(fLegendImages[traceIndex]); | |
785 | traceIndex++; | |
786 | } | |
787 | } | |
788 | fLegendArea.layout(); | |
789 | fLegendArea.getParent().layout(); | |
790 | } | |
791 | ||
0fcf3b09 PT |
792 | private void updateDisplayedSelectionTime(long beginTime, long endTime) { |
793 | fSelectionBeginTime = beginTime; | |
794 | fSelectionEndTime = endTime; | |
38df2c82 | 795 | |
0fcf3b09 PT |
796 | fFullTraceHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime); |
797 | fTimeRangeHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime); | |
720d67cb PT |
798 | fSelectionStartControl.setValue(fSelectionBeginTime); |
799 | fSelectionEndControl.setValue(fSelectionEndTime); | |
38df2c82 AM |
800 | } |
801 | ||
802 | private void updateDisplayedTimeRange(long start, long end) { | |
803 | fWindowStartTime = start; | |
804 | fWindowEndTime = end; | |
805 | fWindowSpan = fWindowEndTime - fWindowStartTime; | |
806 | fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan); | |
807 | } | |
808 | ||
faa38350 PT |
809 | private TmfTimeRange updateTraceTimeRange() { |
810 | fTraceStartTime = 0L; | |
811 | fTraceEndTime = 0L; | |
74237cc3 | 812 | |
faa38350 | 813 | TmfTimeRange timeRange = fTrace.getTimeRange(); |
c6023803 | 814 | if (!timeRange.equals(TmfTimeRange.NULL_RANGE)) { |
faa38350 PT |
815 | fTraceStartTime = timeRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
816 | fTraceEndTime = timeRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
74237cc3 FC |
817 | } |
818 | return timeRange; | |
b59134e1 | 819 | } |
c392540b FC |
820 | |
821 | private void sendTimeRangeRequest(long startTime, long endTime) { | |
1b055dfa | 822 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
c392540b | 823 | fTimeRangeRequest.cancel(); |
088c1d4e | 824 | } |
f8177ba2 FC |
825 | TmfTimestamp startTS = new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE); |
826 | TmfTimestamp endTS = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE); | |
c392540b FC |
827 | TmfTimeRange timeRange = new TmfTimeRange(startTS, endTS); |
828 | ||
829 | fTimeRangeHistogram.clear(); | |
15844a4e | 830 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
c392540b | 831 | fTimeRangeHistogram.setTimeRange(startTime, endTime - startTime); |
4cf201de | 832 | |
faa38350 | 833 | int cacheSize = fTrace.getCacheSize(); |
2740e05c AM |
834 | fTimeRangeRequest = new HistogramRequest(fTimeRangeHistogram.getDataModel(), |
835 | timeRange, 0, ITmfEventRequest.ALL_DATA, cacheSize, ExecutionType.FOREGROUND, false); | |
faa38350 | 836 | fTrace.sendRequest(fTimeRangeRequest); |
088c1d4e | 837 | } |
c392540b | 838 | |
74237cc3 | 839 | private void sendFullRangeRequest(TmfTimeRange fullRange) { |
1b055dfa | 840 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
c392540b FC |
841 | fFullTraceRequest.cancel(); |
842 | } | |
faa38350 | 843 | int cacheSize = fTrace.getCacheSize(); |
2740e05c AM |
844 | fFullTraceRequest = new HistogramRequest(fFullTraceHistogram.getDataModel(), |
845 | fullRange, | |
846 | (int) fFullTraceHistogram.fDataModel.getNbEvents(), | |
847 | ITmfEventRequest.ALL_DATA, | |
848 | cacheSize, | |
849 | ExecutionType.BACKGROUND, true); | |
faa38350 | 850 | fTrace.sendRequest(fFullTraceRequest); |
ed4b3b9f | 851 | } |
c392540b | 852 | |
95aa81ef JCK |
853 | private void contributeToActionBars() { |
854 | IActionBars bars = getViewSite().getActionBars(); | |
855 | bars.getToolBarManager().add(getShowLostEventsAction()); | |
2fc582d2 | 856 | bars.getToolBarManager().add(getShowTraceAction()); |
95aa81ef JCK |
857 | bars.getToolBarManager().add(new Separator()); |
858 | } | |
859 | ||
720d67cb PT |
860 | private void addLinkButtonListeners() { |
861 | fLinkButton.addMouseListener(new MouseAdapter() { | |
862 | @Override | |
863 | public void mouseDown(MouseEvent e) { | |
864 | fSelectionEndControl.setEnabled(fLinkState); | |
865 | fLinkState = !fLinkState; | |
866 | fLinkButton.redraw(); | |
867 | } | |
868 | }); | |
869 | ||
870 | fLinkButton.addPaintListener(new PaintListener() { | |
871 | @Override | |
872 | public void paintControl(PaintEvent e) { | |
873 | if (fLinkState) { | |
874 | Rectangle r = fLinkButton.getBounds(); | |
875 | r.x = -1; | |
876 | r.y = -1; | |
877 | e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); | |
878 | e.gc.drawRectangle(r); | |
879 | r.x = 0; | |
880 | r.y = 0; | |
881 | e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_DARK_GRAY)); | |
882 | e.gc.drawRectangle(r); | |
883 | } | |
884 | } | |
885 | }); | |
886 | } | |
6e512b93 | 887 | } |