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