TMF: Add some @NonNull annotations to the AbstractTimeGraphView
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.ui / src / org / eclipse / tracecompass / internal / lttng2 / kernel / ui / views / controlflow / ControlFlowView.java
CommitLineData
6151d86c 1/*******************************************************************************
1cf25311 2 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
6151d86c
PT
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
4999a196 11 * Geneviève Bastien - Move code to provide base classes for time graph view
6151d86c
PT
12 *******************************************************************************/
13
9bc60be7 14package org.eclipse.tracecompass.internal.lttng2.kernel.ui.views.controlflow;
6151d86c
PT
15
16import java.util.ArrayList;
6151d86c 17import java.util.Comparator;
1cf25311 18import java.util.HashMap;
6151d86c 19import java.util.List;
1cf25311 20import java.util.Map;
6151d86c
PT
21
22import org.eclipse.core.runtime.IProgressMonitor;
dfa0ef96 23import org.eclipse.jdt.annotation.NonNull;
d2120fb6 24import org.eclipse.jdt.annotation.Nullable;
03ab8eeb 25import org.eclipse.jface.action.IAction;
79ec0b89
PT
26import org.eclipse.jface.action.IToolBarManager;
27import org.eclipse.jface.dialogs.IDialogSettings;
9bc60be7
AM
28import org.eclipse.tracecompass.internal.lttng2.kernel.core.Attributes;
29import org.eclipse.tracecompass.internal.lttng2.kernel.ui.Activator;
30import org.eclipse.tracecompass.internal.lttng2.kernel.ui.Messages;
42d5b5f2 31import org.eclipse.tracecompass.lttng2.kernel.core.analysis.kernel.LttngKernelAnalysis;
e894a508 32import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
1dd75589 33import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
e894a508
AM
34import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
35import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
36import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
37import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
38import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
39import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
2bdf0193
AM
40import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
41import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
42import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
43import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
44import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
45import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
46import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
47import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
48import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
49import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent;
50import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
51import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
52import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
6151d86c
PT
53
54/**
55 * The Control Flow view main object
56 *
57 */
4999a196 58public class ControlFlowView extends AbstractTimeGraphView {
6151d86c
PT
59
60 // ------------------------------------------------------------------------
61 // Constants
62 // ------------------------------------------------------------------------
63
64 /**
65 * View ID.
66 */
67 public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$
68
4999a196
GB
69 private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;
70 private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn;
71 private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn;
6151d86c 72 private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn;
4999a196 73 private static final String TRACE_COLUMN = Messages.ControlFlowView_traceColumn;
6151d86c 74
4999a196 75 private static final String[] COLUMN_NAMES = new String[] {
6151d86c
PT
76 PROCESS_COLUMN,
77 TID_COLUMN,
78 PTID_COLUMN,
79 BIRTH_TIME_COLUMN,
80 TRACE_COLUMN
81 };
82
4999a196 83 private static final String[] FILTER_COLUMN_NAMES = new String[] {
6ac5a950
AM
84 PROCESS_COLUMN,
85 TID_COLUMN
86 };
87
aae89862
PT
88 // Timeout between updates in the build thread in ms
89 private static final long BUILD_UPDATE_TIMEOUT = 500;
90
6151d86c 91 // ------------------------------------------------------------------------
4999a196 92 // Constructors
6151d86c
PT
93 // ------------------------------------------------------------------------
94
4999a196
GB
95 /**
96 * Constructor
97 */
98 public ControlFlowView() {
747adf5c
PT
99 super(ID, new ControlFlowPresentationProvider());
100 setTreeColumns(COLUMN_NAMES);
4999a196 101 setTreeLabelProvider(new ControlFlowTreeLabelProvider());
747adf5c 102 setFilterColumns(FILTER_COLUMN_NAMES);
a03b7ee4 103 setFilterLabelProvider(new ControlFlowFilterLabelProvider());
4999a196 104 setEntryComparator(new ControlFlowEntryComparator());
6151d86c
PT
105 }
106
79ec0b89
PT
107 @Override
108 protected void fillLocalToolBar(IToolBarManager manager) {
086f21ae 109 super.fillLocalToolBar(manager);
79ec0b89
PT
110 IDialogSettings settings = Activator.getDefault().getDialogSettings();
111 IDialogSettings section = settings.getSection(getClass().getName());
112 if (section == null) {
113 section = settings.addNewSection(getClass().getName());
114 }
03ab8eeb
PT
115
116 IAction hideArrowsAction = getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section);
117 manager.add(hideArrowsAction);
118
119 IAction followArrowBwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction();
120 followArrowBwdAction.setText(Messages.ControlFlowView_followCPUBwdText);
121 followArrowBwdAction.setToolTipText(Messages.ControlFlowView_followCPUBwdText);
122 manager.add(followArrowBwdAction);
123
124 IAction followArrowFwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction();
125 followArrowFwdAction.setText(Messages.ControlFlowView_followCPUFwdText);
126 followArrowFwdAction.setToolTipText(Messages.ControlFlowView_followCPUFwdText);
127 manager.add(followArrowFwdAction);
79ec0b89
PT
128 }
129
4999a196
GB
130 @Override
131 protected String getNextText() {
132 return Messages.ControlFlowView_nextProcessActionNameText;
133 }
6151d86c 134
4999a196
GB
135 @Override
136 protected String getNextTooltip() {
137 return Messages.ControlFlowView_nextProcessActionToolTipText;
138 }
6151d86c 139
4999a196
GB
140 @Override
141 protected String getPrevText() {
142 return Messages.ControlFlowView_previousProcessActionNameText;
143 }
6151d86c 144
4999a196
GB
145 @Override
146 protected String getPrevTooltip() {
147 return Messages.ControlFlowView_previousProcessActionToolTipText;
6151d86c
PT
148 }
149
150 private static class ControlFlowEntryComparator implements Comparator<ITimeGraphEntry> {
151
152 @Override
153 public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
4999a196 154
6151d86c
PT
155 int result = 0;
156
157 if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {
158 ControlFlowEntry entry1 = (ControlFlowEntry) o1;
159 ControlFlowEntry entry2 = (ControlFlowEntry) o2;
160 result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());
161 if (result == 0) {
162 result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());
163 }
164 if (result == 0) {
165 result = entry1.getThreadId() < entry2.getThreadId() ? -1 : entry1.getThreadId() > entry2.getThreadId() ? 1 : 0;
166 }
167 }
168
169 if (result == 0) {
170 result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
171 }
172
173 return result;
174 }
175 }
176
6151d86c 177 /**
4999a196 178 * @author gbastien
6151d86c 179 *
6151d86c 180 */
4999a196 181 protected static class ControlFlowTreeLabelProvider extends TreeLabelProvider {
6151d86c 182
4999a196
GB
183 @Override
184 public String getColumnText(Object element, int columnIndex) {
185 ControlFlowEntry entry = (ControlFlowEntry) element;
6151d86c 186
4999a196
GB
187 if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_processColumn)) {
188 return entry.getName();
189 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_tidColumn)) {
190 return Integer.toString(entry.getThreadId());
191 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_ptidColumn)) {
192 if (entry.getParentThreadId() > 0) {
193 return Integer.toString(entry.getParentThreadId());
6151d86c 194 }
4999a196
GB
195 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_birthTimeColumn)) {
196 return Utils.formatTime(entry.getStartTime(), TimeFormat.CALENDAR, Resolution.NANOSEC);
197 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_traceColumn)) {
198 return entry.getTrace().getName();
6151d86c 199 }
4999a196 200 return ""; //$NON-NLS-1$
6151d86c 201 }
6151d86c 202
6151d86c
PT
203 }
204
a03b7ee4
PT
205 private static class ControlFlowFilterLabelProvider extends TreeLabelProvider {
206
207 @Override
208 public String getColumnText(Object element, int columnIndex) {
209 ControlFlowEntry entry = (ControlFlowEntry) element;
210
211 if (columnIndex == 0) {
212 return entry.getName();
213 } else if (columnIndex == 1) {
214 return Integer.toString(entry.getThreadId());
215 }
216 return ""; //$NON-NLS-1$
217 }
218
219 }
220
6151d86c
PT
221 // ------------------------------------------------------------------------
222 // Internal
223 // ------------------------------------------------------------------------
224
4999a196 225 @Override
1cf25311 226 protected void buildEventList(final ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
42d5b5f2 227 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysis.ID);
1cf25311
PT
228 if (ssq == null) {
229 return;
230 }
fec1ac0b 231
1cf25311
PT
232 List<ControlFlowEntry> entryList = new ArrayList<>();
233 Map<Integer, ControlFlowEntry> entryMap = new HashMap<>();
234
235 long start = ssq.getStartTime();
236 setStartTime(Math.min(getStartTime(), start));
237
238 boolean complete = false;
239 while (!complete) {
faa38350
PT
240 if (monitor.isCanceled()) {
241 return;
242 }
aae89862 243 complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
1cf25311
PT
244 if (ssq.isCancelled()) {
245 return;
246 }
247 long end = ssq.getCurrentEndTime();
248 if (start == end && !complete) { // when complete execute one last time regardless of end time
249 continue;
250 }
251 setEndTime(Math.max(getEndTime(), end + 1));
252 List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$
253 for (int threadQuark : threadQuarks) {
254 if (monitor.isCanceled()) {
255 return;
4bc53929 256 }
1cf25311
PT
257 String threadName = ssq.getAttributeName(threadQuark);
258 int threadId = -1;
259 try {
260 threadId = Integer.parseInt(threadName);
261 } catch (NumberFormatException e1) {
4bc53929 262 continue;
2002c638 263 }
1cf25311 264 if (threadId <= 0) { // ignore the 'unknown' (-1) and swapper (0) threads
4bc53929 265 continue;
faa38350 266 }
1c471b9e
AM
267
268 int execNameQuark;
269 List<ITmfStateInterval> execNameIntervals;
1cf25311 270 try {
1c471b9e 271 execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME);
1dd75589 272 execNameIntervals = StateSystemUtils.queryHistoryRange(ssq, execNameQuark, start, end);
1c471b9e
AM
273 } catch (AttributeNotFoundException e) {
274 /* No information on this thread (yet?), skip it for now */
275 continue;
276 } catch (StateSystemDisposedException e) {
277 /* State system is closing down, no point continuing */
278 break;
279 }
280
281 for (ITmfStateInterval execNameInterval : execNameIntervals) {
282 if (monitor.isCanceled()) {
283 return;
284 }
285 ControlFlowEntry entry = entryMap.get(threadId);
286 if (!execNameInterval.getStateValue().isNull() &&
287 execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) {
288 String execName = execNameInterval.getStateValue().unboxStr();
289 long startTime = execNameInterval.getStartTime();
290 long endTime = execNameInterval.getEndTime() + 1;
0a35a36f 291
1c471b9e
AM
292 if (entry == null) {
293 ITmfStateInterval ppidInterval = null;
294 try {
1cf25311 295 int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID);
0a35a36f 296 ppidInterval = StateSystemUtils.queryUntilNonNullValue(ssq, ppidQuark, startTime, endTime);
1c471b9e
AM
297 } catch (AttributeNotFoundException e) {
298 /* No info, keep PPID at -1 */
6151d86c 299 }
0a35a36f 300
1c471b9e 301 int ppid = -1;
0a35a36f 302 if (ppidInterval != null) {
1c471b9e
AM
303 ppid = ppidInterval.getStateValue().unboxInt();
304 }
305 entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
306 entryList.add(entry);
307 entryMap.put(threadId, entry);
1cf25311 308 } else {
1c471b9e
AM
309 // update the name of the entry to the latest
310 // execName
311 entry.setName(execName);
312 entry.updateEndTime(endTime);
6151d86c 313 }
1c471b9e
AM
314 } else {
315 entryMap.remove(threadId);
6151d86c
PT
316 }
317 }
6151d86c 318 }
4999a196 319
1cf25311
PT
320 updateTree(entryList, parentTrace);
321
322 if (parentTrace.equals(getTrace())) {
d7ee91bb 323 refresh();
6151d86c 324 }
1cf25311
PT
325
326 for (ControlFlowEntry entry : entryList) {
327 if (monitor.isCanceled()) {
328 return;
329 }
330 buildStatusEvents(entry.getTrace(), entry, monitor, start, end);
faa38350 331 }
1cf25311
PT
332
333 start = end;
6151d86c
PT
334 }
335 }
336
1cf25311
PT
337 private void updateTree(List<ControlFlowEntry> entryList, ITmfTrace parentTrace) {
338 List<TimeGraphEntry> rootListToAdd = new ArrayList<>();
339 List<TimeGraphEntry> rootListToRemove = new ArrayList<>();
340 List<TimeGraphEntry> rootList = getEntryList(parentTrace);
341
1d46dc38 342 for (ControlFlowEntry entry : entryList) {
1cf25311
PT
343 boolean root = (entry.getParent() == null);
344 if (root && entry.getParentThreadId() > 0) {
1d46dc38 345 for (ControlFlowEntry parent : entryList) {
0a35a36f
GB
346 /*
347 * Associate the parent entry only if their time overlap. A
348 * child entry may start before its parent, for example at
349 * the beginning of the trace if a parent has not yet
350 * appeared in the state system. We just want to make sure
351 * that the entry didn't start after the parent ended or
352 * ended before the parent started.
353 */
6151d86c 354 if (parent.getThreadId() == entry.getParentThreadId() &&
0a35a36f
GB
355 !(entry.getStartTime() > parent.getEndTime() ||
356 entry.getEndTime() < parent.getStartTime())) {
6151d86c
PT
357 parent.addChild(entry);
358 root = false;
1cf25311
PT
359 if (rootList != null && rootList.contains(entry)) {
360 rootListToRemove.add(entry);
361 }
6151d86c
PT
362 break;
363 }
364 }
365 }
1cf25311
PT
366 if (root && (rootList == null || !rootList.contains(entry))) {
367 rootListToAdd.add(entry);
6151d86c
PT
368 }
369 }
1cf25311
PT
370
371 addToEntryList(parentTrace, rootListToAdd);
372 removeFromEntryList(parentTrace, rootListToRemove);
6151d86c
PT
373 }
374
dfa0ef96 375 private void buildStatusEvents(ITmfTrace trace, ControlFlowEntry entry, @NonNull IProgressMonitor monitor, long start, long end) {
1cf25311 376 if (start < entry.getEndTime() && end > entry.getStartTime()) {
42d5b5f2 377 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(entry.getTrace(), LttngKernelAnalysis.ID);
1cf25311
PT
378 if (ssq == null) {
379 return;
380 }
381
382 long startTime = Math.max(start, entry.getStartTime());
383 long endTime = Math.min(end + 1, entry.getEndTime());
384 long resolution = Math.max(1, (end - ssq.getStartTime()) / getDisplayWidth());
385 List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor);
d2120fb6 386 if (eventList == null) {
1cf25311
PT
387 return;
388 }
389 for (ITimeEvent event : eventList) {
390 entry.addEvent(event);
391 }
392 if (trace.equals(getTrace())) {
393 redraw();
394 }
faa38350 395 }
6151d86c 396 for (ITimeGraphEntry child : entry.getChildren()) {
faa38350
PT
397 if (monitor.isCanceled()) {
398 return;
399 }
1cf25311 400 buildStatusEvents(trace, (ControlFlowEntry) child, monitor, start, end);
6151d86c
PT
401 }
402 }
403
4999a196 404 @Override
d2120fb6 405 protected @Nullable List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
4999a196
GB
406 List<ITimeEvent> eventList = null;
407 if (!(tgentry instanceof ControlFlowEntry)) {
408 return eventList;
409 }
410 ControlFlowEntry entry = (ControlFlowEntry) tgentry;
41b5c37f
AM
411 final long realStart = Math.max(startTime, entry.getStartTime());
412 final long realEnd = Math.min(endTime, entry.getEndTime());
413 if (realEnd <= realStart) {
6151d86c
PT
414 return null;
415 }
42d5b5f2 416 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(entry.getTrace(), LttngKernelAnalysis.ID);
4bc53929
GB
417 if (ssq == null) {
418 return null;
419 }
6151d86c
PT
420 try {
421 int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);
1dd75589 422 List<ITmfStateInterval> statusIntervals = StateSystemUtils.queryHistoryRange(ssq, statusQuark, realStart, realEnd - 1, resolution, monitor);
e0838ca1 423 eventList = new ArrayList<>(statusIntervals.size());
6151d86c
PT
424 long lastEndTime = -1;
425 for (ITmfStateInterval statusInterval : statusIntervals) {
426 if (monitor.isCanceled()) {
427 return null;
428 }
429 long time = statusInterval.getStartTime();
430 long duration = statusInterval.getEndTime() - time + 1;
431 int status = -1;
432 try {
433 status = statusInterval.getStateValue().unboxInt();
434 } catch (StateValueTypeException e) {
435 e.printStackTrace();
436 }
437 if (lastEndTime != time && lastEndTime != -1) {
af10fe06 438 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
6151d86c 439 }
4999a196 440 eventList.add(new TimeEvent(entry, time, duration, status));
6151d86c
PT
441 lastEndTime = time + duration;
442 }
1cf25311 443 } catch (AttributeNotFoundException | TimeRangeException e) {
6151d86c 444 e.printStackTrace();
96345c5a
AM
445 } catch (StateSystemDisposedException e) {
446 /* Ignored */
6151d86c
PT
447 }
448 return eventList;
449 }
450
4999a196
GB
451 /**
452 * Returns a value corresponding to the selected entry.
453 *
1cf25311
PT
454 * Used in conjunction with synchingToTime to change the selected entry. If
455 * one of these methods is overridden in child class, then both should be.
4999a196
GB
456 *
457 * @param time
458 * The currently selected time
459 * @return a value identifying the entry
460 */
461 private int getSelectionValue(long time) {
462 int thread = -1;
1cf25311
PT
463 ITmfTrace[] traces = TmfTraceManager.getTraceSet(getTrace());
464 if (traces == null) {
465 return thread;
466 }
467 for (ITmfTrace trace : traces) {
4999a196
GB
468 if (thread > 0) {
469 break;
470 }
72221aa4 471 if (trace == null) {
1cf25311
PT
472 continue;
473 }
42d5b5f2 474 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysis.ID);
1cf25311
PT
475 if (ssq == null) {
476 continue;
477 }
478 if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) {
479 List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$
480 for (int currentThreadQuark : currentThreadQuarks) {
481 try {
482 ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark);
483 int currentThread = currentThreadInterval.getStateValue().unboxInt();
484 if (currentThread > 0) {
485 int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread), Attributes.STATUS);
486 ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark);
487 if (statusInterval.getStartTime() == time) {
488 thread = currentThread;
489 break;
4999a196 490 }
4999a196 491 }
1cf25311
PT
492 } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
493 e.printStackTrace();
494 } catch (StateSystemDisposedException e) {
495 /* Ignored */
faa38350 496 }
6151d86c 497 }
6151d86c 498 }
4999a196
GB
499 }
500 return thread;
6151d86c
PT
501 }
502
4999a196
GB
503 @Override
504 protected void synchingToTime(long time) {
505 int selected = getSelectionValue(time);
506 if (selected > 0) {
747adf5c 507 for (Object element : getTimeGraphViewer().getExpandedElements()) {
4999a196
GB
508 if (element instanceof ControlFlowEntry) {
509 ControlFlowEntry entry = (ControlFlowEntry) element;
510 if (entry.getThreadId() == selected) {
511 getTimeGraphCombo().setSelection(entry);
512 break;
6151d86c
PT
513 }
514 }
515 }
6151d86c 516 }
6151d86c 517 }
79ec0b89
PT
518
519 @Override
520 protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) {
e0838ca1 521 List<ILinkEvent> list = new ArrayList<>();
79ec0b89 522 ITmfTrace[] traces = TmfTraceManager.getTraceSet(getTrace());
1cf25311 523 List<TimeGraphEntry> entryList = getEntryList(getTrace());
79ec0b89
PT
524 if (traces == null || entryList == null) {
525 return list;
526 }
527 for (ITmfTrace trace : traces) {
72221aa4 528 if (trace == null) {
1cf25311
PT
529 continue;
530 }
42d5b5f2 531 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysis.ID);
1cf25311
PT
532 if (ssq == null) {
533 continue;
534 }
535 try {
536 long start = Math.max(startTime, ssq.getStartTime());
537 long end = Math.min(endTime, ssq.getCurrentEndTime());
538 if (end < start) {
4bc53929
GB
539 continue;
540 }
1cf25311
PT
541 List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$
542 for (int currentThreadQuark : currentThreadQuarks) {
543 // adjust the query range to include the previous and following intervals
544 long qstart = Math.max(ssq.querySingleState(start, currentThreadQuark).getStartTime() - 1, ssq.getStartTime());
545 long qend = Math.min(ssq.querySingleState(end, currentThreadQuark).getEndTime() + 1, ssq.getCurrentEndTime());
1dd75589 546 List<ITmfStateInterval> currentThreadIntervals = StateSystemUtils.queryHistoryRange(ssq, currentThreadQuark, qstart, qend, resolution, monitor);
1cf25311
PT
547 int prevThread = 0;
548 long prevEnd = 0;
549 long lastEnd = 0;
550 for (ITmfStateInterval currentThreadInterval : currentThreadIntervals) {
551 if (monitor.isCanceled()) {
552 return null;
553 }
554 long time = currentThreadInterval.getStartTime();
555 if (time != lastEnd) {
556 // don't create links where there are gaps in intervals due to the resolution
557 prevThread = 0;
558 prevEnd = 0;
559 }
560 int thread = currentThreadInterval.getStateValue().unboxInt();
561 if (thread > 0 && prevThread > 0) {
562 ITimeGraphEntry prevEntry = findEntry(entryList, trace, prevThread);
563 ITimeGraphEntry nextEntry = findEntry(entryList, trace, thread);
564 list.add(new TimeLinkEvent(prevEntry, nextEntry, prevEnd, time - prevEnd, 0));
565 }
566 lastEnd = currentThreadInterval.getEndTime() + 1;
567 if (thread != 0) {
568 prevThread = thread;
569 prevEnd = lastEnd;
79ec0b89
PT
570 }
571 }
79ec0b89 572 }
1cf25311
PT
573 } catch (TimeRangeException | AttributeNotFoundException | StateValueTypeException e) {
574 e.printStackTrace();
575 } catch (StateSystemDisposedException e) {
576 /* Ignored */
79ec0b89
PT
577 }
578 }
579 return list;
580 }
581
a3188982
PT
582 private ControlFlowEntry findEntry(List<? extends ITimeGraphEntry> entryList, ITmfTrace trace, int threadId) {
583 for (ITimeGraphEntry entry : entryList) {
79ec0b89
PT
584 if (entry instanceof ControlFlowEntry) {
585 ControlFlowEntry controlFlowEntry = (ControlFlowEntry) entry;
586 if (controlFlowEntry.getThreadId() == threadId && controlFlowEntry.getTrace() == trace) {
587 return controlFlowEntry;
588 } else if (entry.hasChildren()) {
589 controlFlowEntry = findEntry(entry.getChildren(), trace, threadId);
590 if (controlFlowEntry != null) {
591 return controlFlowEntry;
592 }
593 }
594 }
595 }
596 return null;
597 }
6151d86c 598}
This page took 0.084018 seconds and 5 git commands to generate.