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