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