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