1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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
.IToolBarManager
;
28 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.Attributes
;
31 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.KernelAnalysisModule
;
32 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.Activator
;
33 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.Messages
;
34 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.controlflow
.ControlFlowColumnComparators
;
35 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
36 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
37 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
38 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
39 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
40 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
41 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
42 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
43 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
44 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
45 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractStateSystemTimeGraphView
;
46 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
47 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
48 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
49 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
51 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
52 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeLinkEvent
;
53 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
54 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
55 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
57 import com
.google
.common
.collect
.ImmutableList
;
60 * The Control Flow view main object
63 public class ControlFlowView
extends AbstractStateSystemTimeGraphView
{
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
71 public static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.views.controlflow"; //$NON-NLS-1$
73 private static final String PROCESS_COLUMN
= Messages
.ControlFlowView_processColumn
;
74 private static final String TID_COLUMN
= Messages
.ControlFlowView_tidColumn
;
75 private static final String PTID_COLUMN
= Messages
.ControlFlowView_ptidColumn
;
76 private static final String BIRTH_TIME_COLUMN
= Messages
.ControlFlowView_birthTimeColumn
;
77 private static final String TRACE_COLUMN
= Messages
.ControlFlowView_traceColumn
;
79 private static final String
[] COLUMN_NAMES
= new String
[] {
87 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
92 // Timeout between updates in the build thread in ms
93 private static final long BUILD_UPDATE_TIMEOUT
= 500;
95 private static final Comparator
<ITimeGraphEntry
>[] COLUMN_COMPARATORS
;
97 private static final int INITIAL_SORT_COLUMN_INDEX
= 3;
100 ImmutableList
.Builder
<Comparator
<ITimeGraphEntry
>> builder
= ImmutableList
.builder();
101 builder
.add(ControlFlowColumnComparators
.PROCESS_NAME_COLUMN_COMPARATOR
)
102 .add(ControlFlowColumnComparators
.TID_COLUMN_COMPARATOR
)
103 .add(ControlFlowColumnComparators
.PTID_COLUMN_COMPARATOR
)
104 .add(ControlFlowColumnComparators
.BIRTH_TIME_COLUMN_COMPARATOR
)
105 .add(ControlFlowColumnComparators
.TRACE_COLUMN_COMPARATOR
);
106 List
<Comparator
<ITimeGraphEntry
>> l
= builder
.build();
107 COLUMN_COMPARATORS
= l
.toArray(new Comparator
[l
.size()]);
110 // ------------------------------------------------------------------------
112 // ------------------------------------------------------------------------
117 public ControlFlowView() {
118 super(ID
, new ControlFlowPresentationProvider());
119 setTreeColumns(COLUMN_NAMES
, COLUMN_COMPARATORS
, INITIAL_SORT_COLUMN_INDEX
);
120 setTreeLabelProvider(new ControlFlowTreeLabelProvider());
121 setFilterColumns(FILTER_COLUMN_NAMES
);
122 setFilterLabelProvider(new ControlFlowFilterLabelProvider());
123 setEntryComparator(ControlFlowColumnComparators
.BIRTH_TIME_COLUMN_COMPARATOR
);
127 public void createPartControl(Composite parent
) {
128 super.createPartControl(parent
);
129 // add "Check active" Button to TimeGraphFilterDialog
130 super.getTimeGraphCombo().addTimeGraphFilterCheckActiveButton(
131 new ControlFlowCheckActiveProvider(Messages
.ControlFlowView_checkActiveLabel
, Messages
.ControlFlowView_checkActiveToolTip
));
132 // add "Uncheck inactive" Button to TimeGraphFilterDialog
133 super.getTimeGraphCombo().addTimeGraphFilterUncheckInactiveButton(
134 new ControlFlowCheckActiveProvider(Messages
.ControlFlowView_uncheckInactiveLabel
, Messages
.ControlFlowView_uncheckInactiveToolTip
));
138 protected void fillLocalToolBar(IToolBarManager manager
) {
139 super.fillLocalToolBar(manager
);
140 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
141 IDialogSettings section
= settings
.getSection(getClass().getName());
142 if (section
== null) {
143 section
= settings
.addNewSection(getClass().getName());
146 IAction hideArrowsAction
= getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section
);
147 manager
.add(hideArrowsAction
);
149 IAction followArrowBwdAction
= getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction();
150 followArrowBwdAction
.setText(Messages
.ControlFlowView_followCPUBwdText
);
151 followArrowBwdAction
.setToolTipText(Messages
.ControlFlowView_followCPUBwdText
);
152 manager
.add(followArrowBwdAction
);
154 IAction followArrowFwdAction
= getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction();
155 followArrowFwdAction
.setText(Messages
.ControlFlowView_followCPUFwdText
);
156 followArrowFwdAction
.setToolTipText(Messages
.ControlFlowView_followCPUFwdText
);
157 manager
.add(followArrowFwdAction
);
161 protected String
getNextText() {
162 return Messages
.ControlFlowView_nextProcessActionNameText
;
166 protected String
getNextTooltip() {
167 return Messages
.ControlFlowView_nextProcessActionToolTipText
;
171 protected String
getPrevText() {
172 return Messages
.ControlFlowView_previousProcessActionNameText
;
176 protected String
getPrevTooltip() {
177 return Messages
.ControlFlowView_previousProcessActionToolTipText
;
184 protected static class ControlFlowTreeLabelProvider
extends TreeLabelProvider
{
187 public String
getColumnText(Object element
, int columnIndex
) {
188 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
190 if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_processColumn
)) {
191 return entry
.getName();
192 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_tidColumn
)) {
193 return Integer
.toString(entry
.getThreadId());
194 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_ptidColumn
)) {
195 if (entry
.getParentThreadId() > 0) {
196 return Integer
.toString(entry
.getParentThreadId());
198 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_birthTimeColumn
)) {
199 return Utils
.formatTime(entry
.getStartTime(), TimeFormat
.CALENDAR
, Resolution
.NANOSEC
);
200 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_traceColumn
)) {
201 return entry
.getTrace().getName();
203 return ""; //$NON-NLS-1$
208 private static class ControlFlowFilterLabelProvider
extends TreeLabelProvider
{
211 public String
getColumnText(Object element
, int columnIndex
) {
212 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
214 if (columnIndex
== 0) {
215 return entry
.getName();
216 } else if (columnIndex
== 1) {
217 return Integer
.toString(entry
.getThreadId());
219 return ""; //$NON-NLS-1$
224 // ------------------------------------------------------------------------
226 // ------------------------------------------------------------------------
229 protected void buildEventList(final ITmfTrace trace
, final ITmfTrace parentTrace
, final IProgressMonitor monitor
) {
230 final ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
235 final List
<ControlFlowEntry
> entryList
= new ArrayList
<>();
236 final Map
<Integer
, ControlFlowEntry
> entryMap
= new HashMap
<>();
238 long start
= ssq
.getStartTime();
239 setStartTime(Math
.min(getStartTime(), start
));
241 boolean complete
= false;
243 if (monitor
.isCanceled()) {
246 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
247 if (ssq
.isCancelled()) {
250 long end
= ssq
.getCurrentEndTime();
251 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
254 final long resolution
= Math
.max(1, (end
- ssq
.getStartTime()) / getDisplayWidth());
255 setEndTime(Math
.max(getEndTime(), end
+ 1));
256 final List
<Integer
> threadQuarks
= ssq
.getQuarks(Attributes
.THREADS
, "*"); //$NON-NLS-1$
257 final long qStart
= start
;
258 final long qEnd
= end
;
259 queryFullStates(ssq
, qStart
, qEnd
, resolution
, monitor
, new IQueryHandler() {
261 public void handle(List
<List
<ITmfStateInterval
>> fullStates
, List
<ITmfStateInterval
> prevFullState
) {
262 for (int threadQuark
: threadQuarks
) {
263 String threadName
= ssq
.getAttributeName(threadQuark
);
266 threadId
= Integer
.parseInt(threadName
);
267 } catch (NumberFormatException e1
) {
270 if (threadId
<= 0) { // ignore the 'unknown' (-1) and swapper (0) threads
277 execNameQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.EXEC_NAME
);
278 ppidQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.PPID
);
279 } catch (AttributeNotFoundException e
) {
280 /* No information on this thread (yet?), skip it for now */
283 ITmfStateInterval lastExecNameInterval
= prevFullState
== null || execNameQuark
>= prevFullState
.size() ?
null : prevFullState
.get(execNameQuark
);
284 long lastExecNameStartTime
= lastExecNameInterval
== null ?
-1 : lastExecNameInterval
.getStartTime();
285 long lastExecNameEndTime
= lastExecNameInterval
== null ?
-1 : lastExecNameInterval
.getEndTime() + 1;
286 long lastPpidStartTime
= prevFullState
== null || ppidQuark
>= prevFullState
.size() ?
-1 : prevFullState
.get(ppidQuark
).getStartTime();
287 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
288 if (monitor
.isCanceled()) {
291 if (execNameQuark
>= fullState
.size() || ppidQuark
>= fullState
.size()) {
292 /* No information on this thread (yet?), skip it for now */
295 ITmfStateInterval execNameInterval
= fullState
.get(execNameQuark
);
296 ITmfStateInterval ppidInterval
= fullState
.get(ppidQuark
);
297 long startTime
= execNameInterval
.getStartTime();
298 long endTime
= execNameInterval
.getEndTime() + 1;
299 if (startTime
== lastExecNameStartTime
&& ppidInterval
.getStartTime() == lastPpidStartTime
) {
302 boolean isNull
= execNameInterval
.getStateValue().isNull();
303 if (isNull
&& lastExecNameEndTime
< startTime
&& lastExecNameEndTime
!= -1) {
305 * There was a non-null interval in between the
306 * full states, try to use it.
309 execNameInterval
= ssq
.querySingleState(startTime
- 1, execNameQuark
);
310 ppidInterval
= ssq
.querySingleState(startTime
- 1, ppidQuark
);
311 startTime
= execNameInterval
.getStartTime();
312 endTime
= execNameInterval
.getEndTime() + 1;
313 } catch (AttributeNotFoundException e
) {
314 Activator
.getDefault().logError(e
.getMessage());
315 } catch (StateSystemDisposedException e
) {
319 if (!execNameInterval
.getStateValue().isNull() &&
320 execNameInterval
.getStateValue().getType() == ITmfStateValue
.Type
.STRING
) {
321 String execName
= execNameInterval
.getStateValue().unboxStr();
322 int ppid
= ppidInterval
.getStateValue().unboxInt();
323 ControlFlowEntry entry
= entryMap
.get(threadId
);
325 entry
= new ControlFlowEntry(threadQuark
, trace
, execName
, threadId
, ppid
, startTime
, endTime
);
326 entryList
.add(entry
);
327 entryMap
.put(threadId
, entry
);
330 * Update the name of the entry to the
331 * latest execName and the parent thread id
332 * to the latest ppid.
334 entry
.setName(execName
);
335 entry
.setParentThreadId(ppid
);
336 entry
.updateEndTime(endTime
);
340 entryMap
.remove(threadId
);
342 lastExecNameStartTime
= startTime
;
343 lastExecNameEndTime
= endTime
;
344 lastPpidStartTime
= ppidInterval
.getStartTime();
347 updateTree(entryList
, parentTrace
, ssq
);
349 for (final TimeGraphEntry entry
: getEntryList(ssq
)) {
350 if (monitor
.isCanceled()) {
353 buildStatusEvents(trace
, parentTrace
, ssq
, fullStates
, prevFullState
, (ControlFlowEntry
) entry
, monitor
, qStart
, qEnd
);
358 if (parentTrace
.equals(getTrace())) {
366 private void updateTree(List
<ControlFlowEntry
> entryList
, ITmfTrace parentTrace
, ITmfStateSystem ss
) {
367 List
<TimeGraphEntry
> rootListToAdd
= new ArrayList
<>();
368 List
<TimeGraphEntry
> rootListToRemove
= new ArrayList
<>();
369 List
<TimeGraphEntry
> rootList
= getEntryList(ss
);
371 for (ControlFlowEntry entry
: entryList
) {
372 boolean root
= (entry
.getParent() == null);
373 if (root
&& entry
.getParentThreadId() > 0) {
374 for (ControlFlowEntry parent
: entryList
) {
376 * Associate the parent entry only if their time overlap. A
377 * child entry may start before its parent, for example at
378 * the beginning of the trace if a parent has not yet
379 * appeared in the state system. We just want to make sure
380 * that the entry didn't start after the parent ended or
381 * ended before the parent started.
383 if (parent
.getThreadId() == entry
.getParentThreadId() &&
384 !(entry
.getStartTime() > parent
.getEndTime() ||
385 entry
.getEndTime() < parent
.getStartTime())) {
386 parent
.addChild(entry
);
388 if (rootList
!= null && rootList
.contains(entry
)) {
389 rootListToRemove
.add(entry
);
395 if (root
&& (rootList
== null || !rootList
.contains(entry
))) {
396 rootListToAdd
.add(entry
);
400 addToEntryList(parentTrace
, ss
, rootListToAdd
);
401 removeFromEntryList(parentTrace
, ss
, rootListToRemove
);
404 private void buildStatusEvents(ITmfTrace trace
, ITmfTrace parentTrace
, ITmfStateSystem ss
, @NonNull List
<List
<ITmfStateInterval
>> fullStates
,
405 @Nullable List
<ITmfStateInterval
> prevFullState
, ControlFlowEntry entry
, @NonNull IProgressMonitor monitor
, long start
, long end
) {
406 if (start
< entry
.getEndTime() && end
> entry
.getStartTime()) {
407 List
<ITimeEvent
> eventList
= getEventList(entry
, ss
, fullStates
, prevFullState
, monitor
);
408 if (eventList
== null) {
411 for (ITimeEvent event
: eventList
) {
412 entry
.addEvent(event
);
414 if (parentTrace
.equals(getTrace())) {
418 for (ITimeGraphEntry child
: entry
.getChildren()) {
419 if (monitor
.isCanceled()) {
422 buildStatusEvents(trace
, parentTrace
, ss
, fullStates
, prevFullState
, (ControlFlowEntry
) child
, monitor
, start
, end
);
427 protected @Nullable List
<ITimeEvent
> getEventList(@NonNull TimeGraphEntry tgentry
, ITmfStateSystem ss
,
428 @NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
, @NonNull IProgressMonitor monitor
) {
429 List
<ITimeEvent
> eventList
= null;
430 if (!(tgentry
instanceof ControlFlowEntry
)) {
433 ControlFlowEntry entry
= (ControlFlowEntry
) tgentry
;
435 int threadQuark
= entry
.getThreadQuark();
436 int statusQuark
= ss
.getQuarkRelative(threadQuark
, Attributes
.STATUS
);
437 eventList
= new ArrayList
<>(fullStates
.size());
438 ITmfStateInterval lastInterval
= prevFullState
== null || statusQuark
>= prevFullState
.size() ?
null : prevFullState
.get(statusQuark
);
439 long lastStartTime
= lastInterval
== null ?
-1 : lastInterval
.getStartTime();
440 long lastEndTime
= lastInterval
== null ?
-1 : lastInterval
.getEndTime() + 1;
441 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
442 if (monitor
.isCanceled()) {
445 if (statusQuark
>= fullState
.size()) {
446 /* No information on this thread (yet?), skip it for now */
449 ITmfStateInterval statusInterval
= fullState
.get(statusQuark
);
450 long time
= statusInterval
.getStartTime();
451 if (time
== lastStartTime
) {
454 long duration
= statusInterval
.getEndTime() - time
+ 1;
457 status
= statusInterval
.getStateValue().unboxInt();
458 } catch (StateValueTypeException e
) {
459 Activator
.getDefault().logError(e
.getMessage());
461 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
462 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
464 if (!statusInterval
.getStateValue().isNull()) {
465 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
467 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
469 lastStartTime
= time
;
470 lastEndTime
= time
+ duration
;
472 } catch (AttributeNotFoundException
| TimeRangeException e
) {
473 Activator
.getDefault().logError(e
.getMessage());
479 * Returns a value corresponding to the selected entry.
481 * Used in conjunction with synchingToTime to change the selected entry. If
482 * one of these methods is overridden in child class, then both should be.
485 * The currently selected time
486 * @return a value identifying the entry
488 private int getSelectionValue(long time
) {
490 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
494 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
498 if (time
>= ssq
.getStartTime() && time
<= ssq
.getCurrentEndTime()) {
499 List
<Integer
> currentThreadQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*", Attributes
.CURRENT_THREAD
); //$NON-NLS-1$
500 for (int currentThreadQuark
: currentThreadQuarks
) {
502 ITmfStateInterval currentThreadInterval
= ssq
.querySingleState(time
, currentThreadQuark
);
503 int currentThread
= currentThreadInterval
.getStateValue().unboxInt();
504 if (currentThread
> 0) {
505 int statusQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThread
), Attributes
.STATUS
);
506 ITmfStateInterval statusInterval
= ssq
.querySingleState(time
, statusQuark
);
507 if (statusInterval
.getStartTime() == time
) {
508 thread
= currentThread
;
512 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
513 Activator
.getDefault().logError(e
.getMessage());
514 } catch (StateSystemDisposedException e
) {
524 protected void synchingToTime(long time
) {
525 int selected
= getSelectionValue(time
);
527 for (Object element
: getTimeGraphViewer().getExpandedElements()) {
528 if (element
instanceof ControlFlowEntry
) {
529 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
530 if (entry
.getThreadId() == selected
) {
531 getTimeGraphCombo().setSelection(entry
);
540 protected @NonNull List
<ILinkEvent
> getLinkList(ITmfStateSystem ss
,
541 @NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
, @NonNull IProgressMonitor monitor
) {
542 List
<ILinkEvent
> list
= new ArrayList
<>();
543 List
<TimeGraphEntry
> entryList
= getEntryList(ss
);
544 if (entryList
== null) {
547 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
548 List
<Integer
> currentThreadQuarks
= ss
.getQuarks(Attributes
.CPUS
, "*", Attributes
.CURRENT_THREAD
); //$NON-NLS-1$
549 for (int currentThreadQuark
: currentThreadQuarks
) {
550 if (currentThreadQuark
>= fullStates
.get(0).size()) {
551 /* No information on this cpu (yet?), skip it for now */
554 List
<ITmfStateInterval
> currentThreadIntervals
= new ArrayList
<>(fullStates
.size() + 2);
557 * Add the previous interval if it is the first query
558 * iteration and the first interval has currentThread=0. Add
559 * the following interval if the last interval has
560 * currentThread=0. These are diagonal arrows crossing the
561 * query iteration range.
563 if (prevFullState
== null) {
564 ITmfStateInterval currentThreadInterval
= fullStates
.get(0).get(currentThreadQuark
);
565 if (currentThreadInterval
.getStateValue().unboxInt() == 0) {
566 long start
= Math
.max(currentThreadInterval
.getStartTime() - 1, ss
.getStartTime());
567 currentThreadIntervals
.add(ss
.querySingleState(start
, currentThreadQuark
));
570 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
571 currentThreadIntervals
.add(fullState
.get(currentThreadQuark
));
573 ITmfStateInterval currentThreadInterval
= fullStates
.get(fullStates
.size() - 1).get(currentThreadQuark
);
574 if (currentThreadInterval
.getStateValue().unboxInt() == 0) {
575 long end
= Math
.min(currentThreadInterval
.getEndTime() + 1, ss
.getCurrentEndTime());
576 currentThreadIntervals
.add(ss
.querySingleState(end
, currentThreadQuark
));
578 } catch (AttributeNotFoundException e
) {
579 Activator
.getDefault().logError(e
.getMessage());
581 } catch (StateSystemDisposedException e
) {
588 for (ITmfStateInterval currentThreadInterval
: currentThreadIntervals
) {
589 if (monitor
.isCanceled()) {
592 if (currentThreadInterval
.getEndTime() + 1 == lastEnd
) {
595 long time
= currentThreadInterval
.getStartTime();
596 if (time
!= lastEnd
) {
597 // don't create links where there are gaps in intervals due to the resolution
601 int thread
= currentThreadInterval
.getStateValue().unboxInt();
602 if (thread
> 0 && prevThread
> 0) {
603 ITimeGraphEntry prevEntry
= findEntry(entryList
, trace
, prevThread
);
604 ITimeGraphEntry nextEntry
= findEntry(entryList
, trace
, thread
);
605 list
.add(new TimeLinkEvent(prevEntry
, nextEntry
, prevEnd
, time
- prevEnd
, 0));
607 lastEnd
= currentThreadInterval
.getEndTime() + 1;
618 private ControlFlowEntry
findEntry(List
<?
extends ITimeGraphEntry
> entryList
, ITmfTrace trace
, int threadId
) {
619 for (ITimeGraphEntry entry
: entryList
) {
620 if (entry
instanceof ControlFlowEntry
) {
621 ControlFlowEntry controlFlowEntry
= (ControlFlowEntry
) entry
;
622 if (controlFlowEntry
.getThreadId() == threadId
&& controlFlowEntry
.getTrace() == trace
) {
623 return controlFlowEntry
;
624 } else if (entry
.hasChildren()) {
625 controlFlowEntry
= findEntry(entry
.getChildren(), trace
, threadId
);
626 if (controlFlowEntry
!= null) {
627 return controlFlowEntry
;