Commit | Line | Data |
---|---|---|
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 | ||
14 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow; | |
15 | ||
16 | import java.util.ArrayList; | |
6151d86c PT |
17 | import java.util.Collections; |
18 | import java.util.Comparator; | |
19 | import java.util.List; | |
20 | ||
21 | import org.eclipse.core.runtime.IProgressMonitor; | |
79ec0b89 PT |
22 | import org.eclipse.jface.action.IToolBarManager; |
23 | import org.eclipse.jface.dialogs.IDialogSettings; | |
6151d86c | 24 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; |
79ec0b89 | 25 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Activator; |
6151d86c | 26 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages; |
d3ba47d4 | 27 | import org.eclipse.linuxtools.lttng2.kernel.core.trace.LttngKernelTrace; |
6151d86c | 28 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; |
96345c5a | 29 | import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; |
6151d86c PT |
30 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; |
31 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
32 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; | |
f1f86dfb | 33 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
b67a2540 | 34 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
6151d86c | 35 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
79ec0b89 | 36 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; |
4999a196 | 37 | import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView; |
79ec0b89 | 38 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent; |
6151d86c PT |
39 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; |
40 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
41 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; | |
4999a196 | 42 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry; |
79ec0b89 | 43 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeLinkEvent; |
6151d86c PT |
44 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; |
45 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; | |
46 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; | |
6151d86c PT |
47 | |
48 | /** | |
49 | * The Control Flow view main object | |
50 | * | |
51 | */ | |
4999a196 | 52 | public class ControlFlowView extends AbstractTimeGraphView { |
6151d86c PT |
53 | |
54 | // ------------------------------------------------------------------------ | |
55 | // Constants | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | /** | |
59 | * View ID. | |
60 | */ | |
61 | public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$ | |
62 | ||
4999a196 GB |
63 | private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn; |
64 | private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn; | |
65 | private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn; | |
6151d86c | 66 | private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn; |
4999a196 | 67 | private static final String TRACE_COLUMN = Messages.ControlFlowView_traceColumn; |
6151d86c | 68 | |
4999a196 | 69 | private static final String[] COLUMN_NAMES = new String[] { |
6151d86c PT |
70 | PROCESS_COLUMN, |
71 | TID_COLUMN, | |
72 | PTID_COLUMN, | |
73 | BIRTH_TIME_COLUMN, | |
74 | TRACE_COLUMN | |
75 | }; | |
76 | ||
4999a196 | 77 | private static final String[] FILTER_COLUMN_NAMES = new String[] { |
6ac5a950 AM |
78 | PROCESS_COLUMN, |
79 | TID_COLUMN | |
80 | }; | |
81 | ||
6151d86c | 82 | // ------------------------------------------------------------------------ |
4999a196 | 83 | // Constructors |
6151d86c PT |
84 | // ------------------------------------------------------------------------ |
85 | ||
4999a196 GB |
86 | /** |
87 | * Constructor | |
88 | */ | |
89 | public ControlFlowView() { | |
747adf5c PT |
90 | super(ID, new ControlFlowPresentationProvider()); |
91 | setTreeColumns(COLUMN_NAMES); | |
4999a196 | 92 | setTreeLabelProvider(new ControlFlowTreeLabelProvider()); |
747adf5c | 93 | setFilterColumns(FILTER_COLUMN_NAMES); |
4999a196 | 94 | setEntryComparator(new ControlFlowEntryComparator()); |
6151d86c PT |
95 | } |
96 | ||
79ec0b89 PT |
97 | @Override |
98 | protected void fillLocalToolBar(IToolBarManager manager) { | |
086f21ae | 99 | super.fillLocalToolBar(manager); |
79ec0b89 PT |
100 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); |
101 | IDialogSettings section = settings.getSection(getClass().getName()); | |
102 | if (section == null) { | |
103 | section = settings.addNewSection(getClass().getName()); | |
104 | } | |
105 | manager.add(getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section)); | |
086f21ae PT |
106 | manager.add(getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction()); |
107 | manager.add(getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction()); | |
79ec0b89 PT |
108 | } |
109 | ||
4999a196 GB |
110 | @Override |
111 | protected String getNextText() { | |
112 | return Messages.ControlFlowView_nextProcessActionNameText; | |
113 | } | |
6151d86c | 114 | |
4999a196 GB |
115 | @Override |
116 | protected String getNextTooltip() { | |
117 | return Messages.ControlFlowView_nextProcessActionToolTipText; | |
118 | } | |
6151d86c | 119 | |
4999a196 GB |
120 | @Override |
121 | protected String getPrevText() { | |
122 | return Messages.ControlFlowView_previousProcessActionNameText; | |
123 | } | |
6151d86c | 124 | |
4999a196 GB |
125 | @Override |
126 | protected String getPrevTooltip() { | |
127 | return Messages.ControlFlowView_previousProcessActionToolTipText; | |
6151d86c PT |
128 | } |
129 | ||
130 | private static class ControlFlowEntryComparator implements Comparator<ITimeGraphEntry> { | |
131 | ||
132 | @Override | |
133 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) { | |
4999a196 | 134 | |
6151d86c PT |
135 | int result = 0; |
136 | ||
137 | if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) { | |
138 | ControlFlowEntry entry1 = (ControlFlowEntry) o1; | |
139 | ControlFlowEntry entry2 = (ControlFlowEntry) o2; | |
140 | result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime()); | |
141 | if (result == 0) { | |
142 | result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName()); | |
143 | } | |
144 | if (result == 0) { | |
145 | result = entry1.getThreadId() < entry2.getThreadId() ? -1 : entry1.getThreadId() > entry2.getThreadId() ? 1 : 0; | |
146 | } | |
147 | } | |
148 | ||
149 | if (result == 0) { | |
150 | result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0; | |
151 | } | |
152 | ||
153 | return result; | |
154 | } | |
155 | } | |
156 | ||
6151d86c | 157 | /** |
4999a196 | 158 | * @author gbastien |
6151d86c | 159 | * |
6151d86c | 160 | */ |
4999a196 | 161 | protected static class ControlFlowTreeLabelProvider extends TreeLabelProvider { |
6151d86c | 162 | |
4999a196 GB |
163 | @Override |
164 | public String getColumnText(Object element, int columnIndex) { | |
165 | ControlFlowEntry entry = (ControlFlowEntry) element; | |
6151d86c | 166 | |
4999a196 GB |
167 | if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_processColumn)) { |
168 | return entry.getName(); | |
169 | } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_tidColumn)) { | |
170 | return Integer.toString(entry.getThreadId()); | |
171 | } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_ptidColumn)) { | |
172 | if (entry.getParentThreadId() > 0) { | |
173 | return Integer.toString(entry.getParentThreadId()); | |
6151d86c | 174 | } |
4999a196 GB |
175 | } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_birthTimeColumn)) { |
176 | return Utils.formatTime(entry.getStartTime(), TimeFormat.CALENDAR, Resolution.NANOSEC); | |
177 | } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_traceColumn)) { | |
178 | return entry.getTrace().getName(); | |
6151d86c | 179 | } |
4999a196 | 180 | return ""; //$NON-NLS-1$ |
6151d86c | 181 | } |
6151d86c | 182 | |
6151d86c PT |
183 | } |
184 | ||
6151d86c PT |
185 | // ------------------------------------------------------------------------ |
186 | // Internal | |
187 | // ------------------------------------------------------------------------ | |
188 | ||
4999a196 GB |
189 | @Override |
190 | protected void buildEventList(final ITmfTrace trace, IProgressMonitor monitor) { | |
191 | setStartTime(Long.MAX_VALUE); | |
192 | setEndTime(Long.MIN_VALUE); | |
fec1ac0b | 193 | |
1d46dc38 PT |
194 | ArrayList<ControlFlowEntry> rootList = new ArrayList<ControlFlowEntry>(); |
195 | for (ITmfTrace aTrace : TmfTraceManager.getTraceSet(trace)) { | |
faa38350 PT |
196 | if (monitor.isCanceled()) { |
197 | return; | |
198 | } | |
d3ba47d4 | 199 | if (aTrace instanceof LttngKernelTrace) { |
1d46dc38 | 200 | ArrayList<ControlFlowEntry> entryList = new ArrayList<ControlFlowEntry>(); |
d3ba47d4 AM |
201 | LttngKernelTrace ctfKernelTrace = (LttngKernelTrace) aTrace; |
202 | ITmfStateSystem ssq = ctfKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID); | |
faa38350 PT |
203 | if (!ssq.waitUntilBuilt()) { |
204 | return; | |
205 | } | |
6151d86c PT |
206 | long start = ssq.getStartTime(); |
207 | long end = ssq.getCurrentEndTime() + 1; | |
4999a196 GB |
208 | setStartTime(Math.min(getStartTime(), start)); |
209 | setEndTime(Math.max(getEndTime(), end)); | |
6151d86c PT |
210 | List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$ |
211 | for (int threadQuark : threadQuarks) { | |
faa38350 PT |
212 | if (monitor.isCanceled()) { |
213 | return; | |
214 | } | |
6151d86c PT |
215 | String threadName = ssq.getAttributeName(threadQuark); |
216 | int threadId = -1; | |
217 | try { | |
218 | threadId = Integer.parseInt(threadName); | |
219 | } catch (NumberFormatException e1) { | |
220 | continue; | |
221 | } | |
222 | if (threadId == 0) { // ignore the swapper thread | |
223 | continue; | |
224 | } | |
225 | int execNameQuark = -1; | |
226 | try { | |
227 | try { | |
228 | execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME); | |
229 | } catch (AttributeNotFoundException e) { | |
230 | continue; | |
231 | } | |
232 | int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID); | |
4999a196 GB |
233 | List<ITmfStateInterval> execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end - 1); |
234 | // use monitor when available in api | |
faa38350 PT |
235 | if (monitor.isCanceled()) { |
236 | return; | |
237 | } | |
1d46dc38 | 238 | ControlFlowEntry entry = null; |
6151d86c | 239 | for (ITmfStateInterval execNameInterval : execNameIntervals) { |
faa38350 PT |
240 | if (monitor.isCanceled()) { |
241 | return; | |
242 | } | |
b67a2540 AM |
243 | if (!execNameInterval.getStateValue().isNull() && |
244 | execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) { | |
6151d86c PT |
245 | String execName = execNameInterval.getStateValue().unboxStr(); |
246 | long startTime = execNameInterval.getStartTime(); | |
247 | long endTime = execNameInterval.getEndTime() + 1; | |
6151d86c PT |
248 | int ppid = -1; |
249 | if (ppidQuark != -1) { | |
250 | ITmfStateInterval ppidInterval = ssq.querySingleState(startTime, ppidQuark); | |
251 | ppid = ppidInterval.getStateValue().unboxInt(); | |
252 | } | |
826deb93 PT |
253 | if (entry == null) { |
254 | entry = new ControlFlowEntry(threadQuark, ctfKernelTrace, execName, threadId, ppid, startTime, endTime); | |
255 | entryList.add(entry); | |
256 | } else { | |
4999a196 GB |
257 | // update the name of the entry to the |
258 | // latest execName | |
826deb93 PT |
259 | entry.setName(execName); |
260 | } | |
6151d86c PT |
261 | entry.addEvent(new TimeEvent(entry, startTime, endTime - startTime)); |
262 | } else { | |
826deb93 | 263 | entry = null; |
6151d86c PT |
264 | } |
265 | } | |
266 | } catch (AttributeNotFoundException e) { | |
267 | e.printStackTrace(); | |
268 | } catch (TimeRangeException e) { | |
269 | e.printStackTrace(); | |
270 | } catch (StateValueTypeException e) { | |
271 | e.printStackTrace(); | |
96345c5a AM |
272 | } catch (StateSystemDisposedException e) { |
273 | /* Ignored */ | |
6151d86c PT |
274 | } |
275 | } | |
276 | buildTree(entryList, rootList); | |
277 | } | |
4999a196 | 278 | Collections.sort(rootList, getEntryComparator()); |
2f91d29c | 279 | putEntryList(trace, new ArrayList<TimeGraphEntry>(rootList)); |
4999a196 GB |
280 | |
281 | if (trace.equals(getTrace())) { | |
d7ee91bb | 282 | refresh(); |
6151d86c | 283 | } |
6151d86c | 284 | } |
1d46dc38 | 285 | for (ControlFlowEntry entry : rootList) { |
faa38350 PT |
286 | if (monitor.isCanceled()) { |
287 | return; | |
288 | } | |
1d46dc38 | 289 | buildStatusEvents(entry.getTrace(), entry, monitor); |
6151d86c PT |
290 | } |
291 | } | |
292 | ||
1d46dc38 PT |
293 | private static void buildTree(ArrayList<ControlFlowEntry> entryList, |
294 | ArrayList<ControlFlowEntry> rootList) { | |
295 | for (ControlFlowEntry entry : entryList) { | |
6151d86c PT |
296 | boolean root = true; |
297 | if (entry.getParentThreadId() > 0) { | |
1d46dc38 | 298 | for (ControlFlowEntry parent : entryList) { |
6151d86c PT |
299 | if (parent.getThreadId() == entry.getParentThreadId() && |
300 | entry.getStartTime() >= parent.getStartTime() && | |
301 | entry.getStartTime() <= parent.getEndTime()) { | |
302 | parent.addChild(entry); | |
303 | root = false; | |
304 | break; | |
305 | } | |
306 | } | |
307 | } | |
308 | if (root) { | |
309 | rootList.add(entry); | |
310 | } | |
311 | } | |
312 | } | |
313 | ||
1d46dc38 | 314 | private void buildStatusEvents(ITmfTrace trace, ControlFlowEntry entry, IProgressMonitor monitor) { |
d3ba47d4 | 315 | ITmfStateSystem ssq = entry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID); |
4999a196 | 316 | |
6151d86c PT |
317 | long start = ssq.getStartTime(); |
318 | long end = ssq.getCurrentEndTime() + 1; | |
4999a196 | 319 | long resolution = Math.max(1, (end - start) / getDisplayWidth()); |
faa38350 PT |
320 | List<ITimeEvent> eventList = getEventList(entry, entry.getStartTime(), entry.getEndTime(), resolution, monitor); |
321 | if (monitor.isCanceled()) { | |
322 | return; | |
323 | } | |
6151d86c | 324 | entry.setEventList(eventList); |
4999a196 | 325 | if (trace.equals(getTrace())) { |
faa38350 PT |
326 | redraw(); |
327 | } | |
6151d86c | 328 | for (ITimeGraphEntry child : entry.getChildren()) { |
faa38350 PT |
329 | if (monitor.isCanceled()) { |
330 | return; | |
331 | } | |
1d46dc38 | 332 | buildStatusEvents(trace, (ControlFlowEntry) child, monitor); |
6151d86c PT |
333 | } |
334 | } | |
335 | ||
4999a196 GB |
336 | @Override |
337 | protected List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
338 | List<ITimeEvent> eventList = null; | |
339 | if (!(tgentry instanceof ControlFlowEntry)) { | |
340 | return eventList; | |
341 | } | |
342 | ControlFlowEntry entry = (ControlFlowEntry) tgentry; | |
41b5c37f AM |
343 | final long realStart = Math.max(startTime, entry.getStartTime()); |
344 | final long realEnd = Math.min(endTime, entry.getEndTime()); | |
345 | if (realEnd <= realStart) { | |
6151d86c PT |
346 | return null; |
347 | } | |
d3ba47d4 | 348 | ITmfStateSystem ssq = entry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID); |
6151d86c PT |
349 | try { |
350 | int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS); | |
41b5c37f | 351 | List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor); |
6151d86c PT |
352 | eventList = new ArrayList<ITimeEvent>(statusIntervals.size()); |
353 | long lastEndTime = -1; | |
354 | for (ITmfStateInterval statusInterval : statusIntervals) { | |
355 | if (monitor.isCanceled()) { | |
356 | return null; | |
357 | } | |
358 | long time = statusInterval.getStartTime(); | |
359 | long duration = statusInterval.getEndTime() - time + 1; | |
360 | int status = -1; | |
361 | try { | |
362 | status = statusInterval.getStateValue().unboxInt(); | |
363 | } catch (StateValueTypeException e) { | |
364 | e.printStackTrace(); | |
365 | } | |
366 | if (lastEndTime != time && lastEndTime != -1) { | |
af10fe06 | 367 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime)); |
6151d86c | 368 | } |
4999a196 | 369 | eventList.add(new TimeEvent(entry, time, duration, status)); |
6151d86c PT |
370 | lastEndTime = time + duration; |
371 | } | |
372 | } catch (AttributeNotFoundException e) { | |
373 | e.printStackTrace(); | |
374 | } catch (TimeRangeException e) { | |
375 | e.printStackTrace(); | |
96345c5a AM |
376 | } catch (StateSystemDisposedException e) { |
377 | /* Ignored */ | |
6151d86c PT |
378 | } |
379 | return eventList; | |
380 | } | |
381 | ||
4999a196 GB |
382 | /** |
383 | * Returns a value corresponding to the selected entry. | |
384 | * | |
385 | * Used in conjunction with selectEntry to change the selected entry. If one | |
386 | * of these methods is overridden in child class, then both should be. | |
387 | * | |
388 | * @param time | |
389 | * The currently selected time | |
390 | * @return a value identifying the entry | |
391 | */ | |
392 | private int getSelectionValue(long time) { | |
393 | int thread = -1; | |
394 | for (ITmfTrace trace : fTraceManager.getActiveTraceSet()) { | |
395 | if (thread > 0) { | |
396 | break; | |
397 | } | |
398 | if (trace instanceof LttngKernelTrace) { | |
399 | LttngKernelTrace ctfKernelTrace = (LttngKernelTrace) trace; | |
400 | ITmfStateSystem ssq = ctfKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID); | |
401 | if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) { | |
402 | List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$ | |
403 | for (int currentThreadQuark : currentThreadQuarks) { | |
404 | try { | |
405 | ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark); | |
406 | int currentThread = currentThreadInterval.getStateValue().unboxInt(); | |
407 | if (currentThread > 0) { | |
408 | int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread), Attributes.STATUS); | |
409 | ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark); | |
410 | if (statusInterval.getStartTime() == time) { | |
411 | thread = currentThread; | |
412 | break; | |
413 | } | |
414 | } | |
415 | } catch (AttributeNotFoundException e) { | |
416 | e.printStackTrace(); | |
417 | } catch (TimeRangeException e) { | |
418 | e.printStackTrace(); | |
419 | } catch (StateValueTypeException e) { | |
420 | e.printStackTrace(); | |
421 | } catch (StateSystemDisposedException e) { | |
422 | /* Ignored */ | |
423 | } | |
faa38350 | 424 | } |
6151d86c | 425 | } |
6151d86c | 426 | } |
4999a196 GB |
427 | } |
428 | return thread; | |
6151d86c PT |
429 | } |
430 | ||
4999a196 GB |
431 | @Override |
432 | protected void synchingToTime(long time) { | |
433 | int selected = getSelectionValue(time); | |
434 | if (selected > 0) { | |
747adf5c | 435 | for (Object element : getTimeGraphViewer().getExpandedElements()) { |
4999a196 GB |
436 | if (element instanceof ControlFlowEntry) { |
437 | ControlFlowEntry entry = (ControlFlowEntry) element; | |
438 | if (entry.getThreadId() == selected) { | |
439 | getTimeGraphCombo().setSelection(entry); | |
440 | break; | |
6151d86c PT |
441 | } |
442 | } | |
443 | } | |
6151d86c | 444 | } |
6151d86c | 445 | } |
79ec0b89 PT |
446 | |
447 | @Override | |
448 | protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
449 | List<ILinkEvent> list = new ArrayList<ILinkEvent>(); | |
450 | ITmfTrace[] traces = TmfTraceManager.getTraceSet(getTrace()); | |
451 | List<TimeGraphEntry> entryList = getEntryListMap().get(getTrace()); | |
452 | if (traces == null || entryList == null) { | |
453 | return list; | |
454 | } | |
455 | for (ITmfTrace trace : traces) { | |
456 | if (trace instanceof LttngKernelTrace) { | |
457 | ITmfStateSystem ssq = trace.getStateSystems().get(LttngKernelTrace.STATE_ID); | |
458 | try { | |
459 | long start = Math.max(startTime, ssq.getStartTime()); | |
460 | long end = Math.min(endTime, ssq.getCurrentEndTime()); | |
461 | if (end < start) { | |
462 | continue; | |
463 | } | |
464 | List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$ | |
465 | for (int currentThreadQuark : currentThreadQuarks) { | |
466 | List<ITmfStateInterval> currentThreadIntervals = ssq.queryHistoryRange(currentThreadQuark, start, end, resolution, monitor); | |
467 | int prevThread = 0; | |
468 | long prevEnd = 0; | |
469 | for (ITmfStateInterval currentThreadInterval : currentThreadIntervals) { | |
470 | if (monitor.isCanceled()) { | |
471 | return null; | |
472 | } | |
473 | long time = currentThreadInterval.getStartTime(); | |
474 | int thread = currentThreadInterval.getStateValue().unboxInt(); | |
475 | if (thread > 0 && prevThread > 0 && thread != prevThread && time == prevEnd) { | |
476 | ITimeGraphEntry prevEntry = findEntry(entryList, trace, prevThread); | |
477 | ITimeGraphEntry nextEntry = findEntry(entryList, trace, thread); | |
478 | list.add(new TimeLinkEvent(prevEntry, nextEntry, time, 0, 0)); | |
479 | } | |
480 | prevThread = thread; | |
481 | prevEnd = currentThreadInterval.getEndTime() + 1; | |
482 | } | |
483 | } | |
484 | } catch (TimeRangeException e) { | |
485 | e.printStackTrace(); | |
486 | } catch (AttributeNotFoundException e) { | |
487 | e.printStackTrace(); | |
488 | } catch (StateValueTypeException e) { | |
489 | e.printStackTrace(); | |
490 | } catch (StateSystemDisposedException e) { | |
491 | /* Ignored */ | |
492 | } | |
493 | } | |
494 | } | |
495 | return list; | |
496 | } | |
497 | ||
498 | private ControlFlowEntry findEntry(List<TimeGraphEntry> entryList, ITmfTrace trace, int threadId) { | |
499 | for (TimeGraphEntry entry : entryList) { | |
500 | if (entry instanceof ControlFlowEntry) { | |
501 | ControlFlowEntry controlFlowEntry = (ControlFlowEntry) entry; | |
502 | if (controlFlowEntry.getThreadId() == threadId && controlFlowEntry.getTrace() == trace) { | |
503 | return controlFlowEntry; | |
504 | } else if (entry.hasChildren()) { | |
505 | controlFlowEntry = findEntry(entry.getChildren(), trace, threadId); | |
506 | if (controlFlowEntry != null) { | |
507 | return controlFlowEntry; | |
508 | } | |
509 | } | |
510 | } | |
511 | } | |
512 | return null; | |
513 | } | |
6151d86c | 514 | } |