Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramView.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * William Bourque - Initial API and implementation
11 * Yuriy Vashchuk - GUI reorganisation, simplification and some related code improvements.
12 * Yuriy Vashchuk - Histograms optimisation.
13 * Yuriy Vashchuk - Histogram Canvas Heritage correction
14 * Francois Chouinard - Cleanup and refactoring
15 * Francois Chouinard - Moved from LTTng to TMF
16 * Patrick Tasse - Update for mouse wheel zoom
17 *******************************************************************************/
18
19 package org.eclipse.linuxtools.tmf.ui.views.histogram;
20
21 import org.eclipse.jface.action.Action;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.action.Separator;
24 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
25 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
26 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
27 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
28 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
29 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
30 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler;
31 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
32 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
33 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
34 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
35 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
36 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
37 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
38 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
39 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
40 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
41 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
42 import org.eclipse.swt.SWT;
43 import org.eclipse.swt.events.MouseWheelListener;
44 import org.eclipse.swt.layout.GridData;
45 import org.eclipse.swt.layout.GridLayout;
46 import org.eclipse.swt.widgets.Composite;
47 import org.eclipse.ui.IActionBars;
48
49 /**
50 * The purpose of this view is to provide graphical time distribution statistics about the trace events.
51 * <p>
52 * The view is composed of two histograms and two controls:
53 * <ul>
54 * <li>an event distribution histogram for the whole trace;
55 * <li>an event distribution histogram for current time window (window span);
56 * <li>the timestamp of the currently selected event;
57 * <li>the window span (size of the time window of the smaller histogram).
58 * </ul>
59 * The histograms x-axis show their respective time range.
60 *
61 * @version 2.0
62 * @author Francois Chouinard
63 */
64 public class HistogramView extends TmfView {
65
66 // ------------------------------------------------------------------------
67 // Constants
68 // ------------------------------------------------------------------------
69
70 /**
71 * The view ID as defined in plugin.xml
72 */
73 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.histogram"; //$NON-NLS-1$
74
75 // ------------------------------------------------------------------------
76 // Attributes
77 // ------------------------------------------------------------------------
78
79 // Parent widget
80 private Composite fParent;
81
82 // The current trace
83 private ITmfTrace fTrace;
84
85 // Current timestamp/time window - everything in the TIME_SCALE
86 private long fTraceStartTime;
87 private long fTraceEndTime;
88 private long fWindowStartTime;
89 private long fWindowEndTime;
90 private long fWindowSpan;
91 private long fSelectionBeginTime;
92 private long fSelectionEndTime;
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 // Throttlers for the time sync and time-range sync signals
107 private final TmfSignalThrottler fTimeSyncThrottle;
108 private final TmfSignalThrottler fTimeRangeSyncThrottle;
109
110 // Action for toggle showing the lost events
111 private Action hideLostEventsAction;
112
113 // ------------------------------------------------------------------------
114 // Constructor
115 // ------------------------------------------------------------------------
116
117 /**
118 * Default constructor
119 */
120 public HistogramView() {
121 super(ID);
122 fTimeSyncThrottle = new TmfSignalThrottler(this, 200);
123 fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200);
124 }
125
126 @Override
127 public void dispose() {
128 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
129 fTimeRangeRequest.cancel();
130 }
131 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
132 fFullTraceRequest.cancel();
133 }
134 fFullTraceHistogram.dispose();
135 fTimeRangeHistogram.dispose();
136 fCurrentEventTimeControl.dispose();
137 fTimeSpanControl.dispose();
138 super.dispose();
139 }
140
141 // ------------------------------------------------------------------------
142 // TmfView
143 // ------------------------------------------------------------------------
144
145 @Override
146 public void createPartControl(Composite parent) {
147
148 fParent = parent;
149
150 // Control labels
151 final String currentEventLabel = Messages.HistogramView_currentEventLabel;
152 final String windowSpanLabel = Messages.HistogramView_windowSpanLabel;
153
154 // --------------------------------------------------------------------
155 // Set the HistogramView layout
156 // --------------------------------------------------------------------
157
158 Composite viewComposite = new Composite(fParent, SWT.FILL);
159 GridLayout gridLayout = new GridLayout();
160 gridLayout.numColumns = 2;
161 gridLayout.horizontalSpacing = 5;
162 gridLayout.verticalSpacing = 0;
163 gridLayout.marginHeight = 0;
164 gridLayout.marginWidth = 0;
165 viewComposite.setLayout(gridLayout);
166
167 // Use all available space
168 GridData gridData = new GridData();
169 gridData.horizontalAlignment = SWT.FILL;
170 gridData.verticalAlignment = SWT.FILL;
171 gridData.grabExcessHorizontalSpace = true;
172 viewComposite.setLayoutData(gridData);
173
174 // --------------------------------------------------------------------
175 // Time controls
176 // --------------------------------------------------------------------
177
178 Composite controlsComposite = new Composite(viewComposite, SWT.FILL);
179 gridLayout = new GridLayout();
180 gridLayout.numColumns = 2;
181 gridLayout.marginHeight = 0;
182 gridLayout.marginWidth = 0;
183 gridLayout.horizontalSpacing = 5;
184 gridLayout.verticalSpacing = 0;
185 gridLayout.makeColumnsEqualWidth = false;
186 gridLayout.marginLeft = 5;
187 gridLayout.marginRight = 5;
188 controlsComposite.setLayout(gridLayout);
189
190 // Current event time control
191 gridData = new GridData();
192 gridData.horizontalAlignment = SWT.CENTER;
193 gridData.verticalAlignment = SWT.CENTER;
194 fCurrentEventTimeControl = new HistogramCurrentTimeControl(this, controlsComposite, currentEventLabel, 0L);
195 fCurrentEventTimeControl.setLayoutData(gridData);
196 fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
197
198 // Window span time control
199 gridData = new GridData();
200 gridData.horizontalAlignment = SWT.CENTER;
201 gridData.verticalAlignment = SWT.CENTER;
202 fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L);
203 fTimeSpanControl.setLayoutData(gridData);
204 fTimeSpanControl.setValue(Long.MIN_VALUE);
205
206 // --------------------------------------------------------------------
207 // Time range histogram
208 // --------------------------------------------------------------------
209
210 Composite timeRangeComposite = new Composite(viewComposite, SWT.FILL);
211 gridLayout = new GridLayout();
212 gridLayout.numColumns = 1;
213 gridLayout.marginHeight = 0;
214 gridLayout.marginWidth = 0;
215 gridLayout.marginTop = 5;
216 gridLayout.horizontalSpacing = 0;
217 gridLayout.verticalSpacing = 0;
218 gridLayout.marginLeft = 5;
219 gridLayout.marginRight = 5;
220 timeRangeComposite.setLayout(gridLayout);
221
222 // Use remaining horizontal space
223 gridData = new GridData();
224 gridData.horizontalAlignment = SWT.FILL;
225 gridData.verticalAlignment = SWT.FILL;
226 gridData.grabExcessHorizontalSpace = true;
227 timeRangeComposite.setLayoutData(gridData);
228
229 // Histogram
230 fTimeRangeHistogram = new TimeRangeHistogram(this, timeRangeComposite);
231
232 // --------------------------------------------------------------------
233 // Full range histogram
234 // --------------------------------------------------------------------
235
236 Composite fullRangeComposite = new Composite(viewComposite, SWT.FILL);
237 gridLayout = new GridLayout();
238 gridLayout.numColumns = 1;
239 gridLayout.marginHeight = 0;
240 gridLayout.marginWidth = 0;
241 gridLayout.marginTop = 5;
242 gridLayout.horizontalSpacing = 0;
243 gridLayout.verticalSpacing = 0;
244 gridLayout.marginLeft = 5;
245 gridLayout.marginRight = 5;
246 fullRangeComposite.setLayout(gridLayout);
247
248 // Use remaining horizontal space
249 gridData = new GridData();
250 gridData.horizontalAlignment = SWT.FILL;
251 gridData.verticalAlignment = SWT.FILL;
252 gridData.horizontalSpan = 2;
253 gridData.grabExcessHorizontalSpace = true;
254 fullRangeComposite.setLayoutData(gridData);
255
256 // Histogram
257 fFullTraceHistogram = new FullTraceHistogram(this, fullRangeComposite);
258
259 // Add mouse wheel listener to time span control
260 MouseWheelListener listener = fFullTraceHistogram.getZoom();
261 fTimeSpanControl.addMouseWheelListener(listener);
262
263
264 // View Action Handling
265 contributeToActionBars();
266
267 ITmfTrace trace = getActiveTrace();
268 if (trace != null) {
269 traceSelected(new TmfTraceSelectedSignal(this, trace));
270 }
271 }
272
273 @Override
274 public void setFocus() {
275 fFullTraceHistogram.fCanvas.setFocus();
276 }
277
278 void refresh() {
279 fParent.layout(true);
280 }
281
282 // ------------------------------------------------------------------------
283 // Accessors
284 // ------------------------------------------------------------------------
285
286 /**
287 * Returns the current trace handled by the view
288 *
289 * @return the current trace
290 * @since 2.0
291 */
292 public ITmfTrace getTrace() {
293 return fTrace;
294 }
295
296 /**
297 * Returns the time range of the current selected window (base on default time scale).
298 *
299 * @return the time range of current selected window.
300 * @since 2.0
301 */
302 public TmfTimeRange getTimeRange() {
303 return new TmfTimeRange(
304 new TmfTimestamp(fWindowStartTime, ITmfTimestamp.NANOSECOND_SCALE),
305 new TmfTimestamp(fWindowEndTime, ITmfTimestamp.NANOSECOND_SCALE));
306 }
307
308 /**
309 * get the show lost events action
310 *
311 * @return The action object
312 * @since 2.2
313 */
314 public Action getShowLostEventsAction() {
315 if (hideLostEventsAction == null) {
316 /* show lost events */
317 hideLostEventsAction = new Action(Messages.HistogramView_hideLostEvents, IAction.AS_CHECK_BOX) {
318 @Override
319 public void run() {
320 HistogramScaledData.hideLostEvents = hideLostEventsAction.isChecked();
321 long maxNbEvents = HistogramScaledData.hideLostEvents ? fFullTraceHistogram.fScaledData.fMaxValue : fFullTraceHistogram.fScaledData.fMaxCombinedValue;
322 fFullTraceHistogram.getMaxNbEventsText().setText(Long.toString(maxNbEvents));
323 fFullTraceHistogram.getMaxNbEventsText().getParent().layout();
324 fFullTraceHistogram.fCanvas.redraw();
325 maxNbEvents = HistogramScaledData.hideLostEvents ? fTimeRangeHistogram.fScaledData.fMaxValue : fTimeRangeHistogram.fScaledData.fMaxCombinedValue;
326 fTimeRangeHistogram.getMaxNbEventsText().setText(Long.toString(maxNbEvents));
327 fTimeRangeHistogram.getMaxNbEventsText().getParent().layout();
328 fTimeRangeHistogram.fCanvas.redraw();
329 }
330 };
331 hideLostEventsAction.setText(Messages.HistogramView_hideLostEvents);
332 hideLostEventsAction.setToolTipText(Messages.HistogramView_hideLostEvents);
333 hideLostEventsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LOST_EVENTS));
334 }
335 return hideLostEventsAction;
336 }
337
338 // ------------------------------------------------------------------------
339 // Operations
340 // ------------------------------------------------------------------------
341
342 /**
343 * Broadcast TmfSignal about new current selection time range.
344 * @param beginTime the begin time of current selection.
345 * @param endTime the end time of current selection.
346 */
347 void updateSelectionTime(long beginTime, long endTime) {
348 updateDisplayedSelectionTime(beginTime, endTime);
349 TmfTimestamp beginTs = new TmfTimestamp(beginTime, ITmfTimestamp.NANOSECOND_SCALE);
350 TmfTimestamp endTs = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE);
351 TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, beginTs, endTs);
352 fTimeSyncThrottle.queue(signal);
353 }
354
355 /**
356 * Broadcast TmfSignal about new selection time range.
357 * @param startTime the new start time
358 * @param endTime the new end time
359 */
360 void updateTimeRange(long startTime, long endTime) {
361 if (fTrace != null) {
362 // Build the new time range; keep the current time
363 TmfTimeRange timeRange = new TmfTimeRange(
364 new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE),
365 new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE));
366 fTimeSpanControl.setValue(endTime - startTime);
367
368 updateDisplayedTimeRange(startTime, endTime);
369
370 // Send the FW signal
371 TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange);
372 fTimeRangeSyncThrottle.queue(signal);
373 }
374 }
375
376 /**
377 * Broadcast TmfSignal about new selected time range.
378 * @param newDuration new duration (relative to current start time)
379 */
380 public synchronized void updateTimeRange(long newDuration) {
381 if (fTrace != null) {
382 long delta = newDuration - fWindowSpan;
383 long newStartTime = fWindowStartTime - (delta / 2);
384 setNewRange(newStartTime, newDuration);
385 }
386 }
387
388 private void setNewRange(long startTime, long duration) {
389 long realStart = startTime;
390
391 if (realStart < fTraceStartTime) {
392 realStart = fTraceStartTime;
393 }
394
395 long endTime = realStart + duration;
396 if (endTime > fTraceEndTime) {
397 endTime = fTraceEndTime;
398 if ((endTime - duration) > fTraceStartTime) {
399 realStart = endTime - duration;
400 } else {
401 realStart = fTraceStartTime;
402 }
403 }
404 updateTimeRange(realStart, endTime);
405 }
406
407 // ------------------------------------------------------------------------
408 // Signal handlers
409 // ------------------------------------------------------------------------
410
411 /**
412 * Handles trace opened signal. Loads histogram if new trace time range is not
413 * equal <code>TmfTimeRange.NULL_RANGE</code>
414 * @param signal the trace opened signal
415 * @since 2.0
416 */
417 @TmfSignalHandler
418 public void traceOpened(TmfTraceOpenedSignal signal) {
419 assert (signal != null);
420 fTrace = signal.getTrace();
421 loadTrace();
422 }
423
424 /**
425 * Handles trace selected signal. Loads histogram if new trace time range is not
426 * equal <code>TmfTimeRange.NULL_RANGE</code>
427 * @param signal the trace selected signal
428 * @since 2.0
429 */
430 @TmfSignalHandler
431 public void traceSelected(TmfTraceSelectedSignal signal) {
432 assert (signal != null);
433 if (fTrace != signal.getTrace()) {
434 fTrace = signal.getTrace();
435 loadTrace();
436 }
437 }
438
439 private void loadTrace() {
440 initializeHistograms();
441 fParent.redraw();
442 }
443
444 /**
445 * Handles trace closed signal. Clears the view and data model and cancels requests.
446 * @param signal the trace closed signal
447 * @since 2.0
448 */
449 @TmfSignalHandler
450 public void traceClosed(TmfTraceClosedSignal signal) {
451
452 if (signal.getTrace() != fTrace) {
453 return;
454 }
455
456 // Kill any running request
457 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
458 fTimeRangeRequest.cancel();
459 }
460 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
461 fFullTraceRequest.cancel();
462 }
463
464 // Initialize the internal data
465 fTrace = null;
466 fTraceStartTime = 0L;
467 fTraceEndTime = 0L;
468 fWindowStartTime = 0L;
469 fWindowEndTime = 0L;
470 fWindowSpan = 0L;
471 fSelectionBeginTime = 0L;
472 fSelectionEndTime = 0L;
473
474 // Clear the UI widgets
475 fFullTraceHistogram.clear();
476 fTimeRangeHistogram.clear();
477 fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
478
479 fTimeSpanControl.setValue(Long.MIN_VALUE);
480 }
481
482 /**
483 * Handles trace range updated signal. Extends histogram according to the new time range. If a
484 * HistogramRequest is already ongoing, it will be cancelled and a new request with the new range
485 * will be issued.
486 *
487 * @param signal the trace range updated signal
488 * @since 2.0
489 */
490 @TmfSignalHandler
491 public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) {
492
493 if (signal.getTrace() != fTrace) {
494 return;
495 }
496
497 TmfTimeRange fullRange = signal.getRange();
498
499 fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
500 fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
501
502 fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
503 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
504
505 sendFullRangeRequest(fullRange);
506 }
507
508 /**
509 * Handles the trace updated signal. Used to update time limits (start and end time)
510 * @param signal the trace updated signal
511 * @since 2.0
512 */
513 @TmfSignalHandler
514 public void traceUpdated(TmfTraceUpdatedSignal signal) {
515 if (signal.getTrace() != fTrace) {
516 return;
517 }
518 TmfTimeRange fullRange = signal.getTrace().getTimeRange();
519 fTraceStartTime = fullRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
520 fTraceEndTime = fullRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
521
522 fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
523 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
524
525 fFullTraceHistogram.setTimeRange(fTimeRangeHistogram.getStartTime(), fWindowSpan);
526 fTimeRangeHistogram.setTimeRange(fTimeRangeHistogram.getStartTime(), fWindowSpan);
527
528 if ((fFullTraceRequest != null) && fFullTraceRequest.getRange().getEndTime().compareTo(signal.getRange().getEndTime()) < 0) {
529 sendFullRangeRequest(fullRange);
530 }
531 }
532
533 /**
534 * Handles the current time updated signal. Sets the current time in the time range
535 * histogram as well as the full histogram.
536 *
537 * @param signal the signal to process
538 */
539 @TmfSignalHandler
540 public void currentTimeUpdated(TmfTimeSynchSignal signal) {
541 // Because this can't happen :-)
542 assert (signal != null);
543
544 // Update the selected time range
545 ITmfTimestamp beginTime = signal.getBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
546 ITmfTimestamp endTime = signal.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
547 updateDisplayedSelectionTime(beginTime.getValue(), endTime.getValue());
548 }
549
550 /**
551 * Updates the current time range in the time range histogram and full range histogram.
552 * @param signal the signal to process
553 */
554 @TmfSignalHandler
555 public void timeRangeUpdated(TmfRangeSynchSignal signal) {
556 // Because this can't happen :-)
557 assert (signal != null);
558
559 if (fTrace != null) {
560 // Validate the time range
561 TmfTimeRange range = signal.getCurrentRange().getIntersection(fTrace.getTimeRange());
562 if (range == null) {
563 return;
564 }
565
566 updateDisplayedTimeRange(
567 range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(),
568 range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
569
570 // Send the event request to populate the small histogram
571 sendTimeRangeRequest(fWindowStartTime, fWindowEndTime);
572
573 fTimeSpanControl.setValue(fWindowSpan);
574 }
575 }
576
577 // ------------------------------------------------------------------------
578 // Helper functions
579 // ------------------------------------------------------------------------
580
581 private void initializeHistograms() {
582 TmfTimeRange fullRange = updateTraceTimeRange();
583 long selectionBeginTime = fTraceManager.getSelectionBeginTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
584 long selectionEndTime = fTraceManager.getSelectionEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
585 long startTime = fTraceManager.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
586 long duration = fTraceManager.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue() - startTime;
587
588 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
589 fTimeRangeRequest.cancel();
590 }
591 fTimeRangeHistogram.clear();
592 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
593 fTimeRangeHistogram.setTimeRange(startTime, duration);
594 fTimeRangeHistogram.setSelection(selectionBeginTime, selectionEndTime);
595
596 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
597 fFullTraceRequest.cancel();
598 }
599 fFullTraceHistogram.clear();
600 fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
601 fFullTraceHistogram.setTimeRange(startTime, duration);
602 fFullTraceHistogram.setSelection(selectionBeginTime, selectionEndTime);
603
604 fWindowStartTime = startTime;
605 fWindowSpan = duration;
606 fWindowEndTime = startTime + duration;
607
608 fSelectionBeginTime = selectionBeginTime;
609 fSelectionEndTime = selectionEndTime;
610 fCurrentEventTimeControl.setValue(fSelectionBeginTime);
611
612 fTimeSpanControl.setValue(duration);
613
614 if (!fullRange.equals(TmfTimeRange.NULL_RANGE)) {
615 sendTimeRangeRequest(startTime, startTime + duration);
616 sendFullRangeRequest(fullRange);
617 }
618 }
619
620 private void updateDisplayedSelectionTime(long beginTime, long endTime) {
621 fSelectionBeginTime = beginTime;
622 fSelectionEndTime = endTime;
623
624 fFullTraceHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime);
625 fTimeRangeHistogram.setSelection(fSelectionBeginTime, fSelectionEndTime);
626 fCurrentEventTimeControl.setValue(fSelectionBeginTime);
627 }
628
629 private void updateDisplayedTimeRange(long start, long end) {
630 fWindowStartTime = start;
631 fWindowEndTime = end;
632 fWindowSpan = fWindowEndTime - fWindowStartTime;
633 fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan);
634 }
635
636 private TmfTimeRange updateTraceTimeRange() {
637 fTraceStartTime = 0L;
638 fTraceEndTime = 0L;
639
640 TmfTimeRange timeRange = fTrace.getTimeRange();
641 if (!timeRange.equals(TmfTimeRange.NULL_RANGE)) {
642 fTraceStartTime = timeRange.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
643 fTraceEndTime = timeRange.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
644 }
645 return timeRange;
646 }
647
648 private void sendTimeRangeRequest(long startTime, long endTime) {
649 if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
650 fTimeRangeRequest.cancel();
651 }
652 TmfTimestamp startTS = new TmfTimestamp(startTime, ITmfTimestamp.NANOSECOND_SCALE);
653 TmfTimestamp endTS = new TmfTimestamp(endTime, ITmfTimestamp.NANOSECOND_SCALE);
654 TmfTimeRange timeRange = new TmfTimeRange(startTS, endTS);
655
656 fTimeRangeHistogram.clear();
657 fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
658 fTimeRangeHistogram.setTimeRange(startTime, endTime - startTime);
659
660 int cacheSize = fTrace.getCacheSize();
661 fTimeRangeRequest = new HistogramRequest(fTimeRangeHistogram.getDataModel(), timeRange, 0, TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.FOREGROUND, false);
662 fTrace.sendRequest(fTimeRangeRequest);
663 }
664
665 private void sendFullRangeRequest(TmfTimeRange fullRange) {
666 if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
667 fFullTraceRequest.cancel();
668 }
669 int cacheSize = fTrace.getCacheSize();
670 fFullTraceRequest = new HistogramRequest(fFullTraceHistogram.getDataModel(), fullRange, (int) fFullTraceHistogram.fDataModel.getNbEvents(),
671 TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.BACKGROUND, true);
672 fTrace.sendRequest(fFullTraceRequest);
673 }
674
675 private void contributeToActionBars() {
676 IActionBars bars = getViewSite().getActionBars();
677 bars.getToolBarManager().add(getShowLostEventsAction());
678 bars.getToolBarManager().add(new Separator());
679 }
680
681 }
This page took 0.047173 seconds and 5 git commands to generate.