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