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