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