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
.internal
.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
.statesystem
.core
.ITmfStateSystem
;
39 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
40 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
41 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
42 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
43 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
44 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
45 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
46 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
47 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
48 import org
.eclipse
.tracecompass
.tmf
.core
.util
.Pair
;
49 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractStateSystemTimeGraphView
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
51 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
52 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
53 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
54 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
55 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
56 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeLinkEvent
;
57 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
58 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
59 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
61 import com
.google
.common
.collect
.ImmutableList
;
64 * The Control Flow view main object
67 public class ControlFlowView
extends AbstractStateSystemTimeGraphView
{
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
75 public static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.views.controlflow"; //$NON-NLS-1$
77 private static final String PROCESS_COLUMN
= Messages
.ControlFlowView_processColumn
;
78 private static final String TID_COLUMN
= Messages
.ControlFlowView_tidColumn
;
79 private static final String PTID_COLUMN
= Messages
.ControlFlowView_ptidColumn
;
80 private static final String BIRTH_TIME_COLUMN
= Messages
.ControlFlowView_birthTimeColumn
;
81 private static final String TRACE_COLUMN
= Messages
.ControlFlowView_traceColumn
;
83 private static final String
[] COLUMN_NAMES
= new String
[] {
91 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
96 // Timeout between updates in the build thread in ms
97 private static final long BUILD_UPDATE_TIMEOUT
= 500;
99 private static final Comparator
<ITimeGraphEntry
>[] COLUMN_COMPARATORS
;
101 private static final int INITIAL_SORT_COLUMN_INDEX
= 3;
104 ImmutableList
.Builder
<Comparator
<ITimeGraphEntry
>> builder
= ImmutableList
.builder();
105 builder
.add(ControlFlowColumnComparators
.PROCESS_NAME_COLUMN_COMPARATOR
)
106 .add(ControlFlowColumnComparators
.TID_COLUMN_COMPARATOR
)
107 .add(ControlFlowColumnComparators
.PTID_COLUMN_COMPARATOR
)
108 .add(ControlFlowColumnComparators
.BIRTH_TIME_COLUMN_COMPARATOR
)
109 .add(ControlFlowColumnComparators
.TRACE_COLUMN_COMPARATOR
);
110 List
<Comparator
<ITimeGraphEntry
>> l
= builder
.build();
111 COLUMN_COMPARATORS
= l
.toArray(new Comparator
[l
.size()]);
114 // ------------------------------------------------------------------------
116 // ------------------------------------------------------------------------
121 public ControlFlowView() {
122 super(ID
, new ControlFlowPresentationProvider());
123 setTreeColumns(COLUMN_NAMES
, COLUMN_COMPARATORS
, INITIAL_SORT_COLUMN_INDEX
);
124 setTreeLabelProvider(new ControlFlowTreeLabelProvider());
125 setFilterColumns(FILTER_COLUMN_NAMES
);
126 setFilterLabelProvider(new ControlFlowFilterLabelProvider());
127 setEntryComparator(ControlFlowColumnComparators
.BIRTH_TIME_COLUMN_COMPARATOR
);
131 public void createPartControl(Composite parent
) {
132 super.createPartControl(parent
);
133 // add "Check active" Button to TimeGraphFilterDialog
134 super.getTimeGraphCombo().addTimeGraphFilterCheckActiveButton(
135 new ControlFlowCheckActiveProvider(Messages
.ControlFlowView_checkActiveLabel
, Messages
.ControlFlowView_checkActiveToolTip
));
136 // add "Uncheck inactive" Button to TimeGraphFilterDialog
137 super.getTimeGraphCombo().addTimeGraphFilterUncheckInactiveButton(
138 new ControlFlowCheckActiveProvider(Messages
.ControlFlowView_uncheckInactiveLabel
, Messages
.ControlFlowView_uncheckInactiveToolTip
));
145 protected void fillTimeGraphEntryContextMenu(@NonNull IMenuManager menuManager
) {
146 ISelection selection
= getSite().getSelectionProvider().getSelection();
147 if (selection
instanceof StructuredSelection
) {
148 StructuredSelection sSel
= (StructuredSelection
) selection
;
149 if (sSel
.getFirstElement() instanceof ControlFlowEntry
) {
150 ControlFlowEntry entry
= (ControlFlowEntry
) sSel
.getFirstElement();
151 menuManager
.add(new FollowThreadAction(ControlFlowView
.this, entry
.getName(), entry
.getThreadId(), entry
.getTrace()));
157 protected void fillLocalToolBar(IToolBarManager manager
) {
158 super.fillLocalToolBar(manager
);
159 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
160 IDialogSettings section
= settings
.getSection(getClass().getName());
161 if (section
== null) {
162 section
= settings
.addNewSection(getClass().getName());
165 IAction hideArrowsAction
= getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section
);
166 manager
.add(hideArrowsAction
);
168 IAction followArrowBwdAction
= getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction();
169 followArrowBwdAction
.setText(Messages
.ControlFlowView_followCPUBwdText
);
170 followArrowBwdAction
.setToolTipText(Messages
.ControlFlowView_followCPUBwdText
);
171 manager
.add(followArrowBwdAction
);
173 IAction followArrowFwdAction
= getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction();
174 followArrowFwdAction
.setText(Messages
.ControlFlowView_followCPUFwdText
);
175 followArrowFwdAction
.setToolTipText(Messages
.ControlFlowView_followCPUFwdText
);
176 manager
.add(followArrowFwdAction
);
180 protected String
getNextText() {
181 return Messages
.ControlFlowView_nextProcessActionNameText
;
185 protected String
getNextTooltip() {
186 return Messages
.ControlFlowView_nextProcessActionToolTipText
;
190 protected String
getPrevText() {
191 return Messages
.ControlFlowView_previousProcessActionNameText
;
195 protected String
getPrevTooltip() {
196 return Messages
.ControlFlowView_previousProcessActionToolTipText
;
203 protected static class ControlFlowTreeLabelProvider
extends TreeLabelProvider
{
206 public String
getColumnText(Object element
, int columnIndex
) {
207 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
209 if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_processColumn
)) {
210 return entry
.getName();
211 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_tidColumn
)) {
212 return Integer
.toString(entry
.getThreadId());
213 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_ptidColumn
)) {
214 if (entry
.getParentThreadId() > 0) {
215 return Integer
.toString(entry
.getParentThreadId());
217 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_birthTimeColumn
)) {
218 return Utils
.formatTime(entry
.getStartTime(), TimeFormat
.CALENDAR
, Resolution
.NANOSEC
);
219 } else if (COLUMN_NAMES
[columnIndex
].equals(Messages
.ControlFlowView_traceColumn
)) {
220 return entry
.getTrace().getName();
222 return ""; //$NON-NLS-1$
227 private static class ControlFlowFilterLabelProvider
extends TreeLabelProvider
{
230 public String
getColumnText(Object element
, int columnIndex
) {
231 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
233 if (columnIndex
== 0) {
234 return entry
.getName();
235 } else if (columnIndex
== 1) {
236 return Integer
.toString(entry
.getThreadId());
238 return ""; //$NON-NLS-1$
243 // ------------------------------------------------------------------------
245 // ------------------------------------------------------------------------
248 protected void buildEntryList(final ITmfTrace trace
, final ITmfTrace parentTrace
, final IProgressMonitor monitor
) {
249 final ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
254 final List
<ControlFlowEntry
> entryList
= new ArrayList
<>();
255 /** Map of view entries, key is a pair [threadId, cpuId] */
256 final Map
<Pair
<Integer
, Integer
>, ControlFlowEntry
> entryMap
= new HashMap
<>();
258 long start
= ssq
.getStartTime();
259 setStartTime(Math
.min(getStartTime(), start
));
261 boolean complete
= false;
263 if (monitor
.isCanceled()) {
266 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
267 if (ssq
.isCancelled()) {
270 long end
= ssq
.getCurrentEndTime();
271 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
274 final long resolution
= Math
.max(1, (end
- ssq
.getStartTime()) / getDisplayWidth());
275 setEndTime(Math
.max(getEndTime(), end
+ 1));
276 final List
<Integer
> threadQuarks
= ssq
.getQuarks(Attributes
.THREADS
, "*"); //$NON-NLS-1$
277 queryFullStates(ssq
, start
, end
, resolution
, monitor
, new IQueryHandler() {
279 public void handle(List
<List
<ITmfStateInterval
>> fullStates
, List
<ITmfStateInterval
> prevFullState
) {
280 for (int threadQuark
: threadQuarks
) {
281 String threadAttributeName
= ssq
.getAttributeName(threadQuark
);
283 Pair
<Integer
, Integer
> entryKey
= Attributes
.parseThreadAttributeName(threadAttributeName
);
284 int threadId
= entryKey
.getFirst();
286 if (threadId
< 0) { // ignore the 'unknown' (-1) thread
293 execNameQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.EXEC_NAME
);
294 ppidQuark
= ssq
.getQuarkRelative(threadQuark
, Attributes
.PPID
);
295 } catch (AttributeNotFoundException e
) {
296 /* No information on this thread (yet?), skip it for now */
299 ITmfStateInterval lastExecNameInterval
= prevFullState
== null || execNameQuark
>= prevFullState
.size() ?
null : prevFullState
.get(execNameQuark
);
300 long lastExecNameStartTime
= lastExecNameInterval
== null ?
-1 : lastExecNameInterval
.getStartTime();
301 long lastExecNameEndTime
= lastExecNameInterval
== null ?
-1 : lastExecNameInterval
.getEndTime() + 1;
302 long lastPpidStartTime
= prevFullState
== null || ppidQuark
>= prevFullState
.size() ?
-1 : prevFullState
.get(ppidQuark
).getStartTime();
303 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
304 if (monitor
.isCanceled()) {
307 if (execNameQuark
>= fullState
.size() || ppidQuark
>= fullState
.size()) {
308 /* No information on this thread (yet?), skip it for now */
311 ITmfStateInterval execNameInterval
= fullState
.get(execNameQuark
);
312 ITmfStateInterval ppidInterval
= fullState
.get(ppidQuark
);
313 long startTime
= execNameInterval
.getStartTime();
314 long endTime
= execNameInterval
.getEndTime() + 1;
315 if (startTime
== lastExecNameStartTime
&& ppidInterval
.getStartTime() == lastPpidStartTime
) {
318 boolean isNull
= execNameInterval
.getStateValue().isNull();
319 if (isNull
&& lastExecNameEndTime
< startTime
&& lastExecNameEndTime
!= -1) {
321 * There was a non-null interval in between the
322 * full states, try to use it.
325 execNameInterval
= ssq
.querySingleState(startTime
- 1, execNameQuark
);
326 ppidInterval
= ssq
.querySingleState(startTime
- 1, ppidQuark
);
327 startTime
= execNameInterval
.getStartTime();
328 endTime
= execNameInterval
.getEndTime() + 1;
329 } catch (AttributeNotFoundException e
) {
330 Activator
.getDefault().logError(e
.getMessage());
331 } catch (StateSystemDisposedException e
) {
335 if (!execNameInterval
.getStateValue().isNull() &&
336 execNameInterval
.getStateValue().getType() == ITmfStateValue
.Type
.STRING
) {
337 String execName
= execNameInterval
.getStateValue().unboxStr();
338 int ppid
= ppidInterval
.getStateValue().unboxInt();
339 ControlFlowEntry entry
= entryMap
.get(entryKey
);
341 entry
= new ControlFlowEntry(threadQuark
, trace
, execName
, threadId
, ppid
, startTime
, endTime
);
342 entryList
.add(entry
);
343 entryMap
.put(entryKey
, entry
);
346 * Update the name of the entry to the
347 * latest execName and the parent thread id
348 * to the latest ppid.
350 entry
.setName(execName
);
351 entry
.setParentThreadId(ppid
);
352 entry
.updateEndTime(endTime
);
356 entryMap
.remove(entryKey
);
358 lastExecNameStartTime
= startTime
;
359 lastExecNameEndTime
= endTime
;
360 lastPpidStartTime
= ppidInterval
.getStartTime();
363 updateTree(entryList
, parentTrace
, ssq
);
367 queryFullStates(ssq
, ssq
.getStartTime(), end
, resolution
, monitor
, new IQueryHandler() {
369 public void handle(@NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
) {
370 for (final TimeGraphEntry entry
: getEntryList(ssq
)) {
371 if (monitor
.isCanceled()) {
374 buildStatusEvents(trace
, parentTrace
, ssq
, fullStates
, prevFullState
, (ControlFlowEntry
) entry
, monitor
, ssq
.getStartTime(), end
);
379 if (parentTrace
.equals(getTrace())) {
387 private void updateTree(List
<ControlFlowEntry
> entryList
, ITmfTrace parentTrace
, ITmfStateSystem ss
) {
388 List
<TimeGraphEntry
> rootListToAdd
= new ArrayList
<>();
389 List
<TimeGraphEntry
> rootListToRemove
= new ArrayList
<>();
390 List
<TimeGraphEntry
> rootList
= getEntryList(ss
);
392 for (ControlFlowEntry entry
: entryList
) {
393 boolean root
= (entry
.getParent() == null);
394 if (root
&& entry
.getParentThreadId() > 0) {
395 for (ControlFlowEntry parent
: entryList
) {
397 * Associate the parent entry only if their time overlap. A
398 * child entry may start before its parent, for example at
399 * the beginning of the trace if a parent has not yet
400 * appeared in the state system. We just want to make sure
401 * that the entry didn't start after the parent ended or
402 * ended before the parent started.
404 if (parent
.getThreadId() == entry
.getParentThreadId() &&
405 !(entry
.getStartTime() > parent
.getEndTime() ||
406 entry
.getEndTime() < parent
.getStartTime())) {
407 parent
.addChild(entry
);
409 if (rootList
!= null && rootList
.contains(entry
)) {
410 rootListToRemove
.add(entry
);
416 if (root
&& (rootList
== null || !rootList
.contains(entry
))) {
417 rootListToAdd
.add(entry
);
421 addToEntryList(parentTrace
, ss
, rootListToAdd
);
422 removeFromEntryList(parentTrace
, ss
, rootListToRemove
);
425 private void buildStatusEvents(ITmfTrace trace
, ITmfTrace parentTrace
, ITmfStateSystem ss
, @NonNull List
<List
<ITmfStateInterval
>> fullStates
,
426 @Nullable List
<ITmfStateInterval
> prevFullState
, ControlFlowEntry entry
, @NonNull IProgressMonitor monitor
, long start
, long end
) {
427 if (start
< entry
.getEndTime() && end
> entry
.getStartTime()) {
428 List
<ITimeEvent
> eventList
= getEventList(entry
, ss
, fullStates
, prevFullState
, monitor
);
429 if (eventList
== null) {
432 /* Start a new event list on first iteration, then append to it */
433 if (prevFullState
== null) {
434 entry
.setEventList(eventList
);
436 for (ITimeEvent event
: eventList
) {
437 entry
.addEvent(event
);
440 if (parentTrace
.equals(getTrace())) {
444 for (ITimeGraphEntry child
: entry
.getChildren()) {
445 if (monitor
.isCanceled()) {
448 buildStatusEvents(trace
, parentTrace
, ss
, fullStates
, prevFullState
, (ControlFlowEntry
) child
, monitor
, start
, end
);
453 protected @Nullable List
<ITimeEvent
> getEventList(@NonNull TimeGraphEntry tgentry
, ITmfStateSystem ss
,
454 @NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
, @NonNull IProgressMonitor monitor
) {
455 List
<ITimeEvent
> eventList
= null;
456 if (!(tgentry
instanceof ControlFlowEntry
)) {
459 ControlFlowEntry entry
= (ControlFlowEntry
) tgentry
;
461 int threadQuark
= entry
.getThreadQuark();
462 int statusQuark
= ss
.getQuarkRelative(threadQuark
, Attributes
.STATUS
);
463 eventList
= new ArrayList
<>(fullStates
.size());
464 ITmfStateInterval lastInterval
= prevFullState
== null || statusQuark
>= prevFullState
.size() ?
null : prevFullState
.get(statusQuark
);
465 long lastStartTime
= lastInterval
== null ?
-1 : lastInterval
.getStartTime();
466 long lastEndTime
= lastInterval
== null ?
-1 : lastInterval
.getEndTime() + 1;
467 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
468 if (monitor
.isCanceled()) {
471 if (statusQuark
>= fullState
.size()) {
472 /* No information on this thread (yet?), skip it for now */
475 ITmfStateInterval statusInterval
= fullState
.get(statusQuark
);
476 long time
= statusInterval
.getStartTime();
477 if (time
== lastStartTime
) {
480 long duration
= statusInterval
.getEndTime() - time
+ 1;
483 status
= statusInterval
.getStateValue().unboxInt();
484 } catch (StateValueTypeException e
) {
485 Activator
.getDefault().logError(e
.getMessage());
487 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
488 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
490 if (!statusInterval
.getStateValue().isNull()) {
491 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
493 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
495 lastStartTime
= time
;
496 lastEndTime
= time
+ duration
;
498 } catch (AttributeNotFoundException
| TimeRangeException e
) {
499 Activator
.getDefault().logError(e
.getMessage());
505 * Returns a value corresponding to the selected entry.
507 * Used in conjunction with synchingToTime to change the selected entry. If
508 * one of these methods is overridden in child class, then both should be.
511 * The currently selected time
512 * @return a value identifying the entry
514 private int getSelectionValue(long time
) {
516 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
520 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
524 if (time
>= ssq
.getStartTime() && time
<= ssq
.getCurrentEndTime()) {
525 List
<Integer
> currentThreadQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*", Attributes
.CURRENT_THREAD
); //$NON-NLS-1$
526 for (int currentThreadQuark
: currentThreadQuarks
) {
528 ITmfStateInterval currentThreadInterval
= ssq
.querySingleState(time
, currentThreadQuark
);
529 int currentThread
= currentThreadInterval
.getStateValue().unboxInt();
530 if (currentThread
> 0) {
531 int statusQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThread
), Attributes
.STATUS
);
532 ITmfStateInterval statusInterval
= ssq
.querySingleState(time
, statusQuark
);
533 if (statusInterval
.getStartTime() == time
) {
534 thread
= currentThread
;
538 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
539 Activator
.getDefault().logError(e
.getMessage());
540 } catch (StateSystemDisposedException e
) {
550 protected void synchingToTime(long time
) {
551 int selected
= getSelectionValue(time
);
553 for (Object element
: getTimeGraphViewer().getExpandedElements()) {
554 if (element
instanceof ControlFlowEntry
) {
555 ControlFlowEntry entry
= (ControlFlowEntry
) element
;
556 if (entry
.getThreadId() == selected
) {
557 getTimeGraphCombo().setSelection(entry
);
566 protected @NonNull List
<ILinkEvent
> getLinkList(ITmfStateSystem ss
,
567 @NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
, @NonNull IProgressMonitor monitor
) {
568 List
<ILinkEvent
> list
= new ArrayList
<>();
569 List
<TimeGraphEntry
> entryList
= getEntryList(ss
);
570 if (entryList
== null) {
573 for (ITmfTrace trace
: TmfTraceManager
.getTraceSet(getTrace())) {
574 List
<Integer
> currentThreadQuarks
= ss
.getQuarks(Attributes
.CPUS
, "*", Attributes
.CURRENT_THREAD
); //$NON-NLS-1$
575 for (int currentThreadQuark
: currentThreadQuarks
) {
576 if (currentThreadQuark
>= fullStates
.get(0).size()) {
577 /* No information on this cpu (yet?), skip it for now */
580 List
<ITmfStateInterval
> currentThreadIntervals
= new ArrayList
<>(fullStates
.size() + 2);
583 * Add the previous interval if it is the first query
584 * iteration and the first interval has currentThread=0. Add
585 * the following interval if the last interval has
586 * currentThread=0. These are diagonal arrows crossing the
587 * query iteration range.
589 if (prevFullState
== null) {
590 ITmfStateInterval currentThreadInterval
= fullStates
.get(0).get(currentThreadQuark
);
591 if (currentThreadInterval
.getStateValue().unboxInt() == 0) {
592 long start
= Math
.max(currentThreadInterval
.getStartTime() - 1, ss
.getStartTime());
593 currentThreadIntervals
.add(ss
.querySingleState(start
, currentThreadQuark
));
596 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
597 currentThreadIntervals
.add(fullState
.get(currentThreadQuark
));
599 ITmfStateInterval currentThreadInterval
= fullStates
.get(fullStates
.size() - 1).get(currentThreadQuark
);
600 if (currentThreadInterval
.getStateValue().unboxInt() == 0) {
601 long end
= Math
.min(currentThreadInterval
.getEndTime() + 1, ss
.getCurrentEndTime());
602 currentThreadIntervals
.add(ss
.querySingleState(end
, currentThreadQuark
));
604 } catch (AttributeNotFoundException e
) {
605 Activator
.getDefault().logError(e
.getMessage());
607 } catch (StateSystemDisposedException e
) {
614 for (ITmfStateInterval currentThreadInterval
: currentThreadIntervals
) {
615 if (monitor
.isCanceled()) {
618 if (currentThreadInterval
.getEndTime() + 1 == lastEnd
) {
621 long time
= currentThreadInterval
.getStartTime();
622 if (time
!= lastEnd
) {
623 // don't create links where there are gaps in intervals due to the resolution
627 int thread
= currentThreadInterval
.getStateValue().unboxInt();
628 if (thread
> 0 && prevThread
> 0) {
629 ITimeGraphEntry prevEntry
= findEntry(entryList
, trace
, prevThread
);
630 ITimeGraphEntry nextEntry
= findEntry(entryList
, trace
, thread
);
631 list
.add(new TimeLinkEvent(prevEntry
, nextEntry
, prevEnd
, time
- prevEnd
, 0));
633 lastEnd
= currentThreadInterval
.getEndTime() + 1;
644 private ControlFlowEntry
findEntry(List
<?
extends ITimeGraphEntry
> entryList
, ITmfTrace trace
, int threadId
) {
645 for (ITimeGraphEntry entry
: entryList
) {
646 if (entry
instanceof ControlFlowEntry
) {
647 ControlFlowEntry controlFlowEntry
= (ControlFlowEntry
) entry
;
648 if (controlFlowEntry
.getThreadId() == threadId
&& controlFlowEntry
.getTrace() == trace
) {
649 return controlFlowEntry
;
650 } else if (entry
.hasChildren()) {
651 controlFlowEntry
= findEntry(entry
.getChildren(), trace
, threadId
);
652 if (controlFlowEntry
!= null) {
653 return controlFlowEntry
;