1 /*******************************************************************************
2 * Copyright (c) 2012, 2016 Ericsson, École Polytechnique de Montréal and others.
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 * Geneviève Bastien - Move code to provide base classes for time graph view
12 * Christian Mansky - Add check active / uncheck inactive buttons
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.ui
.views
.controlflow
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Comparator
;
19 import java
.util
.HashMap
;
20 import java
.util
.List
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.jdt
.annotation
.NonNull
;
25 import org
.eclipse
.jdt
.annotation
.Nullable
;
26 import org
.eclipse
.jface
.action
.IAction
;
27 import org
.eclipse
.jface
.action
.IMenuManager
;
28 import org
.eclipse
.jface
.action
.IToolBarManager
;
29 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
30 import org
.eclipse
.jface
.viewers
.ISelection
;
31 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.KernelAnalysisModule
;
34 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.Attributes
;
35 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.Activator
;
36 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.Messages
;
37 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.actions
.FollowThreadAction
;
38 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.controlflow
.ControlFlowColumnComparators
;
39 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
40 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
41 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
42 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
43 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
44 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
45 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
46 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
47 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
48 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
49 import org
.eclipse
.tracecompass
.tmf
.core
.util
.Pair
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractStateSystemTimeGraphView
;
51 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
52 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
53 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
54 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
55 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
56 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
57 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeLinkEvent
;
58 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
59 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
62 import com
.google
.common
.collect
.ImmutableList
;
65 * The Control Flow view main object
68 public class ControlFlowView
extends AbstractStateSystemTimeGraphView
{
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
76 public static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.views.controlflow"; //$NON-NLS-1$
78 private static final String PROCESS_COLUMN
= Messages
.ControlFlowView_processColumn
;
79 private static final String TID_COLUMN
= Messages
.ControlFlowView_tidColumn
;
80 private static final String PTID_COLUMN
= Messages
.ControlFlowView_ptidColumn
;
81 private static final String BIRTH_TIME_COLUMN
= Messages
.ControlFlowView_birthTimeColumn
;
82 private static final String TRACE_COLUMN
= Messages
.ControlFlowView_traceColumn
;
84 private static final String
[] COLUMN_NAMES
= new String
[] {
92 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
97 // Timeout between updates in the build thread in ms
98 private static final long BUILD_UPDATE_TIMEOUT
= 500;
100 private static final Comparator
<ITimeGraphEntry
>[] COLUMN_COMPARATORS
;
102 private static final int INITIAL_SORT_COLUMN_INDEX
= 3;
105 ImmutableList
.Builder
<Comparator
<ITimeGraphEntry
>> builder
= ImmutableList
.builder();
106 builder
.add(ControlFlowColumnComparators
.PROCESS_NAME_COLUMN_COMPARATOR
)
107 .add(ControlFlowColumnComparators
.TID_COLUMN_COMPARATOR
)
108 .add(ControlFlowColumnComparators
.PTID_COLUMN_COMPARATOR
)
109 .add(ControlFlowColumnComparators
.BIRTH_TIME_COLUMN_COMPARATOR
)
110 .add(ControlFlowColumnComparators
.TRACE_COLUMN_COMPARATOR
);
111 List
<Comparator
<ITimeGraphEntry
>> l
= builder
.build();
112 COLUMN_COMPARATORS
= l
.toArray(new Comparator
[l
.size()]);
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
122 public ControlFlowView() {
123 super(ID
, new ControlFlowPresentationProvider());
124 setTreeColumns(COLUMN_NAMES
, COLUMN_COMPARATORS
, INITIAL_SORT_COLUMN_INDEX
);
125 setTreeLabelProvider(new ControlFlowTreeLabelProvider());
126 setFilterColumns(FILTER_COLUMN_NAMES
);
127 setFilterLabelProvider(new ControlFlowFilterLabelProvider());
128 setEntryComparator(ControlFlowColumnComparators
.BIRTH_TIME_COLUMN_COMPARATOR
);
132 public void createPartControl(Composite parent
) {
133 super.createPartControl(parent
);
134 // add "Check active" Button to TimeGraphFilterDialog
135 super.getTimeGraphCombo().addTimeGraphFilterCheckActiveButton(
136 new ControlFlowCheckActiveProvider(Messages
.ControlFlowView_checkActiveLabel
, Messages
.ControlFlowView_checkActiveToolTip
));
137 // add "Uncheck inactive" Button to TimeGraphFilterDialog
138 super.getTimeGraphCombo().addTimeGraphFilterUncheckInactiveButton(
139 new ControlFlowCheckActiveProvider(Messages
.ControlFlowView_uncheckInactiveLabel
, Messages
.ControlFlowView_uncheckInactiveToolTip
));
146 protected void fillTimeGraphEntryContextMenu(@NonNull IMenuManager menuManager
) {
147 ISelection selection
= getSite().getSelectionProvider().getSelection();
148 if (selection
instanceof StructuredSelection
) {
149 StructuredSelection sSel
= (StructuredSelection
) selection
;
150 if (sSel
.getFirstElement() instanceof ControlFlowEntry
) {
151 ControlFlowEntry entry
= (ControlFlowEntry
) sSel
.getFirstElement();
152 menuManager
.add(new FollowThreadAction(ControlFlowView
.this, entry
.getName(), entry
.getThreadId(), entry
.getTrace()));
158 protected void fillLocalToolBar(IToolBarManager manager
) {
159 super.fillLocalToolBar(manager
);
160 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
161 IDialogSettings section
= settings
.getSection(getClass().getName());
162 if (section
== null) {
163 section
= settings
.addNewSection(getClass().getName());
166 IAction hideArrowsAction
= getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section
);
167 manager
.add(hideArrowsAction
);
169 IAction followArrowBwdAction
= getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction();
170 followArrowBwdAction
.setText(Messages
.ControlFlowView_followCPUBwdText
);
171 followArrowBwdAction
.setToolTipText(Messages
.ControlFlowView_followCPUBwdText
);
172 manager
.add(followArrowBwdAction
);
174 IAction followArrowFwdAction
= getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction();
175 followArrowFwdAction
.setText(Messages
.ControlFlowView_followCPUFwdText
);
176 followArrowFwdAction
.setToolTipText(Messages
.ControlFlowView_followCPUFwdText
);
177 manager
.add(followArrowFwdAction
);
181 protected String
getNextText() {
182 return Messages
.ControlFlowView_nextProcessActionNameText
;
186 protected String
getNextTooltip() {
187 return Messages
.ControlFlowView_nextProcessActionToolTipText
;
191 protected String
getPrevText() {
192 return Messages
.ControlFlowView_previousProcessActionNameText
;
196 protected String
getPrevTooltip() {
197 return Messages
.ControlFlowView_previousProcessActionToolTipText
;
204 protected static class ControlFlowTreeLabelProvider
extends TreeLabelProvider
{
207 public String
getColumnText(Object element
, int columnIndex
) {
208 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
210 if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_processColumn
)) {
211 return entry
.getName();
212 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_tidColumn
)) {
213 return Integer
.toString(entry
.getThreadId());
214 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_ptidColumn
)) {
215 if (entry
.getParentThreadId() > 0) {
216 return Integer
.toString(entry
.getParentThreadId());
218 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_birthTimeColumn
)) {
219 return Utils
.formatTime(entry
.getStartTime(), TimeFormat
.CALENDAR
, Resolution
.NANOSEC
);
220 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_traceColumn
)) {
221 return entry
.getTrace().getName();
223 return ""; //$NON-NLS-1$
228 private static class ControlFlowFilterLabelProvider
extends TreeLabelProvider
{
231 public String
getColumnText(Object element
, int columnIndex
) {
232 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
234 if (columnIndex
== 0) {
235 return entry
.getName();
236 } else if (columnIndex
== 1) {
237 return Integer
.toString(entry
.getThreadId());
239 return ""; //$NON-NLS-1$
244 // ------------------------------------------------------------------------
246 // ------------------------------------------------------------------------
249 protected void buildEntryList(final ITmfTrace trace
, final ITmfTrace parentTrace
, final IProgressMonitor monitor
) {
250 final ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
255 final List
<ControlFlowEntry
> entryList
= new ArrayList
<>();
256 /** Map of view entries, key is a pair [threadId, cpuId] */
257 final Map
<Pair
<Integer
, Integer
>, ControlFlowEntry
> entryMap
= new HashMap
<>();
259 long start
= ssq
.getStartTime();
260 setStartTime(Math
.min(getStartTime(), start
));
262 boolean complete
= false;
264 if (monitor
.isCanceled()) {
267 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
268 if (ssq
.isCancelled()) {
271 long end
= ssq
.getCurrentEndTime();
272 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
275 final long resolution
= Math
.max(1, (end
- ssq
.getStartTime()) / getDisplayWidth());
276 setEndTime(Math
.max(getEndTime(), end
+ 1));
277 final List
<Integer
> threadQuarks
= ssq
.getQuarks(Attributes
.THREADS
, "*"); //$NON-NLS-1$
278 final long qStart
= start
;
279 final long qEnd
= end
;
280 queryFullStates(ssq
, qStart
, qEnd
, resolution
, monitor
, new IQueryHandler() {
282 public void handle(List
<List
<ITmfStateInterval
>> fullStates
, List
<ITmfStateInterval
> prevFullState
) {
283 for (int threadQuark
: threadQuarks
) {
284 String threadAttributeName
= ssq
.getAttributeName(threadQuark
);
286 Pair
<Integer
, Integer
> entryKey
= Attributes
.parseThreadAttributeName(threadAttributeName
);
287 int threadId
= entryKey
.getFirst();
289 if (threadId
< 0) { // ignore the 'unknown' (-1) thread
296 execNameQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.EXEC_NAME
);
297 ppidQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.PPID
);
298 } catch (AttributeNotFoundException e
) {
299 /* No information on this thread (yet?), skip it for now */
302 ITmfStateInterval lastExecNameInterval
= prevFullState
== null || execNameQuark
>= prevFullState
.size() ?
null : prevFullState
.get(execNameQuark
);
303 long lastExecNameStartTime
= lastExecNameInterval
== null ?
-1 : lastExecNameInterval
.getStartTime();
304 long lastExecNameEndTime
= lastExecNameInterval
== null ?
-1 : lastExecNameInterval
.getEndTime() + 1;
305 long lastPpidStartTime
= prevFullState
== null || ppidQuark
>= prevFullState
.size() ?
-1 : prevFullState
.get(ppidQuark
).getStartTime();
306 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
307 if (monitor
.isCanceled()) {
310 if (execNameQuark
>= fullState
.size() || ppidQuark
>= fullState
.size()) {
311 /* No information on this thread (yet?), skip it for now */
314 ITmfStateInterval execNameInterval
= fullState
.get(execNameQuark
);
315 ITmfStateInterval ppidInterval
= fullState
.get(ppidQuark
);
316 long startTime
= execNameInterval
.getStartTime();
317 long endTime
= execNameInterval
.getEndTime() + 1;
318 if (startTime
== lastExecNameStartTime
&& ppidInterval
.getStartTime() == lastPpidStartTime
) {
321 boolean isNull
= execNameInterval
.getStateValue().isNull();
322 if (isNull
&& lastExecNameEndTime
< startTime
&& lastExecNameEndTime
!= -1) {
324 * There was a non-null interval in between the
325 * full states, try to use it.
328 execNameInterval
= ssq
.querySingleState(startTime
- 1, execNameQuark
);
329 ppidInterval
= ssq
.querySingleState(startTime
- 1, ppidQuark
);
330 startTime
= execNameInterval
.getStartTime();
331 endTime
= execNameInterval
.getEndTime() + 1;
332 } catch (AttributeNotFoundException e
) {
333 Activator
.getDefault().logError(e
.getMessage());
334 } catch (StateSystemDisposedException e
) {
338 if (!execNameInterval
.getStateValue().isNull() &&
339 execNameInterval
.getStateValue().getType() == ITmfStateValue
.Type
.STRING
) {
340 String execName
= execNameInterval
.getStateValue().unboxStr();
341 int ppid
= ppidInterval
.getStateValue().unboxInt();
342 ControlFlowEntry entry
= entryMap
.get(entryKey
);
344 entry
= new ControlFlowEntry(threadQuark
, trace
, execName
, threadId
, ppid
, startTime
, endTime
);
345 entryList
.add(entry
);
346 entryMap
.put(entryKey
, entry
);
349 * Update the name of the entry to the
350 * latest execName and the parent thread id
351 * to the latest ppid.
353 entry
.setName(execName
);
354 entry
.setParentThreadId(ppid
);
355 entry
.updateEndTime(endTime
);
359 entryMap
.remove(entryKey
);
361 lastExecNameStartTime
= startTime
;
362 lastExecNameEndTime
= endTime
;
363 lastPpidStartTime
= ppidInterval
.getStartTime();
366 updateTree(entryList
, parentTrace
, ssq
);
368 for (final TimeGraphEntry entry
: getEntryList(ssq
)) {
369 if (monitor
.isCanceled()) {
372 buildStatusEvents(trace
, parentTrace
, ssq
, fullStates
, prevFullState
, (ControlFlowEntry
) entry
, monitor
, qStart
, qEnd
);
377 if (parentTrace
.equals(getTrace())) {
385 private void updateTree(List
<ControlFlowEntry
> entryList
, ITmfTrace parentTrace
, ITmfStateSystem ss
) {
386 List
<TimeGraphEntry
> rootListToAdd
= new ArrayList
<>();
387 List
<TimeGraphEntry
> rootListToRemove
= new ArrayList
<>();
388 List
<TimeGraphEntry
> rootList
= getEntryList(ss
);
390 for (ControlFlowEntry entry
: entryList
) {
391 boolean root
= (entry
.getParent() == null);
392 if (root
&& entry
.getParentThreadId() > 0) {
393 for (ControlFlowEntry parent
: entryList
) {
395 * Associate the parent entry only if their time overlap. A
396 * child entry may start before its parent, for example at
397 * the beginning of the trace if a parent has not yet
398 * appeared in the state system. We just want to make sure
399 * that the entry didn't start after the parent ended or
400 * ended before the parent started.
402 if (parent
.getThreadId() == entry
.getParentThreadId() &&
403 !(entry
.getStartTime() > parent
.getEndTime() ||
404 entry
.getEndTime() < parent
.getStartTime())) {
405 parent
.addChild(entry
);
407 if (rootList
!= null && rootList
.contains(entry
)) {
408 rootListToRemove
.add(entry
);
414 if (root
&& (rootList
== null || !rootList
.contains(entry
))) {
415 rootListToAdd
.add(entry
);
419 addToEntryList(parentTrace
, ss
, rootListToAdd
);
420 removeFromEntryList(parentTrace
, ss
, rootListToRemove
);
423 private void buildStatusEvents(ITmfTrace trace
, ITmfTrace parentTrace
, ITmfStateSystem ss
, @NonNull List
<List
<ITmfStateInterval
>> fullStates
,
424 @Nullable List
<ITmfStateInterval
> prevFullState
, ControlFlowEntry entry
, @NonNull IProgressMonitor monitor
, long start
, long end
) {
425 if (start
< entry
.getEndTime() && end
> entry
.getStartTime()) {
426 List
<ITimeEvent
> eventList
= getEventList(entry
, ss
, fullStates
, prevFullState
, monitor
);
427 if (eventList
== null) {
430 for (ITimeEvent event
: eventList
) {
431 entry
.addEvent(event
);
433 if (parentTrace
.equals(getTrace())) {
437 for (ITimeGraphEntry child
: entry
.getChildren()) {
438 if (monitor
.isCanceled()) {
441 buildStatusEvents(trace
, parentTrace
, ss
, fullStates
, prevFullState
, (ControlFlowEntry
) child
, monitor
, start
, end
);
446 protected @Nullable List
<ITimeEvent
> getEventList(@NonNull TimeGraphEntry tgentry
, ITmfStateSystem ss
,
447 @NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
, @NonNull IProgressMonitor monitor
) {
448 List
<ITimeEvent
> eventList
= null;
449 if (!(tgentry
instanceof ControlFlowEntry
)) {
452 ControlFlowEntry entry
= (ControlFlowEntry
) tgentry
;
454 int threadQuark
= entry
.getThreadQuark();
455 int statusQuark
= ss
.getQuarkRelative(threadQuark
, Attributes
.STATUS
);
456 eventList
= new ArrayList
<>(fullStates
.size());
457 ITmfStateInterval lastInterval
= prevFullState
== null || statusQuark
>= prevFullState
.size() ?
null : prevFullState
.get(statusQuark
);
458 long lastStartTime
= lastInterval
== null ?
-1 : lastInterval
.getStartTime();
459 long lastEndTime
= lastInterval
== null ?
-1 : lastInterval
.getEndTime() + 1;
460 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
461 if (monitor
.isCanceled()) {
464 if (statusQuark
>= fullState
.size()) {
465 /* No information on this thread (yet?), skip it for now */
468 ITmfStateInterval statusInterval
= fullState
.get(statusQuark
);
469 long time
= statusInterval
.getStartTime();
470 if (time
== lastStartTime
) {
473 long duration
= statusInterval
.getEndTime() - time
+ 1;
476 status
= statusInterval
.getStateValue().unboxInt();
477 } catch (StateValueTypeException e
) {
478 Activator
.getDefault().logError(e
.getMessage());
480 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
481 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
483 if (!statusInterval
.getStateValue().isNull()) {
484 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
486 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
488 lastStartTime
= time
;
489 lastEndTime
= time
+ duration
;
491 } catch (AttributeNotFoundException
| TimeRangeException e
) {
492 Activator
.getDefault().logError(e
.getMessage());
498 * Returns a value corresponding to the selected entry.
500 * Used in conjunction with synchingToTime to change the selected entry. If
501 * one of these methods is overridden in child class, then both should be.
504 * The currently selected time
505 * @return a value identifying the entry
507 private int getSelectionValue(long time
) {
509 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
513 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
517 if (time
>= ssq
.getStartTime() && time
<= ssq
.getCurrentEndTime()) {
518 List
<Integer
> currentThreadQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*", Attributes
.CURRENT_THREAD
); //$NON-NLS-1$
519 for (int currentThreadQuark
: currentThreadQuarks
) {
521 ITmfStateInterval currentThreadInterval
= ssq
.querySingleState(time
, currentThreadQuark
);
522 int currentThread
= currentThreadInterval
.getStateValue().unboxInt();
523 if (currentThread
> 0) {
524 int statusQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThread
), Attributes
.STATUS
);
525 ITmfStateInterval statusInterval
= ssq
.querySingleState(time
, statusQuark
);
526 if (statusInterval
.getStartTime() == time
) {
527 thread
= currentThread
;
531 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
532 Activator
.getDefault().logError(e
.getMessage());
533 } catch (StateSystemDisposedException e
) {
543 protected void synchingToTime(long time
) {
544 int selected
= getSelectionValue(time
);
546 for (Object element
: getTimeGraphViewer().getExpandedElements()) {
547 if (element
instanceof ControlFlowEntry
) {
548 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
549 if (entry
.getThreadId() == selected
) {
550 getTimeGraphCombo().setSelection(entry
);
559 protected @NonNull List
<ILinkEvent
> getLinkList(ITmfStateSystem ss
,
560 @NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
, @NonNull IProgressMonitor monitor
) {
561 List
<ILinkEvent
> list
= new ArrayList
<>();
562 List
<TimeGraphEntry
> entryList
= getEntryList(ss
);
563 if (entryList
== null) {
566 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
567 List
<Integer
> currentThreadQuarks
= ss
.getQuarks(Attributes
.CPUS
, "*", Attributes
.CURRENT_THREAD
); //$NON-NLS-1$
568 for (int currentThreadQuark
: currentThreadQuarks
) {
569 if (currentThreadQuark
>= fullStates
.get(0).size()) {
570 /* No information on this cpu (yet?), skip it for now */
573 List
<ITmfStateInterval
> currentThreadIntervals
= new ArrayList
<>(fullStates
.size() + 2);
576 * Add the previous interval if it is the first query
577 * iteration and the first interval has currentThread=0. Add
578 * the following interval if the last interval has
579 * currentThread=0. These are diagonal arrows crossing the
580 * query iteration range.
582 if (prevFullState
== null) {
583 ITmfStateInterval currentThreadInterval
= fullStates
.get(0).get(currentThreadQuark
);
584 if (currentThreadInterval
.getStateValue().unboxInt() == 0) {
585 long start
= Math
.max(currentThreadInterval
.getStartTime() - 1, ss
.getStartTime());
586 currentThreadIntervals
.add(ss
.querySingleState(start
, currentThreadQuark
));
589 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
590 currentThreadIntervals
.add(fullState
.get(currentThreadQuark
));
592 ITmfStateInterval currentThreadInterval
= fullStates
.get(fullStates
.size() - 1).get(currentThreadQuark
);
593 if (currentThreadInterval
.getStateValue().unboxInt() == 0) {
594 long end
= Math
.min(currentThreadInterval
.getEndTime() + 1, ss
.getCurrentEndTime());
595 currentThreadIntervals
.add(ss
.querySingleState(end
, currentThreadQuark
));
597 } catch (AttributeNotFoundException e
) {
598 Activator
.getDefault().logError(e
.getMessage());
600 } catch (StateSystemDisposedException e
) {
607 for (ITmfStateInterval currentThreadInterval
: currentThreadIntervals
) {
608 if (monitor
.isCanceled()) {
611 if (currentThreadInterval
.getEndTime() + 1 == lastEnd
) {
614 long time
= currentThreadInterval
.getStartTime();
615 if (time
!= lastEnd
) {
616 // don't create links where there are gaps in intervals due to the resolution
620 int thread
= currentThreadInterval
.getStateValue().unboxInt();
621 if (thread
> 0 && prevThread
> 0) {
622 ITimeGraphEntry prevEntry
= findEntry(entryList
, trace
, prevThread
);
623 ITimeGraphEntry nextEntry
= findEntry(entryList
, trace
, thread
);
624 list
.add(new TimeLinkEvent(prevEntry
, nextEntry
, prevEnd
, time
- prevEnd
, 0));
626 lastEnd
= currentThreadInterval
.getEndTime() + 1;
637 private ControlFlowEntry
findEntry(List
<?
extends ITimeGraphEntry
> entryList
, ITmfTrace trace
, int threadId
) {
638 for (ITimeGraphEntry entry
: entryList
) {
639 if (entry
instanceof ControlFlowEntry
) {
640 ControlFlowEntry controlFlowEntry
= (ControlFlowEntry
) entry
;
641 if (controlFlowEntry
.getThreadId() == threadId
&& controlFlowEntry
.getTrace() == trace
) {
642 return controlFlowEntry
;
643 } else if (entry
.hasChildren()) {
644 controlFlowEntry
= findEntry(entry
.getChildren(), trace
, threadId
);
645 if (controlFlowEntry
!= null) {
646 return controlFlowEntry
;