Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
e0752744 | 2 | * Copyright (c) 2009, 2010, 2011, 2012 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 |
6e512b93 | 16 | *******************************************************************************/ |
3e9fdb8b | 17 | |
e0752744 | 18 | package org.eclipse.linuxtools.tmf.ui.views.histogram; |
6e512b93 | 19 | |
e0752744 | 20 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 21 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
22 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
23 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
6c13869b | 24 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType; |
f6ad2e3d | 25 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
6c13869b FC |
26 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; |
27 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; | |
28 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; | |
29 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
faa38350 PT |
30 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; |
31 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
32 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal; | |
33 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; | |
34 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; | |
35 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
36 | import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor; | |
b59134e1 WB |
37 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
38 | import org.eclipse.swt.SWT; | |
39 | import org.eclipse.swt.layout.GridData; | |
252ae4bd | 40 | import org.eclipse.swt.layout.GridLayout; |
6e512b93 | 41 | import org.eclipse.swt.widgets.Composite; |
faa38350 PT |
42 | import org.eclipse.ui.IEditorPart; |
43 | import org.eclipse.ui.PlatformUI; | |
6e512b93 | 44 | |
544fe9b7 | 45 | /** |
faa38350 | 46 | * The purpose of this view is to provide graphical time distribution statistics about the trace events. |
544fe9b7 | 47 | * <p> |
c392540b FC |
48 | * The view is composed of two histograms and two controls: |
49 | * <ul> | |
faa38350 | 50 | * <li>an event distribution histogram for the whole trace; |
c392540b FC |
51 | * <li>an event distribution histogram for current time window (window span); |
52 | * <li>the timestamp of the currently selected event; | |
53 | * <li>the window span (size of the time window of the smaller histogram). | |
54 | * </ul> | |
55 | * The histograms x-axis show their respective time range. | |
abbdd66a | 56 | * |
f8177ba2 | 57 | * @version 2.0 |
2af7df97 | 58 | * @author Francois Chouinard |
544fe9b7 | 59 | */ |
c392540b FC |
60 | public class HistogramView extends TmfView { |
61 | ||
62 | // ------------------------------------------------------------------------ | |
63 | // Constants | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
b544077e BH |
66 | /** |
67 | * The view ID as defined in plugin.xml | |
68 | */ | |
e0752744 | 69 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.histogram"; //$NON-NLS-1$ |
c392540b | 70 | |
b544077e BH |
71 | /** |
72 | * The initial window span (in nanoseconds) | |
73 | */ | |
1cceddbe | 74 | public static final long INITIAL_WINDOW_SPAN = (1L * 100 * 1000 * 1000); // .1sec |
c392540b | 75 | |
c392540b FC |
76 | // ------------------------------------------------------------------------ |
77 | // Attributes | |
78 | // ------------------------------------------------------------------------ | |
79 | ||
80 | // Parent widget | |
81 | private Composite fParent; | |
82 | ||
faa38350 PT |
83 | // The current trace |
84 | private ITmfTrace fTrace; | |
c392540b | 85 | |
f8177ba2 | 86 | // Current timestamp/time window - everything in the TIME_SCALE |
faa38350 PT |
87 | private long fTraceStartTime; |
88 | private long fTraceEndTime; | |
c392540b FC |
89 | private long fWindowStartTime; |
90 | private long fWindowEndTime; | |
91 | private long fWindowSpan = INITIAL_WINDOW_SPAN; | |
92 | private long fCurrentTimestamp; | |
93 | ||
94 | // Time controls | |
95 | private HistogramTextControl fCurrentEventTimeControl; | |
96 | private HistogramTextControl fTimeSpanControl; | |
97 | ||
98 | // Histogram/request for the full trace range | |
99 | private static FullTraceHistogram fFullTraceHistogram; | |
100 | private HistogramRequest fFullTraceRequest; | |
101 | ||
102 | // Histogram/request for the selected time range | |
103 | private static TimeRangeHistogram fTimeRangeHistogram; | |
104 | private HistogramRequest fTimeRangeRequest; | |
105 | ||
106 | // ------------------------------------------------------------------------ | |
107 | // Constructor | |
108 | // ------------------------------------------------------------------------ | |
109 | ||
b544077e BH |
110 | /** |
111 | * Default constructor | |
112 | */ | |
c392540b FC |
113 | public HistogramView() { |
114 | super(ID); | |
115 | } | |
116 | ||
6a13fa07 | 117 | @Override |
c392540b | 118 | public void dispose() { |
1b055dfa | 119 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
4dc47e28 FC |
120 | fTimeRangeRequest.cancel(); |
121 | } | |
1b055dfa | 122 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
4dc47e28 FC |
123 | fFullTraceRequest.cancel(); |
124 | } | |
6a13fa07 FC |
125 | fFullTraceHistogram.dispose(); |
126 | fTimeRangeHistogram.dispose(); | |
f8177ba2 FC |
127 | fCurrentEventTimeControl.dispose(); |
128 | fTimeSpanControl.dispose(); | |
4dc47e28 | 129 | super.dispose(); |
c392540b FC |
130 | } |
131 | ||
132 | // ------------------------------------------------------------------------ | |
133 | // TmfView | |
134 | // ------------------------------------------------------------------------ | |
135 | ||
136 | @Override | |
c392540b FC |
137 | public void createPartControl(Composite parent) { |
138 | ||
139 | fParent = parent; | |
140 | ||
141 | // Control labels | |
142 | final String currentEventLabel = Messages.HistogramView_currentEventLabel; | |
143 | final String windowSpanLabel = Messages.HistogramView_windowSpanLabel; | |
144 | ||
145 | // -------------------------------------------------------------------- | |
146 | // Set the HistogramView layout | |
147 | // -------------------------------------------------------------------- | |
148 | ||
149 | Composite viewComposite = new Composite(fParent, SWT.FILL); | |
150 | GridLayout gridLayout = new GridLayout(); | |
151 | gridLayout.numColumns = 2; | |
152 | gridLayout.horizontalSpacing = 5; | |
153 | gridLayout.verticalSpacing = 0; | |
154 | gridLayout.marginHeight = 0; | |
155 | gridLayout.marginWidth = 0; | |
156 | viewComposite.setLayout(gridLayout); | |
157 | ||
158 | // Use all available space | |
159 | GridData gridData = new GridData(); | |
160 | gridData.horizontalAlignment = SWT.FILL; | |
161 | gridData.verticalAlignment = SWT.FILL; | |
162 | gridData.grabExcessHorizontalSpace = true; | |
163 | viewComposite.setLayoutData(gridData); | |
164 | ||
165 | // -------------------------------------------------------------------- | |
166 | // Time controls | |
167 | // -------------------------------------------------------------------- | |
168 | ||
169 | Composite controlsComposite = new Composite(viewComposite, SWT.FILL); | |
170 | gridLayout = new GridLayout(); | |
171 | gridLayout.numColumns = 2; | |
172 | gridLayout.marginHeight = 0; | |
173 | gridLayout.marginWidth = 0; | |
174 | gridLayout.horizontalSpacing = 5; | |
175 | gridLayout.verticalSpacing = 0; | |
f8177ba2 | 176 | gridLayout.makeColumnsEqualWidth = false; |
c392540b FC |
177 | gridLayout.marginLeft = 5; |
178 | gridLayout.marginRight = 5; | |
179 | controlsComposite.setLayout(gridLayout); | |
180 | ||
181 | // Current event time control | |
182 | gridData = new GridData(); | |
183 | gridData.horizontalAlignment = SWT.CENTER; | |
184 | gridData.verticalAlignment = SWT.CENTER; | |
f8177ba2 | 185 | fCurrentEventTimeControl = new HistogramCurrentTimeControl(this, controlsComposite, currentEventLabel, 0L); |
c392540b | 186 | fCurrentEventTimeControl.setLayoutData(gridData); |
f8177ba2 | 187 | fCurrentEventTimeControl.setValue(0L); |
c392540b FC |
188 | |
189 | // Window span time control | |
190 | gridData = new GridData(); | |
191 | gridData.horizontalAlignment = SWT.CENTER; | |
192 | gridData.verticalAlignment = SWT.CENTER; | |
f8177ba2 | 193 | fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L); |
c392540b | 194 | fTimeSpanControl.setLayoutData(gridData); |
f8177ba2 | 195 | fTimeSpanControl.setValue(0L); |
c392540b FC |
196 | |
197 | // -------------------------------------------------------------------- | |
198 | // Time range histogram | |
199 | // -------------------------------------------------------------------- | |
200 | ||
201 | Composite timeRangeComposite = new Composite(viewComposite, SWT.FILL); | |
202 | gridLayout = new GridLayout(); | |
203 | gridLayout.numColumns = 1; | |
204 | gridLayout.marginHeight = 0; | |
205 | gridLayout.marginWidth = 0; | |
206 | gridLayout.marginTop = 5; | |
207 | gridLayout.horizontalSpacing = 0; | |
208 | gridLayout.verticalSpacing = 0; | |
209 | gridLayout.marginLeft = 5; | |
210 | gridLayout.marginRight = 5; | |
211 | timeRangeComposite.setLayout(gridLayout); | |
212 | ||
213 | // Use remaining horizontal space | |
214 | gridData = new GridData(); | |
215 | gridData.horizontalAlignment = SWT.FILL; | |
216 | gridData.verticalAlignment = SWT.FILL; | |
217 | gridData.grabExcessHorizontalSpace = true; | |
218 | timeRangeComposite.setLayoutData(gridData); | |
219 | ||
220 | // Histogram | |
221 | fTimeRangeHistogram = new TimeRangeHistogram(this, timeRangeComposite); | |
222 | ||
223 | // -------------------------------------------------------------------- | |
224 | // Full range histogram | |
225 | // -------------------------------------------------------------------- | |
226 | ||
227 | Composite fullRangeComposite = new Composite(viewComposite, SWT.FILL); | |
228 | gridLayout = new GridLayout(); | |
229 | gridLayout.numColumns = 1; | |
230 | gridLayout.marginHeight = 0; | |
231 | gridLayout.marginWidth = 0; | |
232 | gridLayout.marginTop = 5; | |
233 | gridLayout.horizontalSpacing = 0; | |
234 | gridLayout.verticalSpacing = 0; | |
235 | gridLayout.marginLeft = 5; | |
236 | gridLayout.marginRight = 5; | |
237 | fullRangeComposite.setLayout(gridLayout); | |
238 | ||
239 | // Use remaining horizontal space | |
240 | gridData = new GridData(); | |
241 | gridData.horizontalAlignment = SWT.FILL; | |
242 | gridData.verticalAlignment = SWT.FILL; | |
243 | gridData.horizontalSpan = 2; | |
244 | gridData.grabExcessHorizontalSpace = true; | |
245 | fullRangeComposite.setLayoutData(gridData); | |
246 | ||
247 | // Histogram | |
248 | fFullTraceHistogram = new FullTraceHistogram(this, fullRangeComposite); | |
249 | ||
faa38350 PT |
250 | IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); |
251 | if (editor instanceof ITmfTraceEditor) { | |
252 | ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace(); | |
253 | if (trace != null) { | |
254 | traceSelected(new TmfTraceSelectedSignal(this, trace)); | |
255 | } | |
1b055dfa | 256 | } |
ecfd1d41 | 257 | } |
c392540b FC |
258 | |
259 | @Override | |
c392540b | 260 | public void setFocus() { |
faa38350 | 261 | fFullTraceHistogram.fCanvas.setFocus(); |
833a21aa | 262 | } |
c392540b | 263 | |
f8177ba2 FC |
264 | void refresh() { |
265 | fParent.layout(true); | |
266 | } | |
267 | ||
c392540b FC |
268 | // ------------------------------------------------------------------------ |
269 | // Accessors | |
270 | // ------------------------------------------------------------------------ | |
271 | ||
faa38350 PT |
272 | /** |
273 | * Returns the current trace handled by the view | |
274 | * | |
275 | * @return the current trace | |
276 | * @since 2.0 | |
277 | */ | |
278 | public ITmfTrace getTrace() { | |
279 | return fTrace; | |
280 | } | |
281 | ||
b544077e BH |
282 | /** |
283 | * Returns the time range of the current selected window (base on default time scale). | |
abbdd66a | 284 | * |
b544077e BH |
285 | * @return the time range of current selected window. |
286 | */ | |
c392540b | 287 | public TmfTimeRange getTimeRange() { |
f8177ba2 FC |
288 | return new TmfTimeRange( |
289 | new TmfTimestamp(fWindowStartTime, ITmfTimestamp.NANOSECOND_SCALE), | |
290 | new TmfTimestamp(fWindowEndTime, ITmfTimestamp.NANOSECOND_SCALE)); | |
c392540b FC |
291 | } |
292 | ||
293 | // ------------------------------------------------------------------------ | |
294 | // Operations | |
295 | // ------------------------------------------------------------------------ | |
296 | ||
b544077e BH |
297 | /** |
298 | * Broadcast TmfSignal about new current time value. | |
299 | * @param newTime the new current time. | |
300 | */ | |
f8177ba2 | 301 | void updateCurrentEventTime(long newTime) { |
faa38350 | 302 | if (fTrace != null) { |
f8177ba2 | 303 | TmfTimeRange timeRange = new TmfTimeRange(new TmfTimestamp(newTime, ITmfTimestamp.NANOSECOND_SCALE), TmfTimestamp.BIG_CRUNCH); |
f6ad2e3d | 304 | HistogramRequest request = new HistogramRequest(fTimeRangeHistogram.getDataModel(), timeRange, 0, 1, 0, ExecutionType.FOREGROUND) { |
c392540b | 305 | @Override |
e0752744 | 306 | public void handleData(ITmfEvent event) { |
c392540b FC |
307 | if (event != null) { |
308 | TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, event.getTimestamp()); | |
309 | TmfSignalManager.dispatchSignal(signal); | |
310 | } | |
311 | } | |
312 | }; | |
faa38350 | 313 | fTrace.sendRequest(request); |
c392540b FC |
314 | } |
315 | } | |
316 | ||
b544077e BH |
317 | /** |
318 | * Broadcast TmfSignal about new selected time range. | |
319 | * @param startTime the new start time | |
320 | * @param endTime the new end time | |
321 | */ | |
f8177ba2 | 322 | void updateTimeRange(long startTime, long endTime) { |
faa38350 | 323 | if (fTrace != null) { |
c392540b | 324 | // Build the new time range; keep the current time |
f8177ba2 FC |
325 | TmfTimeRange timeRange = new TmfTimeRange( |
326 | new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE), | |
327 | new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE)); | |
328 | ITmfTimestamp currentTime = new TmfTimestamp(fCurrentTimestamp, ITmfTimestamp.NANOSECOND_SCALE); | |
c392540b FC |
329 | fTimeSpanControl.setValue(endTime - startTime); |
330 | ||
331 | // Send the FW signal | |
332 | TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange, currentTime); | |
333 | TmfSignalManager.dispatchSignal(signal); | |
334 | } | |
335 | } | |
336 | ||
b544077e BH |
337 | /** |
338 | * Broadcast TmfSignal about new selected time range. | |
339 | * @param newDuration new duration (relative to current start time) | |
340 | */ | |
c392540b | 341 | public synchronized void updateTimeRange(long newDuration) { |
faa38350 | 342 | if (fTrace != null) { |
6a13fa07 | 343 | long delta = newDuration - fWindowSpan; |
1b055dfa | 344 | long newStartTime = fWindowStartTime + (delta / 2); |
6a13fa07 | 345 | setNewRange(newStartTime, newDuration); |
c392540b FC |
346 | } |
347 | } | |
348 | ||
349 | private void setNewRange(long startTime, long duration) { | |
faa38350 PT |
350 | if (startTime < fTraceStartTime) { |
351 | startTime = fTraceStartTime; | |
1b055dfa | 352 | } |
c392540b FC |
353 | |
354 | long endTime = startTime + duration; | |
faa38350 PT |
355 | if (endTime > fTraceEndTime) { |
356 | endTime = fTraceEndTime; | |
357 | if ((endTime - duration) > fTraceEndTime) { | |
6a13fa07 | 358 | startTime = endTime - duration; |
1b055dfa | 359 | } else { |
faa38350 | 360 | startTime = fTraceStartTime; |
6a13fa07 | 361 | } |
c392540b FC |
362 | } |
363 | updateTimeRange(startTime, endTime); | |
833a21aa | 364 | } |
c392540b FC |
365 | |
366 | // ------------------------------------------------------------------------ | |
367 | // Signal handlers | |
368 | // ------------------------------------------------------------------------ | |
369 | ||
b544077e | 370 | /** |
faa38350 | 371 | * Handles trace opened signal. Loads histogram if new trace time range is not |
b544077e | 372 | * equal <code>TmfTimeRange.NULL_RANGE</code> |
faa38350 PT |
373 | * @param signal the trace selected signal |
374 | * @since 2.0 | |
b544077e | 375 | */ |
1406f802 | 376 | @TmfSignalHandler |
faa38350 | 377 | public void traceOpened(TmfTraceOpenedSignal signal) { |
c392540b | 378 | assert (signal != null); |
faa38350 PT |
379 | fTrace = signal.getTrace(); |
380 | loadTrace(); | |
ecfd1d41 | 381 | } |
550d787e | 382 | |
faa38350 PT |
383 | /** |
384 | * Handles trace selected signal. Loads histogram if new trace time range is not | |
385 | * equal <code>TmfTimeRange.NULL_RANGE</code> | |
386 | * @param signal the trace selected signal | |
387 | * @since 2.0 | |
388 | */ | |
389 | @TmfSignalHandler | |
390 | public void traceSelected(TmfTraceSelectedSignal signal) { | |
391 | assert (signal != null); | |
392 | if (fTrace != signal.getTrace()) { | |
393 | fTrace = signal.getTrace(); | |
394 | loadTrace(); | |
395 | } | |
396 | } | |
397 | ||
398 | private void loadTrace() { | |
c392540b FC |
399 | initializeHistograms(); |
400 | fParent.redraw(); | |
550d787e FC |
401 | } |
402 | ||
ea279a69 | 403 | /** |
faa38350 PT |
404 | * Handles trace closed signal. Clears the view and data model and cancels requests. |
405 | * @param signal the trace closed signal | |
ea279a69 FC |
406 | * @since 2.0 |
407 | */ | |
408 | @TmfSignalHandler | |
faa38350 PT |
409 | public void traceClosed(TmfTraceClosedSignal signal) { |
410 | ||
411 | if (signal.getTrace() != fTrace) { | |
412 | return; | |
413 | } | |
ea279a69 FC |
414 | |
415 | // Kill any running request | |
416 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { | |
417 | fTimeRangeRequest.cancel(); | |
418 | } | |
419 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { | |
420 | fFullTraceRequest.cancel(); | |
421 | } | |
422 | ||
423 | // Initialize the internal data | |
faa38350 PT |
424 | fTrace = null; |
425 | fTraceStartTime = 0L; | |
426 | fTraceEndTime = 0L; | |
f8177ba2 FC |
427 | fWindowStartTime = 0L; |
428 | fWindowEndTime = 0L; | |
ea279a69 | 429 | fWindowSpan = INITIAL_WINDOW_SPAN; |
f8177ba2 | 430 | fCurrentTimestamp = 0L; |
ea279a69 FC |
431 | |
432 | // Clear the UI widgets | |
433 | fFullTraceHistogram.clear(); | |
434 | fTimeRangeHistogram.clear(); | |
f8177ba2 FC |
435 | fCurrentEventTimeControl.setValue(0L); |
436 | ||
ea279a69 FC |
437 | fTimeSpanControl.setValue(0); |
438 | } | |
439 | ||
b544077e | 440 | /** |
faa38350 | 441 | * Handles trace range updated signal. Extends histogram according to the new time range. If a |
b544077e BH |
442 | * HistogramRequest is already ongoing, it will be cancelled and a new request with the new range |
443 | * will be issued. | |
abbdd66a | 444 | * |
faa38350 PT |
445 | * @param signal the trace range updated signal |
446 | * @since 2.0 | |
b544077e | 447 | */ |
74237cc3 | 448 | @TmfSignalHandler |
faa38350 | 449 | public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) { |
74237cc3 | 450 | |
faa38350 | 451 | if (signal.getTrace() != fTrace) { |
09d11238 PT |
452 | return; |
453 | } | |
454 | ||
faa38350 | 455 | boolean drawTimeRangeHistogram = fTraceStartTime == 0; |
74237cc3 FC |
456 | TmfTimeRange fullRange = signal.getRange(); |
457 | ||
faa38350 PT |
458 | fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
459 | fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
74237cc3 | 460 | |
faa38350 PT |
461 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
462 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); | |
74237cc3 FC |
463 | |
464 | if (drawTimeRangeHistogram) { | |
faa38350 | 465 | fCurrentTimestamp = fTraceStartTime; |
74237cc3 | 466 | fCurrentEventTimeControl.setValue(fCurrentTimestamp); |
faa38350 PT |
467 | fFullTraceHistogram.setTimeRange(fTraceStartTime, INITIAL_WINDOW_SPAN); |
468 | fTimeRangeHistogram.setTimeRange(fTraceStartTime, INITIAL_WINDOW_SPAN); | |
469 | sendTimeRangeRequest(fTraceStartTime, fTraceStartTime + INITIAL_WINDOW_SPAN); | |
74237cc3 FC |
470 | } |
471 | ||
472 | sendFullRangeRequest(fullRange); | |
473 | } | |
c392540b | 474 | |
b544077e | 475 | /** |
faa38350 PT |
476 | * Handles the trace updated signal. Used to update time limits (start and end time) |
477 | * @param signal the trace updated signal | |
478 | * @since 2.0 | |
b544077e | 479 | */ |
a28d503d | 480 | @TmfSignalHandler |
faa38350 PT |
481 | public void traceUpdated(TmfTraceUpdatedSignal signal) { |
482 | if (signal.getTrace() != fTrace) { | |
a28d503d PT |
483 | return; |
484 | } | |
faa38350 PT |
485 | TmfTimeRange fullRange = signal.getTrace().getTimeRange(); |
486 | fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
487 | fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
a28d503d | 488 | |
faa38350 PT |
489 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
490 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); | |
491 | ||
492 | if ((fFullTraceRequest != null) && fFullTraceRequest.getRange().getEndTime().compareTo(signal.getRange().getEndTime()) < 0) { | |
493 | sendFullRangeRequest(fullRange); | |
494 | } | |
495 | } | |
a28d503d | 496 | |
b544077e BH |
497 | /** |
498 | * Handles the current time updated signal. Sets the current time in the time range | |
499 | * histogram as well as the full histogram. | |
abbdd66a | 500 | * |
b544077e BH |
501 | * @param signal the signal to process |
502 | */ | |
c392540b FC |
503 | @TmfSignalHandler |
504 | public void currentTimeUpdated(TmfTimeSynchSignal signal) { | |
505 | // Because this can't happen :-) | |
506 | assert (signal != null); | |
507 | ||
508 | // Update the selected event time | |
f8177ba2 FC |
509 | ITmfTimestamp currentTime = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE); |
510 | fCurrentTimestamp = currentTime.getValue(); | |
c392540b FC |
511 | |
512 | // Notify the relevant widgets | |
513 | fFullTraceHistogram.setCurrentEvent(fCurrentTimestamp); | |
514 | fTimeRangeHistogram.setCurrentEvent(fCurrentTimestamp); | |
515 | fCurrentEventTimeControl.setValue(fCurrentTimestamp); | |
ecfd1d41 | 516 | } |
f05aabed | 517 | |
b544077e BH |
518 | /** |
519 | * Updates the current time range in the time range histogram and full range histogram. | |
520 | * @param signal the signal to process | |
521 | */ | |
c392540b FC |
522 | @TmfSignalHandler |
523 | public void timeRangeUpdated(TmfRangeSynchSignal signal) { | |
524 | // Because this can't happen :-) | |
525 | assert (signal != null); | |
526 | ||
faa38350 | 527 | if (fTrace != null) { |
c392540b | 528 | // Update the time range |
f8177ba2 FC |
529 | fWindowStartTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
530 | fWindowEndTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
c392540b FC |
531 | fWindowSpan = fWindowEndTime - fWindowStartTime; |
532 | ||
533 | // Notify the relevant widgets | |
534 | sendTimeRangeRequest(fWindowStartTime, fWindowEndTime); | |
535 | fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan); | |
f8177ba2 | 536 | |
c392540b FC |
537 | fTimeSpanControl.setValue(fWindowSpan); |
538 | } | |
b59134e1 | 539 | } |
c392540b FC |
540 | |
541 | // ------------------------------------------------------------------------ | |
542 | // Helper functions | |
543 | // ------------------------------------------------------------------------ | |
544 | ||
545 | private void initializeHistograms() { | |
faa38350 | 546 | TmfTimeRange fullRange = updateTraceTimeRange(); |
74237cc3 | 547 | |
faa38350 PT |
548 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
549 | fTimeRangeRequest.cancel(); | |
550 | } | |
74237cc3 | 551 | fTimeRangeHistogram.clear(); |
faa38350 PT |
552 | fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
553 | fTimeRangeHistogram.setTimeRange(fTraceStartTime, INITIAL_WINDOW_SPAN); | |
554 | fTimeRangeHistogram.setCurrentEvent(fTraceStartTime); | |
c392540b | 555 | |
faa38350 PT |
556 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
557 | fFullTraceRequest.cancel(); | |
558 | } | |
74237cc3 | 559 | fFullTraceHistogram.clear(); |
faa38350 PT |
560 | fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime); |
561 | fFullTraceHistogram.setTimeRange(fTraceStartTime, INITIAL_WINDOW_SPAN); | |
562 | fFullTraceHistogram.setCurrentEvent(fTraceStartTime); | |
c392540b | 563 | |
faa38350 | 564 | fWindowStartTime = fTraceStartTime; |
c392540b FC |
565 | fWindowSpan = INITIAL_WINDOW_SPAN; |
566 | fWindowEndTime = fWindowStartTime + fWindowSpan; | |
6a13fa07 | 567 | |
faa38350 | 568 | fCurrentEventTimeControl.setValue(fTraceStartTime); |
f8177ba2 | 569 | |
c392540b | 570 | fTimeSpanControl.setValue(fWindowSpan); |
6a13fa07 | 571 | |
2af7df97 | 572 | if (!fullRange.equals(TmfTimeRange.NULL_RANGE)) { |
faa38350 | 573 | sendTimeRangeRequest(fTraceStartTime, fTraceStartTime + fWindowSpan); |
2af7df97 FC |
574 | sendFullRangeRequest(fullRange); |
575 | } | |
74237cc3 FC |
576 | } |
577 | ||
faa38350 PT |
578 | private TmfTimeRange updateTraceTimeRange() { |
579 | fTraceStartTime = 0L; | |
580 | fTraceEndTime = 0L; | |
f8177ba2 | 581 | fCurrentTimestamp = 0L; |
74237cc3 | 582 | |
faa38350 | 583 | TmfTimeRange timeRange = fTrace.getTimeRange(); |
c6023803 | 584 | if (!timeRange.equals(TmfTimeRange.NULL_RANGE)) { |
faa38350 PT |
585 | fTraceStartTime = timeRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
586 | fTraceEndTime = timeRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
587 | fCurrentTimestamp = fTraceStartTime; | |
74237cc3 FC |
588 | } |
589 | return timeRange; | |
b59134e1 | 590 | } |
c392540b FC |
591 | |
592 | private void sendTimeRangeRequest(long startTime, long endTime) { | |
1b055dfa | 593 | if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) { |
c392540b | 594 | fTimeRangeRequest.cancel(); |
088c1d4e | 595 | } |
f8177ba2 FC |
596 | TmfTimestamp startTS = new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE); |
597 | TmfTimestamp endTS = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE); | |
c392540b FC |
598 | TmfTimeRange timeRange = new TmfTimeRange(startTS, endTS); |
599 | ||
600 | fTimeRangeHistogram.clear(); | |
601 | fTimeRangeHistogram.setTimeRange(startTime, endTime - startTime); | |
4cf201de | 602 | |
faa38350 | 603 | int cacheSize = fTrace.getCacheSize(); |
f6ad2e3d | 604 | fTimeRangeRequest = new HistogramRequest(fTimeRangeHistogram.getDataModel(), timeRange, 0, TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.FOREGROUND); |
faa38350 | 605 | fTrace.sendRequest(fTimeRangeRequest); |
088c1d4e | 606 | } |
c392540b | 607 | |
74237cc3 | 608 | private void sendFullRangeRequest(TmfTimeRange fullRange) { |
1b055dfa | 609 | if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) { |
c392540b FC |
610 | fFullTraceRequest.cancel(); |
611 | } | |
faa38350 | 612 | int cacheSize = fTrace.getCacheSize(); |
fbd124dd | 613 | fFullTraceRequest = new HistogramRequest(fFullTraceHistogram.getDataModel(), fullRange, (int) fFullTraceHistogram.fDataModel.getNbEvents(), |
f6ad2e3d | 614 | TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.BACKGROUND); |
faa38350 | 615 | fTrace.sendRequest(fFullTraceRequest); |
ed4b3b9f | 616 | } |
c392540b | 617 | |
6e512b93 | 618 | } |