714f9b8871edafc83623a816749a0ce91a1c504f
[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.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;
56
57 import com.google.common.collect.ImmutableList;
58
59 /**
60 * The Control Flow view main object
61 *
62 */
63 public class ControlFlowView extends AbstractStateSystemTimeGraphView {
64
65 // ------------------------------------------------------------------------
66 // Constants
67 // ------------------------------------------------------------------------
68 /**
69 * View ID.
70 */
71 public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.views.controlflow"; //$NON-NLS-1$
72
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;
78
79 private static final String[] COLUMN_NAMES = new String[] {
80 PROCESS_COLUMN,
81 TID_COLUMN,
82 PTID_COLUMN,
83 BIRTH_TIME_COLUMN,
84 TRACE_COLUMN
85 };
86
87 private static final String[] FILTER_COLUMN_NAMES = new String[] {
88 PROCESS_COLUMN,
89 TID_COLUMN
90 };
91
92 // Timeout between updates in the build thread in ms
93 private static final long BUILD_UPDATE_TIMEOUT = 500;
94
95 private static final Comparator<ITimeGraphEntry>[] COLUMN_COMPARATORS;
96
97 private static final int INITIAL_SORT_COLUMN_INDEX = 3;
98
99 static {
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()]);
108 }
109
110 // ------------------------------------------------------------------------
111 // Constructors
112 // ------------------------------------------------------------------------
113
114 /**
115 * Constructor
116 */
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);
124 }
125
126 @Override
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));
135 }
136
137 @Override
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());
144 }
145
146 IAction hideArrowsAction = getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section);
147 manager.add(hideArrowsAction);
148
149 IAction followArrowBwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction();
150 followArrowBwdAction.setText(Messages.ControlFlowView_followCPUBwdText);
151 followArrowBwdAction.setToolTipText(Messages.ControlFlowView_followCPUBwdText);
152 manager.add(followArrowBwdAction);
153
154 IAction followArrowFwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction();
155 followArrowFwdAction.setText(Messages.ControlFlowView_followCPUFwdText);
156 followArrowFwdAction.setToolTipText(Messages.ControlFlowView_followCPUFwdText);
157 manager.add(followArrowFwdAction);
158 }
159
160 @Override
161 protected String getNextText() {
162 return Messages.ControlFlowView_nextProcessActionNameText;
163 }
164
165 @Override
166 protected String getNextTooltip() {
167 return Messages.ControlFlowView_nextProcessActionToolTipText;
168 }
169
170 @Override
171 protected String getPrevText() {
172 return Messages.ControlFlowView_previousProcessActionNameText;
173 }
174
175 @Override
176 protected String getPrevTooltip() {
177 return Messages.ControlFlowView_previousProcessActionToolTipText;
178 }
179
180 /**
181 * @author gbastien
182 *
183 */
184 protected static class ControlFlowTreeLabelProvider extends TreeLabelProvider {
185
186 @Override
187 public String getColumnText(Object element, int columnIndex) {
188 ControlFlowEntry entry = (ControlFlowEntry) element;
189
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());
197 }
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();
202 }
203 return ""; //$NON-NLS-1$
204 }
205
206 }
207
208 private static class ControlFlowFilterLabelProvider extends TreeLabelProvider {
209
210 @Override
211 public String getColumnText(Object element, int columnIndex) {
212 ControlFlowEntry entry = (ControlFlowEntry) element;
213
214 if (columnIndex == 0) {
215 return entry.getName();
216 } else if (columnIndex == 1) {
217 return Integer.toString(entry.getThreadId());
218 }
219 return ""; //$NON-NLS-1$
220 }
221
222 }
223
224 // ------------------------------------------------------------------------
225 // Internal
226 // ------------------------------------------------------------------------
227
228 @Override
229 protected void buildEventList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
230 final ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
231 if (ssq == null) {
232 return;
233 }
234
235 final List<ControlFlowEntry> entryList = new ArrayList<>();
236 final Map<Integer, ControlFlowEntry> entryMap = new HashMap<>();
237
238 long start = ssq.getStartTime();
239 setStartTime(Math.min(getStartTime(), start));
240
241 boolean complete = false;
242 while (!complete) {
243 if (monitor.isCanceled()) {
244 return;
245 }
246 complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
247 if (ssq.isCancelled()) {
248 return;
249 }
250 long end = ssq.getCurrentEndTime();
251 if (start == end && !complete) { // when complete execute one last time regardless of end time
252 continue;
253 }
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() {
260 @Override
261 public void handle(List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState) {
262 for (int threadQuark : threadQuarks) {
263 String threadName = ssq.getAttributeName(threadQuark);
264 int threadId = -1;
265 try {
266 threadId = Integer.parseInt(threadName);
267 } catch (NumberFormatException e1) {
268 continue;
269 }
270 if (threadId <= 0) { // ignore the 'unknown' (-1) and swapper (0) threads
271 continue;
272 }
273
274 int execNameQuark;
275 int ppidQuark;
276 try {
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 */
281 continue;
282 }
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()) {
289 return;
290 }
291 if (execNameQuark >= fullState.size() || ppidQuark >= fullState.size()) {
292 /* No information on this thread (yet?), skip it for now */
293 continue;
294 }
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) {
300 continue;
301 }
302 boolean isNull = execNameInterval.getStateValue().isNull();
303 if (isNull && lastExecNameEndTime < startTime && lastExecNameEndTime != -1) {
304 /*
305 * There was a non-null interval in between the
306 * full states, try to use it.
307 */
308 try {
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) {
316 /* ignored */
317 }
318 }
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);
324 if (entry == null) {
325 entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
326 entryList.add(entry);
327 entryMap.put(threadId, entry);
328 } else {
329 /*
330 * Update the name of the entry to the
331 * latest execName and the parent thread id
332 * to the latest ppid.
333 */
334 entry.setName(execName);
335 entry.setParentThreadId(ppid);
336 entry.updateEndTime(endTime);
337 }
338 }
339 if (isNull) {
340 entryMap.remove(threadId);
341 }
342 lastExecNameStartTime = startTime;
343 lastExecNameEndTime = endTime;
344 lastPpidStartTime = ppidInterval.getStartTime();
345 }
346 }
347 updateTree(entryList, parentTrace, ssq);
348
349 for (final TimeGraphEntry entry : getEntryList(ssq)) {
350 if (monitor.isCanceled()) {
351 return;
352 }
353 buildStatusEvents(trace, parentTrace, ssq, fullStates, prevFullState, (ControlFlowEntry) entry, monitor, qStart, qEnd);
354 }
355 }
356 });
357
358 if (parentTrace.equals(getTrace())) {
359 refresh();
360 }
361
362 start = end;
363 }
364 }
365
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);
370
371 for (ControlFlowEntry entry : entryList) {
372 boolean root = (entry.getParent() == null);
373 if (root && entry.getParentThreadId() > 0) {
374 for (ControlFlowEntry parent : entryList) {
375 /*
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.
382 */
383 if (parent.getThreadId() == entry.getParentThreadId() &&
384 !(entry.getStartTime() > parent.getEndTime() ||
385 entry.getEndTime() < parent.getStartTime())) {
386 parent.addChild(entry);
387 root = false;
388 if (rootList != null && rootList.contains(entry)) {
389 rootListToRemove.add(entry);
390 }
391 break;
392 }
393 }
394 }
395 if (root && (rootList == null || !rootList.contains(entry))) {
396 rootListToAdd.add(entry);
397 }
398 }
399
400 addToEntryList(parentTrace, ss, rootListToAdd);
401 removeFromEntryList(parentTrace, ss, rootListToRemove);
402 }
403
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) {
409 return;
410 }
411 for (ITimeEvent event : eventList) {
412 entry.addEvent(event);
413 }
414 if (parentTrace.equals(getTrace())) {
415 redraw();
416 }
417 }
418 for (ITimeGraphEntry child : entry.getChildren()) {
419 if (monitor.isCanceled()) {
420 return;
421 }
422 buildStatusEvents(trace, parentTrace, ss, fullStates, prevFullState, (ControlFlowEntry) child, monitor, start, end);
423 }
424 }
425
426 @Override
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)) {
431 return eventList;
432 }
433 ControlFlowEntry entry = (ControlFlowEntry) tgentry;
434 try {
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()) {
443 return null;
444 }
445 if (statusQuark >= fullState.size()) {
446 /* No information on this thread (yet?), skip it for now */
447 continue;
448 }
449 ITmfStateInterval statusInterval = fullState.get(statusQuark);
450 long time = statusInterval.getStartTime();
451 if (time == lastStartTime) {
452 continue;
453 }
454 long duration = statusInterval.getEndTime() - time + 1;
455 int status = -1;
456 try {
457 status = statusInterval.getStateValue().unboxInt();
458 } catch (StateValueTypeException e) {
459 Activator.getDefault().logError(e.getMessage());
460 }
461 if (lastEndTime != time && lastEndTime != -1) {
462 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
463 }
464 if (!statusInterval.getStateValue().isNull()) {
465 eventList.add(new TimeEvent(entry, time, duration, status));
466 } else {
467 eventList.add(new NullTimeEvent(entry, time, duration));
468 }
469 lastStartTime = time;
470 lastEndTime = time + duration;
471 }
472 } catch (AttributeNotFoundException | TimeRangeException e) {
473 Activator.getDefault().logError(e.getMessage());
474 }
475 return eventList;
476 }
477
478 /**
479 * Returns a value corresponding to the selected entry.
480 *
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.
483 *
484 * @param time
485 * The currently selected time
486 * @return a value identifying the entry
487 */
488 private int getSelectionValue(long time) {
489 int thread = -1;
490 for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
491 if (thread > 0) {
492 break;
493 }
494 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
495 if (ssq == null) {
496 continue;
497 }
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) {
501 try {
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;
509 break;
510 }
511 }
512 } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
513 Activator.getDefault().logError(e.getMessage());
514 } catch (StateSystemDisposedException e) {
515 /* Ignored */
516 }
517 }
518 }
519 }
520 return thread;
521 }
522
523 @Override
524 protected void synchingToTime(long time) {
525 int selected = getSelectionValue(time);
526 if (selected > 0) {
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);
532 break;
533 }
534 }
535 }
536 }
537 }
538
539 @Override
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) {
545 return list;
546 }
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 */
552 continue;
553 }
554 List<ITmfStateInterval> currentThreadIntervals = new ArrayList<>(fullStates.size() + 2);
555 try {
556 /*
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.
562 */
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));
568 }
569 }
570 for (List<ITmfStateInterval> fullState : fullStates) {
571 currentThreadIntervals.add(fullState.get(currentThreadQuark));
572 }
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));
577 }
578 } catch (AttributeNotFoundException e) {
579 Activator.getDefault().logError(e.getMessage());
580 return list;
581 } catch (StateSystemDisposedException e) {
582 /* Ignored */
583 return list;
584 }
585 int prevThread = 0;
586 long prevEnd = 0;
587 long lastEnd = 0;
588 for (ITmfStateInterval currentThreadInterval : currentThreadIntervals) {
589 if (monitor.isCanceled()) {
590 return list;
591 }
592 if (currentThreadInterval.getEndTime() + 1 == lastEnd) {
593 continue;
594 }
595 long time = currentThreadInterval.getStartTime();
596 if (time != lastEnd) {
597 // don't create links where there are gaps in intervals due to the resolution
598 prevThread = 0;
599 prevEnd = 0;
600 }
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));
606 }
607 lastEnd = currentThreadInterval.getEndTime() + 1;
608 if (thread != 0) {
609 prevThread = thread;
610 prevEnd = lastEnd;
611 }
612 }
613 }
614 }
615 return list;
616 }
617
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;
628 }
629 }
630 }
631 }
632 return null;
633 }
634 }
This page took 0.061981 seconds and 5 git commands to generate.