c31fd207797655cd8364f9c2507c8ca7e822d883
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / analysis / os / linux / ui / views / controlflow / ControlFlowView.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal and others.
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * 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 *******************************************************************************/
14
15 package org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow;
16
17 import java.util.ArrayList;
18 import java.util.Comparator;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
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;
61
62 import com.google.common.collect.ImmutableList;
63
64 /**
65 * The Control Flow view main object
66 *
67 */
68 public class ControlFlowView extends AbstractStateSystemTimeGraphView {
69
70 // ------------------------------------------------------------------------
71 // Constants
72 // ------------------------------------------------------------------------
73 /**
74 * View ID.
75 */
76 public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.views.controlflow"; //$NON-NLS-1$
77
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;
83
84 private static final String[] COLUMN_NAMES = new String[] {
85 PROCESS_COLUMN,
86 TID_COLUMN,
87 PTID_COLUMN,
88 BIRTH_TIME_COLUMN,
89 TRACE_COLUMN
90 };
91
92 private static final String[] FILTER_COLUMN_NAMES = new String[] {
93 PROCESS_COLUMN,
94 TID_COLUMN
95 };
96
97 // Timeout between updates in the build thread in ms
98 private static final long BUILD_UPDATE_TIMEOUT = 500;
99
100 private static final Comparator<ITimeGraphEntry>[] COLUMN_COMPARATORS;
101
102 private static final int INITIAL_SORT_COLUMN_INDEX = 3;
103
104 static {
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()]);
113 }
114
115 // ------------------------------------------------------------------------
116 // Constructors
117 // ------------------------------------------------------------------------
118
119 /**
120 * Constructor
121 */
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);
129 }
130
131 @Override
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));
140 }
141
142 /**
143 * @since 2.0
144 */
145 @Override
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()));
153 }
154 }
155 }
156
157 @Override
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());
164 }
165
166 IAction hideArrowsAction = getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section);
167 manager.add(hideArrowsAction);
168
169 IAction followArrowBwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction();
170 followArrowBwdAction.setText(Messages.ControlFlowView_followCPUBwdText);
171 followArrowBwdAction.setToolTipText(Messages.ControlFlowView_followCPUBwdText);
172 manager.add(followArrowBwdAction);
173
174 IAction followArrowFwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction();
175 followArrowFwdAction.setText(Messages.ControlFlowView_followCPUFwdText);
176 followArrowFwdAction.setToolTipText(Messages.ControlFlowView_followCPUFwdText);
177 manager.add(followArrowFwdAction);
178 }
179
180 @Override
181 protected String getNextText() {
182 return Messages.ControlFlowView_nextProcessActionNameText;
183 }
184
185 @Override
186 protected String getNextTooltip() {
187 return Messages.ControlFlowView_nextProcessActionToolTipText;
188 }
189
190 @Override
191 protected String getPrevText() {
192 return Messages.ControlFlowView_previousProcessActionNameText;
193 }
194
195 @Override
196 protected String getPrevTooltip() {
197 return Messages.ControlFlowView_previousProcessActionToolTipText;
198 }
199
200 /**
201 * @author gbastien
202 *
203 */
204 protected static class ControlFlowTreeLabelProvider extends TreeLabelProvider {
205
206 @Override
207 public String getColumnText(Object element, int columnIndex) {
208 ControlFlowEntry entry = (ControlFlowEntry) element;
209
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());
217 }
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();
222 }
223 return ""; //$NON-NLS-1$
224 }
225
226 }
227
228 private static class ControlFlowFilterLabelProvider extends TreeLabelProvider {
229
230 @Override
231 public String getColumnText(Object element, int columnIndex) {
232 ControlFlowEntry entry = (ControlFlowEntry) element;
233
234 if (columnIndex == 0) {
235 return entry.getName();
236 } else if (columnIndex == 1) {
237 return Integer.toString(entry.getThreadId());
238 }
239 return ""; //$NON-NLS-1$
240 }
241
242 }
243
244 // ------------------------------------------------------------------------
245 // Internal
246 // ------------------------------------------------------------------------
247
248 @Override
249 protected void buildEventList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
250 final ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
251 if (ssq == null) {
252 return;
253 }
254
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<>();
258
259 long start = ssq.getStartTime();
260 setStartTime(Math.min(getStartTime(), start));
261
262 boolean complete = false;
263 while (!complete) {
264 if (monitor.isCanceled()) {
265 return;
266 }
267 complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
268 if (ssq.isCancelled()) {
269 return;
270 }
271 long end = ssq.getCurrentEndTime();
272 if (start == end && !complete) { // when complete execute one last time regardless of end time
273 continue;
274 }
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() {
281 @Override
282 public void handle(List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState) {
283 for (int threadQuark : threadQuarks) {
284 String threadAttributeName = ssq.getAttributeName(threadQuark);
285
286 Pair<Integer, Integer> entryKey = Attributes.parseThreadAttributeName(threadAttributeName);
287 int threadId = entryKey.getFirst();
288
289 if (threadId < 0) { // ignore the 'unknown' (-1) thread
290 continue;
291 }
292
293 int execNameQuark;
294 int ppidQuark;
295 try {
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 */
300 continue;
301 }
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()) {
308 return;
309 }
310 if (execNameQuark >= fullState.size() || ppidQuark >= fullState.size()) {
311 /* No information on this thread (yet?), skip it for now */
312 continue;
313 }
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) {
319 continue;
320 }
321 boolean isNull = execNameInterval.getStateValue().isNull();
322 if (isNull && lastExecNameEndTime < startTime && lastExecNameEndTime != -1) {
323 /*
324 * There was a non-null interval in between the
325 * full states, try to use it.
326 */
327 try {
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) {
335 /* ignored */
336 }
337 }
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);
343 if (entry == null) {
344 entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
345 entryList.add(entry);
346 entryMap.put(entryKey, entry);
347 } else {
348 /*
349 * Update the name of the entry to the
350 * latest execName and the parent thread id
351 * to the latest ppid.
352 */
353 entry.setName(execName);
354 entry.setParentThreadId(ppid);
355 entry.updateEndTime(endTime);
356 }
357 }
358 if (isNull) {
359 entryMap.remove(entryKey);
360 }
361 lastExecNameStartTime = startTime;
362 lastExecNameEndTime = endTime;
363 lastPpidStartTime = ppidInterval.getStartTime();
364 }
365 }
366 updateTree(entryList, parentTrace, ssq);
367
368 for (final TimeGraphEntry entry : getEntryList(ssq)) {
369 if (monitor.isCanceled()) {
370 return;
371 }
372 buildStatusEvents(trace, parentTrace, ssq, fullStates, prevFullState, (ControlFlowEntry) entry, monitor, qStart, qEnd);
373 }
374 }
375 });
376
377 if (parentTrace.equals(getTrace())) {
378 refresh();
379 }
380
381 start = end;
382 }
383 }
384
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);
389
390 for (ControlFlowEntry entry : entryList) {
391 boolean root = (entry.getParent() == null);
392 if (root && entry.getParentThreadId() > 0) {
393 for (ControlFlowEntry parent : entryList) {
394 /*
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.
401 */
402 if (parent.getThreadId() == entry.getParentThreadId() &&
403 !(entry.getStartTime() > parent.getEndTime() ||
404 entry.getEndTime() < parent.getStartTime())) {
405 parent.addChild(entry);
406 root = false;
407 if (rootList != null && rootList.contains(entry)) {
408 rootListToRemove.add(entry);
409 }
410 break;
411 }
412 }
413 }
414 if (root && (rootList == null || !rootList.contains(entry))) {
415 rootListToAdd.add(entry);
416 }
417 }
418
419 addToEntryList(parentTrace, ss, rootListToAdd);
420 removeFromEntryList(parentTrace, ss, rootListToRemove);
421 }
422
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) {
428 return;
429 }
430 for (ITimeEvent event : eventList) {
431 entry.addEvent(event);
432 }
433 if (parentTrace.equals(getTrace())) {
434 redraw();
435 }
436 }
437 for (ITimeGraphEntry child : entry.getChildren()) {
438 if (monitor.isCanceled()) {
439 return;
440 }
441 buildStatusEvents(trace, parentTrace, ss, fullStates, prevFullState, (ControlFlowEntry) child, monitor, start, end);
442 }
443 }
444
445 @Override
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)) {
450 return eventList;
451 }
452 ControlFlowEntry entry = (ControlFlowEntry) tgentry;
453 try {
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()) {
462 return null;
463 }
464 if (statusQuark >= fullState.size()) {
465 /* No information on this thread (yet?), skip it for now */
466 continue;
467 }
468 ITmfStateInterval statusInterval = fullState.get(statusQuark);
469 long time = statusInterval.getStartTime();
470 if (time == lastStartTime) {
471 continue;
472 }
473 long duration = statusInterval.getEndTime() - time + 1;
474 int status = -1;
475 try {
476 status = statusInterval.getStateValue().unboxInt();
477 } catch (StateValueTypeException e) {
478 Activator.getDefault().logError(e.getMessage());
479 }
480 if (lastEndTime != time && lastEndTime != -1) {
481 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
482 }
483 if (!statusInterval.getStateValue().isNull()) {
484 eventList.add(new TimeEvent(entry, time, duration, status));
485 } else {
486 eventList.add(new NullTimeEvent(entry, time, duration));
487 }
488 lastStartTime = time;
489 lastEndTime = time + duration;
490 }
491 } catch (AttributeNotFoundException | TimeRangeException e) {
492 Activator.getDefault().logError(e.getMessage());
493 }
494 return eventList;
495 }
496
497 /**
498 * Returns a value corresponding to the selected entry.
499 *
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.
502 *
503 * @param time
504 * The currently selected time
505 * @return a value identifying the entry
506 */
507 private int getSelectionValue(long time) {
508 int thread = -1;
509 for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
510 if (thread > 0) {
511 break;
512 }
513 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
514 if (ssq == null) {
515 continue;
516 }
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) {
520 try {
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;
528 break;
529 }
530 }
531 } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
532 Activator.getDefault().logError(e.getMessage());
533 } catch (StateSystemDisposedException e) {
534 /* Ignored */
535 }
536 }
537 }
538 }
539 return thread;
540 }
541
542 @Override
543 protected void synchingToTime(long time) {
544 int selected = getSelectionValue(time);
545 if (selected > 0) {
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);
551 break;
552 }
553 }
554 }
555 }
556 }
557
558 @Override
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) {
564 return list;
565 }
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 */
571 continue;
572 }
573 List<ITmfStateInterval> currentThreadIntervals = new ArrayList<>(fullStates.size() + 2);
574 try {
575 /*
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.
581 */
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));
587 }
588 }
589 for (List<ITmfStateInterval> fullState : fullStates) {
590 currentThreadIntervals.add(fullState.get(currentThreadQuark));
591 }
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));
596 }
597 } catch (AttributeNotFoundException e) {
598 Activator.getDefault().logError(e.getMessage());
599 return list;
600 } catch (StateSystemDisposedException e) {
601 /* Ignored */
602 return list;
603 }
604 int prevThread = 0;
605 long prevEnd = 0;
606 long lastEnd = 0;
607 for (ITmfStateInterval currentThreadInterval : currentThreadIntervals) {
608 if (monitor.isCanceled()) {
609 return list;
610 }
611 if (currentThreadInterval.getEndTime() + 1 == lastEnd) {
612 continue;
613 }
614 long time = currentThreadInterval.getStartTime();
615 if (time != lastEnd) {
616 // don't create links where there are gaps in intervals due to the resolution
617 prevThread = 0;
618 prevEnd = 0;
619 }
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));
625 }
626 lastEnd = currentThreadInterval.getEndTime() + 1;
627 if (thread != 0) {
628 prevThread = thread;
629 prevEnd = lastEnd;
630 }
631 }
632 }
633 }
634 return list;
635 }
636
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;
647 }
648 }
649 }
650 }
651 return null;
652 }
653 }
This page took 0.07048 seconds and 4 git commands to generate.