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