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