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; | |
03ab8eeb | 23 | import org.eclipse.jface.action.IAction; |
79ec0b89 PT |
24 | import org.eclipse.jface.action.IToolBarManager; |
25 | import org.eclipse.jface.dialogs.IDialogSettings; | |
6151d86c | 26 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; |
79ec0b89 | 27 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Activator; |
6151d86c | 28 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages; |
e3366401 | 29 | import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule; |
6151d86c | 30 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; |
96345c5a | 31 | import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; |
6151d86c PT |
32 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; |
33 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
34 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; | |
f1f86dfb | 35 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
b67a2540 | 36 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
6151d86c | 37 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
79ec0b89 | 38 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; |
4999a196 | 39 | import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView; |
79ec0b89 | 40 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent; |
6151d86c PT |
41 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; |
42 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
43 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; | |
4999a196 | 44 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry; |
79ec0b89 | 45 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeLinkEvent; |
6151d86c PT |
46 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; |
47 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; | |
48 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; | |
6151d86c PT |
49 | |
50 | /** | |
51 | * The Control Flow view main object | |
52 | * | |
53 | */ | |
4999a196 | 54 | public class ControlFlowView extends AbstractTimeGraphView { |
6151d86c PT |
55 | |
56 | // ------------------------------------------------------------------------ | |
57 | // Constants | |
58 | // ------------------------------------------------------------------------ | |
59 | ||
60 | /** | |
61 | * View ID. | |
62 | */ | |
63 | public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$ | |
64 | ||
4999a196 GB |
65 | private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn; |
66 | private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn; | |
67 | private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn; | |
6151d86c | 68 | private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn; |
4999a196 | 69 | private static final String TRACE_COLUMN = Messages.ControlFlowView_traceColumn; |
6151d86c | 70 | |
4999a196 | 71 | private static final String[] COLUMN_NAMES = new String[] { |
6151d86c PT |
72 | PROCESS_COLUMN, |
73 | TID_COLUMN, | |
74 | PTID_COLUMN, | |
75 | BIRTH_TIME_COLUMN, | |
76 | TRACE_COLUMN | |
77 | }; | |
78 | ||
4999a196 | 79 | private static final String[] FILTER_COLUMN_NAMES = new String[] { |
6ac5a950 AM |
80 | PROCESS_COLUMN, |
81 | TID_COLUMN | |
82 | }; | |
83 | ||
1cf25311 PT |
84 | // Timeout between updates in the build thread in ms |
85 | private static final long BUILD_UPDATE_TIMEOUT = 500; | |
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) { |
ff3f02c8 | 223 | LttngKernelAnalysisModule module = trace.getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID); |
1cf25311 PT |
224 | if (module == null) { |
225 | return; | |
226 | } | |
227 | module.schedule(); | |
228 | module.waitForInitialization(); | |
229 | ITmfStateSystem ssq = module.getStateSystem(); | |
230 | if (ssq == null) { | |
231 | return; | |
232 | } | |
fec1ac0b | 233 | |
1cf25311 PT |
234 | List<ControlFlowEntry> entryList = new ArrayList<>(); |
235 | Map<Integer, ControlFlowEntry> entryMap = new HashMap<>(); | |
236 | ||
237 | long start = ssq.getStartTime(); | |
238 | setStartTime(Math.min(getStartTime(), start)); | |
239 | ||
240 | boolean complete = false; | |
241 | while (!complete) { | |
faa38350 PT |
242 | if (monitor.isCanceled()) { |
243 | return; | |
244 | } | |
1cf25311 PT |
245 | complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT); |
246 | if (ssq.isCancelled()) { | |
247 | return; | |
248 | } | |
249 | long end = ssq.getCurrentEndTime(); | |
250 | if (start == end && !complete) { // when complete execute one last time regardless of end time | |
251 | continue; | |
252 | } | |
253 | setEndTime(Math.max(getEndTime(), end + 1)); | |
254 | List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$ | |
255 | for (int threadQuark : threadQuarks) { | |
256 | if (monitor.isCanceled()) { | |
257 | return; | |
4bc53929 | 258 | } |
1cf25311 PT |
259 | String threadName = ssq.getAttributeName(threadQuark); |
260 | int threadId = -1; | |
261 | try { | |
262 | threadId = Integer.parseInt(threadName); | |
263 | } catch (NumberFormatException e1) { | |
4bc53929 | 264 | continue; |
2002c638 | 265 | } |
1cf25311 | 266 | if (threadId <= 0) { // ignore the 'unknown' (-1) and swapper (0) threads |
4bc53929 | 267 | continue; |
faa38350 | 268 | } |
1c471b9e AM |
269 | |
270 | int execNameQuark; | |
271 | List<ITmfStateInterval> execNameIntervals; | |
1cf25311 | 272 | try { |
1c471b9e AM |
273 | execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME); |
274 | execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end); | |
275 | } catch (AttributeNotFoundException e) { | |
276 | /* No information on this thread (yet?), skip it for now */ | |
277 | continue; | |
278 | } catch (StateSystemDisposedException e) { | |
279 | /* State system is closing down, no point continuing */ | |
280 | break; | |
281 | } | |
282 | ||
283 | for (ITmfStateInterval execNameInterval : execNameIntervals) { | |
284 | if (monitor.isCanceled()) { | |
285 | return; | |
286 | } | |
287 | ControlFlowEntry entry = entryMap.get(threadId); | |
288 | if (!execNameInterval.getStateValue().isNull() && | |
289 | execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) { | |
290 | String execName = execNameInterval.getStateValue().unboxStr(); | |
291 | long startTime = execNameInterval.getStartTime(); | |
292 | long endTime = execNameInterval.getEndTime() + 1; | |
293 | if (entry == null) { | |
294 | ITmfStateInterval ppidInterval = null; | |
295 | try { | |
1cf25311 | 296 | int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID); |
1c471b9e AM |
297 | ppidInterval = ssq.querySingleState(startTime, ppidQuark); |
298 | } catch (AttributeNotFoundException e) { | |
299 | /* No info, keep PPID at -1 */ | |
300 | } catch (StateSystemDisposedException e) { | |
301 | /* SS is closing down, time to bail */ | |
302 | break; | |
6151d86c | 303 | } |
1c471b9e AM |
304 | int ppid = -1; |
305 | if (!(ppidInterval == null) && !ppidInterval.getStateValue().isNull()) { | |
306 | ppid = ppidInterval.getStateValue().unboxInt(); | |
307 | } | |
308 | entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime); | |
309 | entryList.add(entry); | |
310 | entryMap.put(threadId, entry); | |
1cf25311 | 311 | } else { |
1c471b9e AM |
312 | // update the name of the entry to the latest |
313 | // execName | |
314 | entry.setName(execName); | |
315 | entry.updateEndTime(endTime); | |
6151d86c | 316 | } |
1c471b9e AM |
317 | } else { |
318 | entryMap.remove(threadId); | |
6151d86c PT |
319 | } |
320 | } | |
6151d86c | 321 | } |
4999a196 | 322 | |
1cf25311 PT |
323 | updateTree(entryList, parentTrace); |
324 | ||
325 | if (parentTrace.equals(getTrace())) { | |
d7ee91bb | 326 | refresh(); |
6151d86c | 327 | } |
1cf25311 PT |
328 | |
329 | for (ControlFlowEntry entry : entryList) { | |
330 | if (monitor.isCanceled()) { | |
331 | return; | |
332 | } | |
333 | buildStatusEvents(entry.getTrace(), entry, monitor, start, end); | |
faa38350 | 334 | } |
1cf25311 PT |
335 | |
336 | start = end; | |
6151d86c PT |
337 | } |
338 | } | |
339 | ||
1cf25311 PT |
340 | private void updateTree(List<ControlFlowEntry> entryList, ITmfTrace parentTrace) { |
341 | List<TimeGraphEntry> rootListToAdd = new ArrayList<>(); | |
342 | List<TimeGraphEntry> rootListToRemove = new ArrayList<>(); | |
343 | List<TimeGraphEntry> rootList = getEntryList(parentTrace); | |
344 | ||
1d46dc38 | 345 | for (ControlFlowEntry entry : entryList) { |
1cf25311 PT |
346 | boolean root = (entry.getParent() == null); |
347 | if (root && entry.getParentThreadId() > 0) { | |
1d46dc38 | 348 | for (ControlFlowEntry parent : entryList) { |
6151d86c PT |
349 | if (parent.getThreadId() == entry.getParentThreadId() && |
350 | entry.getStartTime() >= parent.getStartTime() && | |
351 | entry.getStartTime() <= parent.getEndTime()) { | |
352 | parent.addChild(entry); | |
353 | root = false; | |
1cf25311 PT |
354 | if (rootList != null && rootList.contains(entry)) { |
355 | rootListToRemove.add(entry); | |
356 | } | |
6151d86c PT |
357 | break; |
358 | } | |
359 | } | |
360 | } | |
1cf25311 PT |
361 | if (root && (rootList == null || !rootList.contains(entry))) { |
362 | rootListToAdd.add(entry); | |
6151d86c PT |
363 | } |
364 | } | |
1cf25311 PT |
365 | |
366 | addToEntryList(parentTrace, rootListToAdd); | |
367 | removeFromEntryList(parentTrace, rootListToRemove); | |
6151d86c PT |
368 | } |
369 | ||
1cf25311 PT |
370 | private void buildStatusEvents(ITmfTrace trace, ControlFlowEntry entry, IProgressMonitor monitor, long start, long end) { |
371 | if (start < entry.getEndTime() && end > entry.getStartTime()) { | |
ff3f02c8 | 372 | LttngKernelAnalysisModule module = entry.getTrace().getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID); |
1cf25311 PT |
373 | if (module == null) { |
374 | return; | |
375 | } | |
376 | ITmfStateSystem ssq = module.getStateSystem(); | |
377 | if (ssq == null) { | |
378 | return; | |
379 | } | |
380 | ||
381 | long startTime = Math.max(start, entry.getStartTime()); | |
382 | long endTime = Math.min(end + 1, entry.getEndTime()); | |
383 | long resolution = Math.max(1, (end - ssq.getStartTime()) / getDisplayWidth()); | |
384 | List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor); | |
385 | if (monitor.isCanceled()) { | |
386 | return; | |
387 | } | |
388 | for (ITimeEvent event : eventList) { | |
389 | entry.addEvent(event); | |
390 | } | |
391 | if (trace.equals(getTrace())) { | |
392 | redraw(); | |
393 | } | |
faa38350 | 394 | } |
6151d86c | 395 | for (ITimeGraphEntry child : entry.getChildren()) { |
faa38350 PT |
396 | if (monitor.isCanceled()) { |
397 | return; | |
398 | } | |
1cf25311 | 399 | buildStatusEvents(trace, (ControlFlowEntry) child, monitor, start, end); |
6151d86c PT |
400 | } |
401 | } | |
402 | ||
4999a196 GB |
403 | @Override |
404 | protected List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
405 | List<ITimeEvent> eventList = null; | |
406 | if (!(tgentry instanceof ControlFlowEntry)) { | |
407 | return eventList; | |
408 | } | |
409 | ControlFlowEntry entry = (ControlFlowEntry) tgentry; | |
41b5c37f AM |
410 | final long realStart = Math.max(startTime, entry.getStartTime()); |
411 | final long realEnd = Math.min(endTime, entry.getEndTime()); | |
412 | if (realEnd <= realStart) { | |
6151d86c PT |
413 | return null; |
414 | } | |
ff3f02c8 | 415 | LttngKernelAnalysisModule module = entry.getTrace().getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID); |
1cf25311 PT |
416 | if (module == null) { |
417 | return null; | |
418 | } | |
4bc53929 GB |
419 | ITmfStateSystem ssq = module.getStateSystem(); |
420 | if (ssq == null) { | |
421 | return null; | |
422 | } | |
6151d86c PT |
423 | try { |
424 | int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS); | |
41b5c37f | 425 | List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor); |
e0838ca1 | 426 | eventList = new ArrayList<>(statusIntervals.size()); |
6151d86c PT |
427 | long lastEndTime = -1; |
428 | for (ITmfStateInterval statusInterval : statusIntervals) { | |
429 | if (monitor.isCanceled()) { | |
430 | return null; | |
431 | } | |
432 | long time = statusInterval.getStartTime(); | |
433 | long duration = statusInterval.getEndTime() - time + 1; | |
434 | int status = -1; | |
435 | try { | |
436 | status = statusInterval.getStateValue().unboxInt(); | |
437 | } catch (StateValueTypeException e) { | |
438 | e.printStackTrace(); | |
439 | } | |
440 | if (lastEndTime != time && lastEndTime != -1) { | |
af10fe06 | 441 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime)); |
6151d86c | 442 | } |
4999a196 | 443 | eventList.add(new TimeEvent(entry, time, duration, status)); |
6151d86c PT |
444 | lastEndTime = time + duration; |
445 | } | |
1cf25311 | 446 | } catch (AttributeNotFoundException | TimeRangeException e) { |
6151d86c | 447 | e.printStackTrace(); |
96345c5a AM |
448 | } catch (StateSystemDisposedException e) { |
449 | /* Ignored */ | |
6151d86c PT |
450 | } |
451 | return eventList; | |
452 | } | |
453 | ||
4999a196 GB |
454 | /** |
455 | * Returns a value corresponding to the selected entry. | |
456 | * | |
1cf25311 PT |
457 | * Used in conjunction with synchingToTime to change the selected entry. If |
458 | * one of these methods is overridden in child class, then both should be. | |
4999a196 GB |
459 | * |
460 | * @param time | |
461 | * The currently selected time | |
462 | * @return a value identifying the entry | |
463 | */ | |
464 | private int getSelectionValue(long time) { | |
465 | int thread = -1; | |
1cf25311 PT |
466 | ITmfTrace[] traces = TmfTraceManager.getTraceSet(getTrace()); |
467 | if (traces == null) { | |
468 | return thread; | |
469 | } | |
470 | for (ITmfTrace trace : traces) { | |
4999a196 GB |
471 | if (thread > 0) { |
472 | break; | |
473 | } | |
ff3f02c8 | 474 | LttngKernelAnalysisModule module = trace.getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID); |
1cf25311 PT |
475 | if (module == null) { |
476 | continue; | |
477 | } | |
478 | ITmfStateSystem ssq = module.getStateSystem(); | |
479 | if (ssq == null) { | |
480 | continue; | |
481 | } | |
482 | if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) { | |
483 | List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$ | |
484 | for (int currentThreadQuark : currentThreadQuarks) { | |
485 | try { | |
486 | ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark); | |
487 | int currentThread = currentThreadInterval.getStateValue().unboxInt(); | |
488 | if (currentThread > 0) { | |
489 | int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread), Attributes.STATUS); | |
490 | ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark); | |
491 | if (statusInterval.getStartTime() == time) { | |
492 | thread = currentThread; | |
493 | break; | |
4999a196 | 494 | } |
4999a196 | 495 | } |
1cf25311 PT |
496 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { |
497 | e.printStackTrace(); | |
498 | } catch (StateSystemDisposedException e) { | |
499 | /* Ignored */ | |
faa38350 | 500 | } |
6151d86c | 501 | } |
6151d86c | 502 | } |
4999a196 GB |
503 | } |
504 | return thread; | |
6151d86c PT |
505 | } |
506 | ||
4999a196 GB |
507 | @Override |
508 | protected void synchingToTime(long time) { | |
509 | int selected = getSelectionValue(time); | |
510 | if (selected > 0) { | |
747adf5c | 511 | for (Object element : getTimeGraphViewer().getExpandedElements()) { |
4999a196 GB |
512 | if (element instanceof ControlFlowEntry) { |
513 | ControlFlowEntry entry = (ControlFlowEntry) element; | |
514 | if (entry.getThreadId() == selected) { | |
515 | getTimeGraphCombo().setSelection(entry); | |
516 | break; | |
6151d86c PT |
517 | } |
518 | } | |
519 | } | |
6151d86c | 520 | } |
6151d86c | 521 | } |
79ec0b89 PT |
522 | |
523 | @Override | |
524 | protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
e0838ca1 | 525 | List<ILinkEvent> list = new ArrayList<>(); |
79ec0b89 | 526 | ITmfTrace[] traces = TmfTraceManager.getTraceSet(getTrace()); |
1cf25311 | 527 | List<TimeGraphEntry> entryList = getEntryList(getTrace()); |
79ec0b89 PT |
528 | if (traces == null || entryList == null) { |
529 | return list; | |
530 | } | |
531 | for (ITmfTrace trace : traces) { | |
ff3f02c8 | 532 | LttngKernelAnalysisModule module = trace.getAnalysisModuleOfClass(LttngKernelAnalysisModule.class, LttngKernelAnalysisModule.ID); |
1cf25311 PT |
533 | if (module == null) { |
534 | continue; | |
535 | } | |
536 | ITmfStateSystem ssq = module.getStateSystem(); | |
537 | if (ssq == null) { | |
538 | continue; | |
539 | } | |
540 | try { | |
541 | long start = Math.max(startTime, ssq.getStartTime()); | |
542 | long end = Math.min(endTime, ssq.getCurrentEndTime()); | |
543 | if (end < start) { | |
4bc53929 GB |
544 | continue; |
545 | } | |
1cf25311 PT |
546 | List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$ |
547 | for (int currentThreadQuark : currentThreadQuarks) { | |
548 | // adjust the query range to include the previous and following intervals | |
549 | long qstart = Math.max(ssq.querySingleState(start, currentThreadQuark).getStartTime() - 1, ssq.getStartTime()); | |
550 | long qend = Math.min(ssq.querySingleState(end, currentThreadQuark).getEndTime() + 1, ssq.getCurrentEndTime()); | |
551 | List<ITmfStateInterval> currentThreadIntervals = ssq.queryHistoryRange(currentThreadQuark, qstart, qend, resolution, monitor); | |
552 | int prevThread = 0; | |
553 | long prevEnd = 0; | |
554 | long lastEnd = 0; | |
555 | for (ITmfStateInterval currentThreadInterval : currentThreadIntervals) { | |
556 | if (monitor.isCanceled()) { | |
557 | return null; | |
558 | } | |
559 | long time = currentThreadInterval.getStartTime(); | |
560 | if (time != lastEnd) { | |
561 | // don't create links where there are gaps in intervals due to the resolution | |
562 | prevThread = 0; | |
563 | prevEnd = 0; | |
564 | } | |
565 | int thread = currentThreadInterval.getStateValue().unboxInt(); | |
566 | if (thread > 0 && prevThread > 0) { | |
567 | ITimeGraphEntry prevEntry = findEntry(entryList, trace, prevThread); | |
568 | ITimeGraphEntry nextEntry = findEntry(entryList, trace, thread); | |
569 | list.add(new TimeLinkEvent(prevEntry, nextEntry, prevEnd, time - prevEnd, 0)); | |
570 | } | |
571 | lastEnd = currentThreadInterval.getEndTime() + 1; | |
572 | if (thread != 0) { | |
573 | prevThread = thread; | |
574 | prevEnd = lastEnd; | |
79ec0b89 PT |
575 | } |
576 | } | |
79ec0b89 | 577 | } |
1cf25311 PT |
578 | } catch (TimeRangeException | AttributeNotFoundException | StateValueTypeException e) { |
579 | e.printStackTrace(); | |
580 | } catch (StateSystemDisposedException e) { | |
581 | /* Ignored */ | |
79ec0b89 PT |
582 | } |
583 | } | |
584 | return list; | |
585 | } | |
586 | ||
587 | private ControlFlowEntry findEntry(List<TimeGraphEntry> entryList, ITmfTrace trace, int threadId) { | |
588 | for (TimeGraphEntry entry : entryList) { | |
589 | if (entry instanceof ControlFlowEntry) { | |
590 | ControlFlowEntry controlFlowEntry = (ControlFlowEntry) entry; | |
591 | if (controlFlowEntry.getThreadId() == threadId && controlFlowEntry.getTrace() == trace) { | |
592 | return controlFlowEntry; | |
593 | } else if (entry.hasChildren()) { | |
594 | controlFlowEntry = findEntry(entry.getChildren(), trace, threadId); | |
595 | if (controlFlowEntry != null) { | |
596 | return controlFlowEntry; | |
597 | } | |
598 | } | |
599 | } | |
600 | } | |
601 | return null; | |
602 | } | |
6151d86c | 603 | } |