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