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