1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.controlflow
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.Collections
;
18 import java
.util
.Comparator
;
19 import java
.util
.List
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
23 import org
.eclipse
.jface
.action
.Action
;
24 import org
.eclipse
.jface
.action
.IToolBarManager
;
25 import org
.eclipse
.jface
.action
.Separator
;
26 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
27 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
28 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
29 import org
.eclipse
.jface
.viewers
.Viewer
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
32 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.CtfKernelTrace
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTimestamp
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfStateSystemBuildCompleted
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.IStateSystemQuerier
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphSelectionListener
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphSelectionEvent
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
61 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
62 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
63 import org
.eclipse
.swt
.SWT
;
64 import org
.eclipse
.swt
.graphics
.Image
;
65 import org
.eclipse
.swt
.widgets
.Composite
;
66 import org
.eclipse
.swt
.widgets
.Display
;
67 import org
.eclipse
.swt
.widgets
.TreeColumn
;
68 import org
.eclipse
.ui
.IActionBars
;
71 * The Control Flow view main object
74 public class ControlFlowView
extends TmfView
{
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
83 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$
88 private static final long INITIAL_WINDOW_OFFSET
= (1L * 100 * 1000 * 1000); // .1sec
90 private static final String PROCESS_COLUMN
= Messages
.ControlFlowView_processColumn
;
91 private static final String TID_COLUMN
= Messages
.ControlFlowView_tidColumn
;
92 private static final String PTID_COLUMN
= Messages
.ControlFlowView_ptidColumn
;
93 private static final String BIRTH_TIME_COLUMN
= Messages
.ControlFlowView_birthTimeColumn
;
94 private static final String TRACE_COLUMN
= Messages
.ControlFlowView_traceColumn
;
96 private final String
[] COLUMN_NAMES
= new String
[] {
107 private enum State
{ IDLE
, BUSY
, PENDING
};
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
113 // The timegraph combo
114 private TimeGraphCombo fTimeGraphCombo
;
116 // The selected experiment
117 private TmfExperiment
<ITmfEvent
> fSelectedExperiment
;
119 // The timegraph entry list
120 private ArrayList
<ControlFlowEntry
> fEntryList
;
122 // The time graph entry list synchronization object
123 final private Object fEntryListSyncObj
= new Object();
126 private long fStartTime
;
129 private long fEndTime
;
132 private final int fDisplayWidth
;
135 private ZoomThread fZoomThread
;
137 // The next resource action
138 private Action fNextResourceAction
;
140 // The previous resource action
141 private Action fPreviousResourceAction
;
143 // A comparator class
144 private final ControlFlowEntryComparator fControlFlowEntryComparator
= new ControlFlowEntryComparator();
146 // The redraw state used to prevent unnecessary queuing of display runnables
147 private State fRedrawState
= State
.IDLE
;
149 // The redraw synchronization object
150 final private Object fSyncObj
= new Object();
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
156 private class TreeContentProvider
implements ITreeContentProvider
{
159 public void dispose() {
163 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
167 public Object
[] getElements(Object inputElement
) {
168 return (ITimeGraphEntry
[]) inputElement
;
172 public Object
[] getChildren(Object parentElement
) {
173 ITimeGraphEntry entry
= (ITimeGraphEntry
) parentElement
;
174 return entry
.getChildren();
178 public Object
getParent(Object element
) {
179 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
180 return entry
.getParent();
184 public boolean hasChildren(Object element
) {
185 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
186 return entry
.hasChildren();
191 private class TreeLabelProvider
implements ITableLabelProvider
{
194 public void addListener(ILabelProviderListener listener
) {
198 public void dispose() {
202 public boolean isLabelProperty(Object element
, String property
) {
207 public void removeListener(ILabelProviderListener listener
) {
211 public Image
getColumnImage(Object element
, int columnIndex
) {
216 public String
getColumnText(Object element
, int columnIndex
) {
217 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
218 if (columnIndex
== 0) {
219 return entry
.getName();
220 } else if (columnIndex
== 1) {
221 return Integer
.toString(entry
.getThreadId());
222 } else if (columnIndex
== 2) {
223 if (entry
.getParentThreadId() > 0) {
224 return Integer
.toString(entry
.getParentThreadId());
226 } else if (columnIndex
== 3) {
227 return Utils
.formatTime(entry
.getBirthTime(), TimeFormat
.ABSOLUTE
, Resolution
.NANOSEC
);
228 } else if (columnIndex
== 4) {
229 return entry
.getTrace().getName();
231 return ""; //$NON-NLS-1$
236 private static class ControlFlowEntryComparator
implements Comparator
<ITimeGraphEntry
> {
239 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
242 if ((o1
instanceof ControlFlowEntry
) && (o2
instanceof ControlFlowEntry
)) {
243 ControlFlowEntry entry1
= (ControlFlowEntry
) o1
;
244 ControlFlowEntry entry2
= (ControlFlowEntry
) o2
;
245 result
= entry1
.getTrace().getStartTime().compareTo(entry2
.getTrace().getStartTime());
247 result
= entry1
.getTrace().getName().compareTo(entry2
.getTrace().getName());
250 result
= entry1
.getThreadId() < entry2
.getThreadId() ?
-1 : entry1
.getThreadId() > entry2
.getThreadId() ?
1 : 0;
255 result
= o1
.getStartTime() < o2
.getStartTime() ?
-1 : o1
.getStartTime() > o2
.getStartTime() ?
1 : 0;
263 private class ZoomThread
extends Thread
{
264 private final long fZoomStartTime
;
265 private final long fZoomEndTime
;
266 private final long fResolution
;
267 private final IProgressMonitor fMonitor
;
269 public ZoomThread(long startTime
, long endTime
) {
270 super("ControlFlowView zoom"); //$NON-NLS-1$
271 fZoomStartTime
= startTime
;
272 fZoomEndTime
= endTime
;
273 fResolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
274 fMonitor
= new NullProgressMonitor();
279 ArrayList
<ControlFlowEntry
> entryList
= null;
280 synchronized (fEntryListSyncObj
) {
281 entryList
= fEntryList
;
283 if (entryList
== null) {
286 for (ControlFlowEntry entry
: entryList
) {
287 if (fMonitor
.isCanceled()) {
290 zoom(entry
, fMonitor
);
294 private void zoom(ControlFlowEntry entry
, IProgressMonitor monitor
) {
295 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
296 entry
.setZoomedEventList(null);
298 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, fResolution
, monitor
);
299 if (zoomedEventList
!= null) {
300 entry
.setZoomedEventList(zoomedEventList
);
304 for (ControlFlowEntry child
: entry
.getChildren()) {
305 if (fMonitor
.isCanceled()) {
308 zoom(child
, monitor
);
312 public void cancel() {
313 fMonitor
.setCanceled(true);
317 // ------------------------------------------------------------------------
319 // ------------------------------------------------------------------------
324 public ControlFlowView() {
326 fDisplayWidth
= Display
.getDefault().getBounds().width
;
329 // ------------------------------------------------------------------------
331 // ------------------------------------------------------------------------
334 * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
337 public void createPartControl(Composite parent
) {
338 fTimeGraphCombo
= new TimeGraphCombo(parent
, SWT
.NONE
);
340 fTimeGraphCombo
.setTreeContentProvider(new TreeContentProvider());
342 fTimeGraphCombo
.setTreeLabelProvider(new TreeLabelProvider());
344 fTimeGraphCombo
.setTimeGraphProvider(new ControlFlowPresentationProvider());
346 fTimeGraphCombo
.setTreeColumns(COLUMN_NAMES
);
348 fTimeGraphCombo
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
350 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
351 final long startTime
= event
.getStartTime();
352 final long endTime
= event
.getEndTime();
353 TmfTimeRange range
= new TmfTimeRange(new CtfTmfTimestamp(startTime
), new CtfTmfTimestamp(endTime
));
354 TmfTimestamp time
= new CtfTmfTimestamp(fTimeGraphCombo
.getTimeGraphViewer().getSelectedTime());
355 broadcast(new TmfRangeSynchSignal(ControlFlowView
.this, range
, time
));
356 if (fZoomThread
!= null) {
357 fZoomThread
.cancel();
359 startZoomThread(startTime
, endTime
);
363 fTimeGraphCombo
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
365 public void timeSelected(TimeGraphTimeEvent event
) {
366 long time
= event
.getTime();
367 broadcast(new TmfTimeSynchSignal(ControlFlowView
.this, new CtfTmfTimestamp(time
)));
371 fTimeGraphCombo
.addSelectionListener(new ITimeGraphSelectionListener() {
373 public void selectionChanged(TimeGraphSelectionEvent event
) {
374 //ITimeGraphEntry selection = event.getSelection();
378 fTimeGraphCombo
.getTimeGraphViewer().setTimeCalendarFormat(true);
380 final Thread thread
= new Thread("ControlFlowView build") { //$NON-NLS-1$
383 if (TmfExperiment
.getCurrentExperiment() != null) {
384 selectExperiment(TmfExperiment
.getCurrentExperiment());
390 // View Action Handling
392 contributeToActionBars();
396 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
399 public void setFocus() {
400 fTimeGraphCombo
.setFocus();
403 // ------------------------------------------------------------------------
405 // ------------------------------------------------------------------------
408 * Handler for the experiment selected signal
411 * The signal that's received
414 public void experimentSelected(final TmfExperimentSelectedSignal
<?
extends ITmfEvent
> signal
) {
415 if (signal
.getExperiment().equals(fSelectedExperiment
)) {
419 final Thread thread
= new Thread("ControlFlowView build") { //$NON-NLS-1$
422 selectExperiment(signal
.getExperiment());
429 * Handler for the synch signal
432 * The signal that's received
435 public void synchToTime(final TmfTimeSynchSignal signal
) {
436 if (signal
.getSource() == this || fSelectedExperiment
== null) {
439 final long time
= signal
.getCurrentTime().normalize(0, -9).getValue();
442 for (ITmfTrace
<?
> trace
: fSelectedExperiment
.getTraces()) {
446 if (trace
instanceof CtfKernelTrace
) {
447 CtfKernelTrace ctfKernelTrace
= (CtfKernelTrace
) trace
;
448 IStateSystemQuerier ssq
= ctfKernelTrace
.getStateSystem();
449 if (time
>= ssq
.getStartTime() && time
<= ssq
.getCurrentEndTime()) {
450 List
<Integer
> currentThreadQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*", Attributes
.CURRENT_THREAD
); //$NON-NLS-1$
451 for (int currentThreadQuark
: currentThreadQuarks
) {
453 ITmfStateInterval currentThreadInterval
= ssq
.querySingleState(time
, currentThreadQuark
);
454 int currentThread
= currentThreadInterval
.getStateValue().unboxInt();
455 if (currentThread
> 0) {
456 int statusQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThread
), Attributes
.STATUS
);
457 ITmfStateInterval statusInterval
= ssq
.querySingleState(time
, statusQuark
);
458 if (statusInterval
.getStartTime() == time
) {
459 thread
= currentThread
;
463 } catch (AttributeNotFoundException e
) {
465 } catch (TimeRangeException e
) {
467 } catch (StateValueTypeException e
) {
474 final int selectedThread
= thread
;
476 Display
.getDefault().asyncExec(new Runnable() {
479 if (fTimeGraphCombo
.isDisposed()) {
482 fTimeGraphCombo
.getTimeGraphViewer().setSelectedTime(time
, true);
483 startZoomThread(fTimeGraphCombo
.getTimeGraphViewer().getTime0(), fTimeGraphCombo
.getTimeGraphViewer().getTime1());
485 if (selectedThread
> 0) {
486 for (Object element
: fTimeGraphCombo
.getTimeGraphViewer().getExpandedElements()) {
487 if (element
instanceof ControlFlowEntry
) {
488 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
489 if (entry
.getThreadId() == selectedThread
) {
490 fTimeGraphCombo
.setSelection(entry
);
501 * Handler for the range sync signal
504 * The signal that's received
507 public void synchToRange(final TmfRangeSynchSignal signal
) {
508 if (signal
.getSource() == this || fSelectedExperiment
== null) {
511 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, -9).getValue();
512 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, -9).getValue();
513 final long time
= signal
.getCurrentTime().normalize(0, -9).getValue();
514 Display
.getDefault().asyncExec(new Runnable() {
517 if (fTimeGraphCombo
.isDisposed()) {
520 fTimeGraphCombo
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
521 fTimeGraphCombo
.getTimeGraphViewer().setSelectedTime(time
, false);
522 startZoomThread(startTime
, endTime
);
528 * Handler for the state system build completed signal
531 * The signal that's received
534 public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal
) {
535 final TmfExperiment
<?
> selectedExperiment
= fSelectedExperiment
;
536 if (selectedExperiment
== null) {
539 for (ITmfTrace
<?
> trace
: selectedExperiment
.getTraces()) {
540 if (trace
== signal
.getTrace() && trace
instanceof CtfKernelTrace
) {
541 final Thread thread
= new Thread("ControlFlowView build") { //$NON-NLS-1$
545 selectExperiment(selectedExperiment
);
553 // ------------------------------------------------------------------------
555 // ------------------------------------------------------------------------
557 @SuppressWarnings("unchecked")
558 private void selectExperiment(TmfExperiment
<?
> experiment
) {
559 fStartTime
= Long
.MAX_VALUE
;
560 fEndTime
= Long
.MIN_VALUE
;
561 fSelectedExperiment
= (TmfExperiment
<ITmfEvent
>) experiment
;
562 ArrayList
<ControlFlowEntry
> rootList
= new ArrayList
<ControlFlowEntry
>();
563 for (ITmfTrace
<?
> trace
: experiment
.getTraces()) {
564 if (trace
instanceof CtfKernelTrace
) {
565 ArrayList
<ControlFlowEntry
> entryList
= new ArrayList
<ControlFlowEntry
>();
566 CtfKernelTrace ctfKernelTrace
= (CtfKernelTrace
) trace
;
567 IStateSystemQuerier ssq
= ctfKernelTrace
.getStateSystem();
568 long start
= ssq
.getStartTime();
569 long end
= ssq
.getCurrentEndTime() + 1;
570 fStartTime
= Math
.min(fStartTime
, start
);
571 fEndTime
= Math
.max(fEndTime
, end
);
572 List
<Integer
> threadQuarks
= ssq
.getQuarks(Attributes
.THREADS
, "*"); //$NON-NLS-1$
573 for (int threadQuark
: threadQuarks
) {
574 String threadName
= ssq
.getAttributeName(threadQuark
);
577 threadId
= Integer
.parseInt(threadName
);
578 } catch (NumberFormatException e1
) {
581 if (threadId
== 0) { // ignore the swapper thread
584 int execNameQuark
= -1;
587 execNameQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.EXEC_NAME
);
588 } catch (AttributeNotFoundException e
) {
591 int ppidQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.PPID
);
592 List
<ITmfStateInterval
> execNameIntervals
= ssq
.queryHistoryRange(execNameQuark
, start
, end
- 1);
594 for (ITmfStateInterval execNameInterval
: execNameIntervals
) {
595 if (!execNameInterval
.getStateValue().isNull() && execNameInterval
.getStateValue().getType() == 1) {
596 String execName
= execNameInterval
.getStateValue().unboxStr();
597 long startTime
= execNameInterval
.getStartTime();
598 long endTime
= execNameInterval
.getEndTime() + 1;
599 if (birthTime
== -1) {
600 birthTime
= startTime
;
603 if (ppidQuark
!= -1) {
604 ITmfStateInterval ppidInterval
= ssq
.querySingleState(startTime
, ppidQuark
);
605 ppid
= ppidInterval
.getStateValue().unboxInt();
607 ControlFlowEntry entry
= new ControlFlowEntry(threadQuark
, ctfKernelTrace
, execName
, threadId
, ppid
, birthTime
, startTime
, endTime
);
608 entryList
.add(entry
);
609 entry
.addEvent(new TimeEvent(entry
, startTime
, endTime
- startTime
));
614 } catch (AttributeNotFoundException e
) {
616 } catch (TimeRangeException e
) {
618 } catch (StateValueTypeException e
) {
622 buildTree(entryList
, rootList
);
624 Collections
.sort(rootList
, fControlFlowEntryComparator
);
625 synchronized (fEntryListSyncObj
) {
626 fEntryList
= (ArrayList
<ControlFlowEntry
>) rootList
.clone();
628 refresh(INITIAL_WINDOW_OFFSET
);
630 for (ControlFlowEntry entry
: rootList
) {
631 buildStatusEvents(entry
);
635 private static void buildTree(ArrayList
<ControlFlowEntry
> entryList
,
636 ArrayList
<ControlFlowEntry
> rootList
) {
637 for (ControlFlowEntry entry
: entryList
) {
639 if (entry
.getParentThreadId() > 0) {
640 for (ControlFlowEntry parent
: entryList
) {
641 if (parent
.getThreadId() == entry
.getParentThreadId() &&
642 entry
.getStartTime() >= parent
.getStartTime() &&
643 entry
.getStartTime() <= parent
.getEndTime()) {
644 parent
.addChild(entry
);
656 private void buildStatusEvents(ControlFlowEntry entry
) {
657 IStateSystemQuerier ssq
= entry
.getTrace().getStateSystem();
658 long start
= ssq
.getStartTime();
659 long end
= ssq
.getCurrentEndTime() + 1;
660 long resolution
= Math
.max(1, (end
- start
) / fDisplayWidth
);
661 List
<ITimeEvent
> eventList
= getEventList(entry
, entry
.getStartTime(), entry
.getEndTime(), resolution
, new NullProgressMonitor());
662 entry
.setEventList(eventList
);
664 for (ITimeGraphEntry child
: entry
.getChildren()) {
665 buildStatusEvents((ControlFlowEntry
) child
);
669 private static List
<ITimeEvent
> getEventList(ControlFlowEntry entry
,
670 long startTime
, long endTime
, long resolution
,
671 IProgressMonitor monitor
) {
672 startTime
= Math
.max(startTime
, entry
.getStartTime());
673 endTime
= Math
.min(endTime
, entry
.getEndTime());
674 if (endTime
<= startTime
) {
677 IStateSystemQuerier ssq
= entry
.getTrace().getStateSystem();
678 List
<ITimeEvent
> eventList
= null;
680 int statusQuark
= ssq
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.STATUS
);
681 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, startTime
, endTime
- 1, resolution
, monitor
);
682 eventList
= new ArrayList
<ITimeEvent
>(statusIntervals
.size());
683 long lastEndTime
= -1;
684 for (ITmfStateInterval statusInterval
: statusIntervals
) {
685 if (monitor
.isCanceled()) {
688 long time
= statusInterval
.getStartTime();
689 long duration
= statusInterval
.getEndTime() - time
+ 1;
692 status
= statusInterval
.getStateValue().unboxInt();
693 } catch (StateValueTypeException e
) {
696 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
697 eventList
.add(new ControlFlowEvent(entry
, lastEndTime
, time
- lastEndTime
, 0));
699 eventList
.add(new ControlFlowEvent(entry
, time
, duration
, status
));
700 lastEndTime
= time
+ duration
;
702 } catch (AttributeNotFoundException e
) {
704 } catch (TimeRangeException e
) {
710 private void refresh(final long windowRange
) {
711 Display
.getDefault().asyncExec(new Runnable() {
714 if (fTimeGraphCombo
.isDisposed()) {
717 ITimeGraphEntry
[] entries
= null;
718 synchronized (fEntryListSyncObj
) {
719 entries
= fEntryList
.toArray(new ITimeGraphEntry
[0]);
721 Arrays
.sort(entries
, fControlFlowEntryComparator
);
722 fTimeGraphCombo
.setInput(entries
);
723 fTimeGraphCombo
.getTimeGraphViewer().setTimeBounds(fStartTime
, fEndTime
);
725 long endTime
= fStartTime
+ windowRange
;
727 if (fEndTime
< endTime
) {
730 fTimeGraphCombo
.getTimeGraphViewer().setStartFinishTime(fStartTime
, endTime
);
731 for (TreeColumn column
: fTimeGraphCombo
.getTreeViewer().getTree().getColumns()) {
735 startZoomThread(fStartTime
, endTime
);
740 private void redraw() {
741 synchronized (fSyncObj
) {
742 if (fRedrawState
== State
.IDLE
) {
743 fRedrawState
= State
.BUSY
;
745 fRedrawState
= State
.PENDING
;
749 Display
.getDefault().asyncExec(new Runnable() {
752 if (fTimeGraphCombo
.isDisposed()) {
755 fTimeGraphCombo
.redraw();
756 fTimeGraphCombo
.update();
757 synchronized (fSyncObj
) {
758 if (fRedrawState
== State
.PENDING
) {
759 fRedrawState
= State
.IDLE
;
762 fRedrawState
= State
.IDLE
;
769 private void startZoomThread(long startTime
, long endTime
) {
770 if (fZoomThread
!= null) {
771 fZoomThread
.cancel();
773 fZoomThread
= new ZoomThread(startTime
, endTime
);
777 private void makeActions() {
778 fPreviousResourceAction
= fTimeGraphCombo
.getTimeGraphViewer().getPreviousItemAction();
779 fPreviousResourceAction
.setText(Messages
.ControlFlowView_previousProcessActionNameText
);
780 fPreviousResourceAction
.setToolTipText(Messages
.ControlFlowView_previousProcessActionToolTipText
);
781 fNextResourceAction
= fTimeGraphCombo
.getTimeGraphViewer().getNextItemAction();
782 fNextResourceAction
.setText(Messages
.ControlFlowView_nextProcessActionNameText
);
783 fNextResourceAction
.setToolTipText(Messages
.ControlFlowView_nextProcessActionToolTipText
);
786 private void contributeToActionBars() {
787 IActionBars bars
= getViewSite().getActionBars();
788 fillLocalToolBar(bars
.getToolBarManager());
791 private void fillLocalToolBar(IToolBarManager manager
) {
792 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getShowLegendAction());
793 manager
.add(new Separator());
794 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getResetScaleAction());
795 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getPreviousEventAction());
796 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getNextEventAction());
797 manager
.add(fPreviousResourceAction
);
798 manager
.add(fNextResourceAction
);
799 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getZoomInAction());
800 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getZoomOutAction());
801 manager
.add(new Separator());