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