Commit | Line | Data |
---|---|---|
04835162 PT |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2012 Ericsson\r | |
27f3a03d | 3 | *\r |
04835162 PT |
4 | * All rights reserved. This program and the accompanying materials are\r |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
27f3a03d | 8 | *\r |
04835162 PT |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;\r | |
14 | \r | |
15 | import java.util.ArrayList;\r | |
16 | import java.util.Arrays;\r | |
15c04058 | 17 | import java.util.Collections;\r |
2c33fc31 | 18 | import java.util.Comparator;\r |
04835162 | 19 | import java.util.List;\r |
04835162 | 20 | \r |
0137b624 PT |
21 | import org.eclipse.core.runtime.IProgressMonitor;\r |
22 | import org.eclipse.core.runtime.NullProgressMonitor;\r | |
49ffadb7 PT |
23 | import org.eclipse.jface.action.Action;\r |
24 | import org.eclipse.jface.action.IToolBarManager;\r | |
25 | import org.eclipse.jface.action.Separator;\r | |
04835162 PT |
26 | import org.eclipse.jface.viewers.ILabelProviderListener;\r |
27 | import org.eclipse.jface.viewers.ITableLabelProvider;\r | |
28 | import org.eclipse.jface.viewers.ITreeContentProvider;\r | |
29 | import org.eclipse.jface.viewers.Viewer;\r | |
3e97fbfa | 30 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r |
04835162 | 31 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r |
04835162 | 32 | import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\r |
49ffadb7 | 33 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;\r |
04835162 | 34 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r |
49ffadb7 PT |
35 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;\r |
36 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r | |
04835162 PT |
37 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r |
38 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r | |
39 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r | |
04835162 PT |
40 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r |
41 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;\r | |
49ffadb7 | 42 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;\r |
04835162 | 43 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r |
b987050f | 44 | import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;\r |
49ffadb7 | 45 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;\r |
04835162 PT |
46 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r |
47 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r | |
9e0640dc | 48 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;\r |
04835162 PT |
49 | import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r |
50 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;\r | |
51 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener;\r | |
52 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;\r | |
53 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphCombo;\r | |
04835162 PT |
54 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;\r |
55 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent;\r | |
56 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;\r | |
57 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r | |
58 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r | |
59 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r | |
49ffadb7 PT |
60 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;\r |
61 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;\r | |
62 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;\r | |
04835162 PT |
63 | import org.eclipse.swt.SWT;\r |
64 | import org.eclipse.swt.graphics.Image;\r | |
65 | import org.eclipse.swt.widgets.Composite;\r | |
66 | import org.eclipse.swt.widgets.Display;\r | |
49ffadb7 PT |
67 | import org.eclipse.swt.widgets.TreeColumn;\r |
68 | import org.eclipse.ui.IActionBars;\r | |
04835162 | 69 | \r |
27f3a03d AM |
70 | /**\r |
71 | * The Control Flow view main object\r | |
72 | *\r | |
73 | */\r | |
04835162 PT |
74 | public class ControlFlowView extends TmfView {\r |
75 | \r | |
76 | // ------------------------------------------------------------------------\r | |
77 | // Constants\r | |
78 | // ------------------------------------------------------------------------\r | |
79 | \r | |
80 | /**\r | |
81 | * View ID.\r | |
82 | */\r | |
83 | public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.controlflow"; //$NON-NLS-1$\r | |
84 | \r | |
3ac6ad1a BH |
85 | /**\r |
86 | * Initial time range\r | |
87 | */\r | |
88 | private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec\r | |
0137b624 | 89 | \r |
49ffadb7 PT |
90 | private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;\r |
91 | private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn;\r | |
3d90c4ff | 92 | private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn;\r |
49ffadb7 PT |
93 | private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn;\r |
94 | private static final String TRACE_COLUMN = Messages.ControlFlowView_traceColumn;\r | |
04835162 PT |
95 | \r |
96 | private final String[] COLUMN_NAMES = new String[] {\r | |
97 | PROCESS_COLUMN,\r | |
98 | TID_COLUMN,\r | |
3d90c4ff | 99 | PTID_COLUMN,\r |
49ffadb7 | 100 | BIRTH_TIME_COLUMN,\r |
04835162 PT |
101 | TRACE_COLUMN\r |
102 | };\r | |
103 | \r | |
104 | // ------------------------------------------------------------------------\r | |
105 | // Fields\r | |
106 | // ------------------------------------------------------------------------\r | |
107 | \r | |
108 | // The timegraph combo\r | |
109 | private TimeGraphCombo fTimeGraphCombo;\r | |
110 | \r | |
111 | // The selected experiment\r | |
112 | private TmfExperiment<ITmfEvent> fSelectedExperiment;\r | |
113 | \r | |
114 | // The timegraph entry list\r | |
49ffadb7 | 115 | private ArrayList<ControlFlowEntry> fEntryList;\r |
04835162 | 116 | \r |
c19a8781 PT |
117 | // The time graph entry list synchronization object\r |
118 | final private Object fEntryListSyncObj = new Object();\r | |
119 | \r | |
04835162 PT |
120 | // The start time\r |
121 | private long fStartTime;\r | |
122 | \r | |
123 | // The end time\r | |
124 | private long fEndTime;\r | |
125 | \r | |
49ffadb7 | 126 | // The display width\r |
27f3a03d | 127 | private final int fDisplayWidth;\r |
49ffadb7 PT |
128 | \r |
129 | // The zoom thread\r | |
130 | private ZoomThread fZoomThread;\r | |
0137b624 | 131 | \r |
49ffadb7 PT |
132 | // The next resource action\r |
133 | private Action fNextResourceAction;\r | |
0137b624 | 134 | \r |
49ffadb7 PT |
135 | // The previous resource action\r |
136 | private Action fPreviousResourceAction;\r | |
27f3a03d | 137 | \r |
2c33fc31 | 138 | // A comparator class\r |
27f3a03d | 139 | private final ControlFlowEntryComparator fControlFlowEntryComparator = new ControlFlowEntryComparator();\r |
49ffadb7 | 140 | \r |
04835162 PT |
141 | // ------------------------------------------------------------------------\r |
142 | // Classes\r | |
143 | // ------------------------------------------------------------------------\r | |
144 | \r | |
145 | private class TreeContentProvider implements ITreeContentProvider {\r | |
146 | \r | |
147 | @Override\r | |
148 | public void dispose() {\r | |
149 | }\r | |
150 | \r | |
151 | @Override\r | |
152 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r | |
153 | }\r | |
154 | \r | |
155 | @Override\r | |
156 | public Object[] getElements(Object inputElement) {\r | |
157 | return (ITimeGraphEntry[]) inputElement;\r | |
158 | }\r | |
159 | \r | |
160 | @Override\r | |
161 | public Object[] getChildren(Object parentElement) {\r | |
162 | ITimeGraphEntry entry = (ITimeGraphEntry) parentElement;\r | |
163 | return entry.getChildren();\r | |
164 | }\r | |
165 | \r | |
166 | @Override\r | |
167 | public Object getParent(Object element) {\r | |
168 | ITimeGraphEntry entry = (ITimeGraphEntry) element;\r | |
169 | return entry.getParent();\r | |
170 | }\r | |
171 | \r | |
172 | @Override\r | |
173 | public boolean hasChildren(Object element) {\r | |
174 | ITimeGraphEntry entry = (ITimeGraphEntry) element;\r | |
175 | return entry.hasChildren();\r | |
176 | }\r | |
0137b624 | 177 | \r |
04835162 PT |
178 | }\r |
179 | \r | |
180 | private class TreeLabelProvider implements ITableLabelProvider {\r | |
181 | \r | |
182 | @Override\r | |
183 | public void addListener(ILabelProviderListener listener) {\r | |
184 | }\r | |
185 | \r | |
186 | @Override\r | |
187 | public void dispose() {\r | |
188 | }\r | |
189 | \r | |
190 | @Override\r | |
191 | public boolean isLabelProperty(Object element, String property) {\r | |
192 | return false;\r | |
193 | }\r | |
194 | \r | |
195 | @Override\r | |
196 | public void removeListener(ILabelProviderListener listener) {\r | |
197 | }\r | |
198 | \r | |
199 | @Override\r | |
200 | public Image getColumnImage(Object element, int columnIndex) {\r | |
201 | return null;\r | |
202 | }\r | |
203 | \r | |
204 | @Override\r | |
205 | public String getColumnText(Object element, int columnIndex) {\r | |
206 | ControlFlowEntry entry = (ControlFlowEntry) element;\r | |
207 | if (columnIndex == 0) {\r | |
208 | return entry.getName();\r | |
209 | } else if (columnIndex == 1) {\r | |
210 | return Integer.toString(entry.getThreadId());\r | |
49ffadb7 | 211 | } else if (columnIndex == 2) {\r |
3d90c4ff PT |
212 | if (entry.getParentThreadId() > 0) {\r |
213 | return Integer.toString(entry.getParentThreadId());\r | |
04835162 | 214 | }\r |
49ffadb7 PT |
215 | } else if (columnIndex == 3) {\r |
216 | return Utils.formatTime(entry.getBirthTime(), TimeFormat.ABSOLUTE, Resolution.NANOSEC);\r | |
217 | } else if (columnIndex == 4) {\r | |
218 | return entry.getTrace().getName();\r | |
04835162 PT |
219 | }\r |
220 | return ""; //$NON-NLS-1$\r | |
221 | }\r | |
0137b624 | 222 | \r |
04835162 PT |
223 | }\r |
224 | \r | |
2c33fc31 BH |
225 | private static class ControlFlowEntryComparator implements Comparator<ITimeGraphEntry> {\r |
226 | \r | |
227 | @Override\r | |
228 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {\r | |
229 | int result = 0;\r | |
230 | \r | |
231 | if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {\r | |
232 | ControlFlowEntry entry1 = (ControlFlowEntry) o1;\r | |
233 | ControlFlowEntry entry2 = (ControlFlowEntry) o2;\r | |
234 | result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());\r | |
15c04058 PT |
235 | if (result == 0) {\r |
236 | result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());\r | |
237 | }\r | |
2c33fc31 BH |
238 | if (result == 0) {\r |
239 | result = entry1.getThreadId() < entry2.getThreadId() ? -1 : entry1.getThreadId() > entry2.getThreadId() ? 1 : 0;\r | |
240 | }\r | |
241 | }\r | |
242 | \r | |
243 | if (result == 0) {\r | |
244 | result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;\r | |
245 | }\r | |
246 | \r | |
247 | return result;\r | |
248 | }\r | |
249 | }\r | |
250 | \r | |
27f3a03d | 251 | \r |
49ffadb7 | 252 | private class ZoomThread extends Thread {\r |
27f3a03d AM |
253 | private final long fZoomStartTime;\r |
254 | private final long fZoomEndTime;\r | |
255 | private final long fResolution;\r | |
256 | private final IProgressMonitor fMonitor;\r | |
49ffadb7 PT |
257 | \r |
258 | public ZoomThread(long startTime, long endTime) {\r | |
259 | super("ControlFlowView zoom"); //$NON-NLS-1$\r | |
3ac6ad1a BH |
260 | fZoomStartTime = startTime;\r |
261 | fZoomEndTime = endTime;\r | |
262 | fResolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);\r | |
0137b624 | 263 | fMonitor = new NullProgressMonitor();\r |
49ffadb7 PT |
264 | }\r |
265 | \r | |
266 | @Override\r | |
267 | public void run() {\r | |
c19a8781 PT |
268 | ArrayList<ControlFlowEntry> entryList = null;\r |
269 | synchronized (fEntryListSyncObj) {\r | |
270 | entryList = fEntryList;\r | |
271 | }\r | |
8d8cb868 | 272 | if (entryList == null) {\r |
49ffadb7 PT |
273 | return;\r |
274 | }\r | |
8d8cb868 | 275 | for (ControlFlowEntry entry : entryList) {\r |
0137b624 | 276 | if (fMonitor.isCanceled()) {\r |
5929fada | 277 | break;\r |
49ffadb7 | 278 | }\r |
0137b624 | 279 | zoom(entry, fMonitor);\r |
49ffadb7 PT |
280 | }\r |
281 | redraw();\r | |
282 | }\r | |
283 | \r | |
0137b624 | 284 | private void zoom(ControlFlowEntry entry, IProgressMonitor monitor) {\r |
f7ddf9b3 | 285 | if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {\r |
b987050f | 286 | entry.setZoomedEventList(null);\r |
5929fada PT |
287 | } else {\r |
288 | List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, fResolution, monitor);\r | |
289 | if (zoomedEventList != null) {\r | |
290 | entry.setZoomedEventList(zoomedEventList);\r | |
291 | }\r | |
0137b624 | 292 | }\r |
49ffadb7 | 293 | for (ControlFlowEntry child : entry.getChildren()) {\r |
0137b624 | 294 | if (fMonitor.isCanceled()) {\r |
49ffadb7 PT |
295 | return;\r |
296 | }\r | |
0137b624 | 297 | zoom(child, monitor);\r |
49ffadb7 PT |
298 | }\r |
299 | }\r | |
300 | \r | |
301 | public void cancel() {\r | |
0137b624 | 302 | fMonitor.setCanceled(true);\r |
49ffadb7 PT |
303 | }\r |
304 | }\r | |
305 | \r | |
04835162 PT |
306 | // ------------------------------------------------------------------------\r |
307 | // Constructors\r | |
308 | // ------------------------------------------------------------------------\r | |
309 | \r | |
27f3a03d AM |
310 | /**\r |
311 | * Constructor\r | |
312 | */\r | |
04835162 PT |
313 | public ControlFlowView() {\r |
314 | super(ID);\r | |
49ffadb7 | 315 | fDisplayWidth = Display.getDefault().getBounds().width;\r |
04835162 PT |
316 | }\r |
317 | \r | |
318 | // ------------------------------------------------------------------------\r | |
319 | // ViewPart\r | |
320 | // ------------------------------------------------------------------------\r | |
321 | \r | |
322 | /* (non-Javadoc)\r | |
323 | * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)\r | |
324 | */\r | |
325 | @Override\r | |
326 | public void createPartControl(Composite parent) {\r | |
327 | fTimeGraphCombo = new TimeGraphCombo(parent, SWT.NONE);\r | |
328 | \r | |
329 | fTimeGraphCombo.setTreeContentProvider(new TreeContentProvider());\r | |
330 | \r | |
331 | fTimeGraphCombo.setTreeLabelProvider(new TreeLabelProvider());\r | |
332 | \r | |
72b5abb1 | 333 | fTimeGraphCombo.setTimeGraphProvider(new ControlFlowPresentationProvider());\r |
04835162 PT |
334 | \r |
335 | fTimeGraphCombo.setTreeColumns(COLUMN_NAMES);\r | |
336 | \r | |
337 | fTimeGraphCombo.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {\r | |
338 | @Override\r | |
339 | public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {\r | |
49ffadb7 PT |
340 | final long startTime = event.getStartTime();\r |
341 | final long endTime = event.getEndTime();\r | |
342 | TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));\r | |
343 | TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphCombo.getTimeGraphViewer().getSelectedTime());\r | |
344 | broadcast(new TmfRangeSynchSignal(ControlFlowView.this, range, time));\r | |
345 | if (fZoomThread != null) {\r | |
346 | fZoomThread.cancel();\r | |
347 | }\r | |
3ac6ad1a | 348 | startZoomThread(startTime, endTime);\r |
04835162 PT |
349 | }\r |
350 | });\r | |
351 | \r | |
352 | fTimeGraphCombo.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {\r | |
353 | @Override\r | |
354 | public void timeSelected(TimeGraphTimeEvent event) {\r | |
355 | long time = event.getTime();\r | |
49ffadb7 | 356 | broadcast(new TmfTimeSynchSignal(ControlFlowView.this, new CtfTmfTimestamp(time)));\r |
04835162 PT |
357 | }\r |
358 | });\r | |
359 | \r | |
360 | fTimeGraphCombo.addSelectionListener(new ITimeGraphSelectionListener() {\r | |
361 | @Override\r | |
362 | public void selectionChanged(TimeGraphSelectionEvent event) {\r | |
49ffadb7 | 363 | //ITimeGraphEntry selection = event.getSelection();\r |
04835162 PT |
364 | }\r |
365 | });\r | |
366 | \r | |
49ffadb7 PT |
367 | fTimeGraphCombo.getTimeGraphViewer().setTimeCalendarFormat(true);\r |
368 | \r | |
369 | final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$\r | |
04835162 PT |
370 | @Override\r |
371 | public void run() {\r | |
372 | if (TmfExperiment.getCurrentExperiment() != null) {\r | |
373 | selectExperiment(TmfExperiment.getCurrentExperiment());\r | |
374 | }\r | |
375 | }\r | |
376 | };\r | |
377 | thread.start();\r | |
0137b624 | 378 | \r |
49ffadb7 PT |
379 | // View Action Handling\r |
380 | makeActions();\r | |
381 | contributeToActionBars();\r | |
04835162 PT |
382 | }\r |
383 | \r | |
384 | /* (non-Javadoc)\r | |
385 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r | |
386 | */\r | |
387 | @Override\r | |
388 | public void setFocus() {\r | |
389 | fTimeGraphCombo.setFocus();\r | |
390 | }\r | |
391 | \r | |
392 | // ------------------------------------------------------------------------\r | |
393 | // Signal handlers\r | |
394 | // ------------------------------------------------------------------------\r | |
395 | \r | |
27f3a03d AM |
396 | /**\r |
397 | * Handler for the experiment selected signal\r | |
398 | *\r | |
399 | * @param signal\r | |
400 | * The signal that's received\r | |
401 | */\r | |
04835162 PT |
402 | @TmfSignalHandler\r |
403 | public void experimentSelected(final TmfExperimentSelectedSignal<? extends ITmfEvent> signal) {\r | |
404 | if (signal.getExperiment().equals(fSelectedExperiment)) {\r | |
405 | return;\r | |
406 | }\r | |
407 | \r | |
49ffadb7 | 408 | final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$\r |
04835162 PT |
409 | @Override\r |
410 | public void run() {\r | |
411 | selectExperiment(signal.getExperiment());\r | |
0137b624 PT |
412 | }\r |
413 | };\r | |
49ffadb7 PT |
414 | thread.start();\r |
415 | }\r | |
416 | \r | |
27f3a03d AM |
417 | /**\r |
418 | * Handler for the synch signal\r | |
419 | *\r | |
420 | * @param signal\r | |
421 | * The signal that's received\r | |
422 | */\r | |
49ffadb7 PT |
423 | @TmfSignalHandler\r |
424 | public void synchToTime(final TmfTimeSynchSignal signal) {\r | |
8a74a597 | 425 | if (signal.getSource() == this || fSelectedExperiment == null) {\r |
49ffadb7 PT |
426 | return;\r |
427 | }\r | |
428 | final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r | |
0137b624 PT |
429 | \r |
430 | int thread = -1;\r | |
431 | for (ITmfTrace<?> trace : fSelectedExperiment.getTraces()) {\r | |
432 | if (thread > 0) {\r | |
433 | break;\r | |
434 | }\r | |
435 | if (trace instanceof CtfKernelTrace) {\r | |
436 | CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r | |
437 | IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r | |
438 | if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) {\r | |
439 | List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$\r | |
440 | for (int currentThreadQuark : currentThreadQuarks) {\r | |
441 | try {\r | |
442 | ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark);\r | |
443 | int currentThread = currentThreadInterval.getStateValue().unboxInt();\r | |
444 | if (currentThread > 0) {\r | |
445 | int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread), Attributes.STATUS);\r | |
446 | ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark);\r | |
447 | if (statusInterval.getStartTime() == time) {\r | |
448 | thread = currentThread;\r | |
449 | break;\r | |
450 | }\r | |
451 | }\r | |
452 | } catch (AttributeNotFoundException e) {\r | |
453 | e.printStackTrace();\r | |
454 | } catch (TimeRangeException e) {\r | |
455 | e.printStackTrace();\r | |
456 | } catch (StateValueTypeException e) {\r | |
457 | e.printStackTrace();\r | |
458 | }\r | |
459 | }\r | |
460 | }\r | |
461 | }\r | |
462 | }\r | |
463 | final int selectedThread = thread;\r | |
27f3a03d | 464 | \r |
49ffadb7 PT |
465 | Display.getDefault().asyncExec(new Runnable() {\r |
466 | @Override\r | |
467 | public void run() {\r | |
468 | if (fTimeGraphCombo.isDisposed()) {\r | |
469 | return;\r | |
470 | }\r | |
3ac6ad1a | 471 | fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, true);\r |
0137b624 PT |
472 | startZoomThread(fTimeGraphCombo.getTimeGraphViewer().getTime0(), fTimeGraphCombo.getTimeGraphViewer().getTime1());\r |
473 | \r | |
474 | if (selectedThread > 0) {\r | |
475 | for (Object element : fTimeGraphCombo.getTimeGraphViewer().getExpandedElements()) {\r | |
476 | if (element instanceof ControlFlowEntry) {\r | |
477 | ControlFlowEntry entry = (ControlFlowEntry) element;\r | |
478 | if (entry.getThreadId() == selectedThread) {\r | |
479 | fTimeGraphCombo.setSelection(entry);\r | |
7264b6f2 | 480 | break;\r |
0137b624 PT |
481 | }\r |
482 | }\r | |
483 | }\r | |
484 | }\r | |
49ffadb7 PT |
485 | }\r |
486 | });\r | |
487 | }\r | |
488 | \r | |
27f3a03d AM |
489 | /**\r |
490 | * Handler for the range sync signal\r | |
491 | *\r | |
492 | * @param signal\r | |
493 | * The signal that's received\r | |
494 | */\r | |
49ffadb7 PT |
495 | @TmfSignalHandler\r |
496 | public void synchToRange(final TmfRangeSynchSignal signal) {\r | |
8a74a597 | 497 | if (signal.getSource() == this || fSelectedExperiment == null) {\r |
49ffadb7 PT |
498 | return;\r |
499 | }\r | |
500 | final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();\r | |
501 | final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();\r | |
502 | final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r | |
503 | Display.getDefault().asyncExec(new Runnable() {\r | |
504 | @Override\r | |
505 | public void run() {\r | |
506 | if (fTimeGraphCombo.isDisposed()) {\r | |
507 | return;\r | |
508 | }\r | |
509 | fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(startTime, endTime);\r | |
3ac6ad1a BH |
510 | fTimeGraphCombo.getTimeGraphViewer().setSelectedTime(time, false);\r |
511 | startZoomThread(startTime, endTime);\r | |
49ffadb7 PT |
512 | }\r |
513 | });\r | |
04835162 PT |
514 | }\r |
515 | \r | |
27f3a03d AM |
516 | /**\r |
517 | * Handler for the state system build completed signal\r | |
518 | *\r | |
519 | * @param signal\r | |
520 | * The signal that's received\r | |
521 | */\r | |
b987050f PT |
522 | @TmfSignalHandler\r |
523 | public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {\r | |
524 | final TmfExperiment<?> selectedExperiment = fSelectedExperiment;\r | |
525 | if (selectedExperiment == null) {\r | |
526 | return;\r | |
527 | }\r | |
528 | for (ITmfTrace<?> trace : selectedExperiment.getTraces()) {\r | |
529 | if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {\r | |
530 | final Thread thread = new Thread("ControlFlowView build") { //$NON-NLS-1$\r | |
531 | @Override\r | |
532 | public void run() {\r | |
533 | // rebuild the model\r | |
534 | selectExperiment(selectedExperiment);\r | |
535 | }\r | |
536 | };\r | |
537 | thread.start();\r | |
538 | }\r | |
539 | }\r | |
540 | }\r | |
541 | \r | |
49ffadb7 PT |
542 | // ------------------------------------------------------------------------\r |
543 | // Internal\r | |
544 | // ------------------------------------------------------------------------\r | |
545 | \r | |
04835162 PT |
546 | @SuppressWarnings("unchecked")\r |
547 | private void selectExperiment(TmfExperiment<?> experiment) {\r | |
548 | fStartTime = Long.MAX_VALUE;\r | |
549 | fEndTime = Long.MIN_VALUE;\r | |
550 | fSelectedExperiment = (TmfExperiment<ITmfEvent>) experiment;\r | |
15c04058 | 551 | ArrayList<ControlFlowEntry> rootList = new ArrayList<ControlFlowEntry>();\r |
04835162 PT |
552 | for (ITmfTrace<?> trace : experiment.getTraces()) {\r |
553 | if (trace instanceof CtfKernelTrace) {\r | |
15c04058 | 554 | ArrayList<ControlFlowEntry> entryList = new ArrayList<ControlFlowEntry>();\r |
04835162 PT |
555 | CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r |
556 | IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r | |
04835162 | 557 | long start = ssq.getStartTime();\r |
b987050f | 558 | long end = ssq.getCurrentEndTime() + 1;\r |
04835162 PT |
559 | fStartTime = Math.min(fStartTime, start);\r |
560 | fEndTime = Math.max(fEndTime, end);\r | |
561 | List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$\r | |
562 | for (int threadQuark : threadQuarks) {\r | |
563 | String threadName = ssq.getAttributeName(threadQuark);\r | |
564 | int threadId = -1;\r | |
565 | try {\r | |
566 | threadId = Integer.parseInt(threadName);\r | |
567 | } catch (NumberFormatException e1) {\r | |
568 | continue;\r | |
569 | }\r | |
49ffadb7 PT |
570 | if (threadId == 0) { // ignore the swapper thread\r |
571 | continue;\r | |
572 | }\r | |
04835162 PT |
573 | int execNameQuark = -1;\r |
574 | try {\r | |
575 | try {\r | |
576 | execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME);\r | |
577 | } catch (AttributeNotFoundException e) {\r | |
578 | continue;\r | |
579 | }\r | |
580 | int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID);\r | |
b987050f | 581 | List<ITmfStateInterval> execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end - 1);\r |
49ffadb7 | 582 | long birthTime = -1;\r |
04835162 PT |
583 | for (ITmfStateInterval execNameInterval : execNameIntervals) {\r |
584 | if (!execNameInterval.getStateValue().isNull() && execNameInterval.getStateValue().getType() == 1) {\r | |
585 | String execName = execNameInterval.getStateValue().unboxStr();\r | |
586 | long startTime = execNameInterval.getStartTime();\r | |
49ffadb7 PT |
587 | long endTime = execNameInterval.getEndTime() + 1;\r |
588 | if (birthTime == -1) {\r | |
589 | birthTime = startTime;\r | |
590 | }\r | |
04835162 PT |
591 | int ppid = -1;\r |
592 | if (ppidQuark != -1) {\r | |
593 | ITmfStateInterval ppidInterval = ssq.querySingleState(startTime, ppidQuark);\r | |
594 | ppid = ppidInterval.getStateValue().unboxInt();\r | |
595 | }\r | |
49ffadb7 | 596 | ControlFlowEntry entry = new ControlFlowEntry(threadQuark, ctfKernelTrace, execName, threadId, ppid, birthTime, startTime, endTime);\r |
8d8cb868 | 597 | entryList.add(entry);\r |
49ffadb7 PT |
598 | entry.addEvent(new TimeEvent(entry, startTime, endTime - startTime));\r |
599 | } else {\r | |
600 | birthTime = -1;\r | |
04835162 PT |
601 | }\r |
602 | }\r | |
603 | } catch (AttributeNotFoundException e) {\r | |
604 | e.printStackTrace();\r | |
605 | } catch (TimeRangeException e) {\r | |
606 | e.printStackTrace();\r | |
607 | } catch (StateValueTypeException e) {\r | |
608 | e.printStackTrace();\r | |
609 | }\r | |
610 | }\r | |
15c04058 | 611 | buildTree(entryList, rootList);\r |
04835162 | 612 | }\r |
15c04058 | 613 | Collections.sort(rootList, fControlFlowEntryComparator);\r |
c19a8781 PT |
614 | synchronized (fEntryListSyncObj) {\r |
615 | fEntryList = (ArrayList<ControlFlowEntry>) rootList.clone();\r | |
616 | }\r | |
3ac6ad1a | 617 | refresh(INITIAL_WINDOW_OFFSET);\r |
15c04058 PT |
618 | }\r |
619 | for (ControlFlowEntry entry : rootList) {\r | |
620 | buildStatusEvents(entry);\r | |
49ffadb7 PT |
621 | }\r |
622 | }\r | |
623 | \r | |
0a78d11a AM |
624 | private static void buildTree(ArrayList<ControlFlowEntry> entryList,\r |
625 | ArrayList<ControlFlowEntry> rootList) {\r | |
8d8cb868 | 626 | for (ControlFlowEntry entry : entryList) {\r |
49ffadb7 | 627 | boolean root = true;\r |
3d90c4ff | 628 | if (entry.getParentThreadId() > 0) {\r |
8d8cb868 | 629 | for (ControlFlowEntry parent : entryList) {\r |
3d90c4ff | 630 | if (parent.getThreadId() == entry.getParentThreadId() &&\r |
49ffadb7 PT |
631 | entry.getStartTime() >= parent.getStartTime() &&\r |
632 | entry.getStartTime() <= parent.getEndTime()) {\r | |
633 | parent.addChild(entry);\r | |
634 | root = false;\r | |
635 | break;\r | |
636 | }\r | |
637 | }\r | |
638 | }\r | |
639 | if (root) {\r | |
640 | rootList.add(entry);\r | |
641 | }\r | |
04835162 | 642 | }\r |
49ffadb7 PT |
643 | }\r |
644 | \r | |
645 | private void buildStatusEvents(ControlFlowEntry entry) {\r | |
646 | IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r | |
647 | long start = ssq.getStartTime();\r | |
b987050f | 648 | long end = ssq.getCurrentEndTime() + 1;\r |
49ffadb7 | 649 | long resolution = Math.max(1, (end - start) / fDisplayWidth);\r |
0137b624 | 650 | List<ITimeEvent> eventList = getEventList(entry, entry.getStartTime(), entry.getEndTime(), resolution, new NullProgressMonitor());\r |
49ffadb7 PT |
651 | entry.setEventList(eventList);\r |
652 | redraw();\r | |
653 | for (ITimeGraphEntry child : entry.getChildren()) {\r | |
654 | buildStatusEvents((ControlFlowEntry) child);\r | |
655 | }\r | |
656 | }\r | |
657 | \r | |
0a78d11a AM |
658 | private static List<ITimeEvent> getEventList(ControlFlowEntry entry,\r |
659 | long startTime, long endTime, long resolution,\r | |
660 | IProgressMonitor monitor) {\r | |
49ffadb7 PT |
661 | startTime = Math.max(startTime, entry.getStartTime());\r |
662 | endTime = Math.min(endTime, entry.getEndTime());\r | |
663 | if (endTime <= startTime) {\r | |
664 | return null;\r | |
665 | }\r | |
666 | IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r | |
667 | List<ITimeEvent> eventList = null;\r | |
668 | try {\r | |
669 | int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);\r | |
670 | List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution);\r | |
671 | eventList = new ArrayList<ITimeEvent>(statusIntervals.size());\r | |
672 | long lastEndTime = -1;\r | |
673 | for (ITmfStateInterval statusInterval : statusIntervals) {\r | |
0137b624 PT |
674 | if (monitor.isCanceled()) {\r |
675 | return null;\r | |
676 | }\r | |
49ffadb7 PT |
677 | long time = statusInterval.getStartTime();\r |
678 | long duration = statusInterval.getEndTime() - time + 1;\r | |
679 | int status = -1;\r | |
680 | try {\r | |
681 | status = statusInterval.getStateValue().unboxInt();\r | |
682 | } catch (StateValueTypeException e) {\r | |
683 | e.printStackTrace();\r | |
684 | }\r | |
685 | if (lastEndTime != time && lastEndTime != -1) {\r | |
686 | eventList.add(new ControlFlowEvent(entry, lastEndTime, time - lastEndTime, 0));\r | |
687 | }\r | |
688 | eventList.add(new ControlFlowEvent(entry, time, duration, status));\r | |
689 | lastEndTime = time + duration;\r | |
690 | }\r | |
691 | } catch (AttributeNotFoundException e) {\r | |
692 | e.printStackTrace();\r | |
693 | } catch (TimeRangeException e) {\r | |
694 | e.printStackTrace();\r | |
695 | }\r | |
696 | return eventList;\r | |
04835162 PT |
697 | }\r |
698 | \r | |
3ac6ad1a | 699 | private void refresh(final long windowRange) {\r |
04835162 PT |
700 | Display.getDefault().asyncExec(new Runnable() {\r |
701 | @Override\r | |
702 | public void run() {\r | |
703 | if (fTimeGraphCombo.isDisposed()) {\r | |
704 | return;\r | |
705 | }\r | |
c19a8781 PT |
706 | ITimeGraphEntry[] entries = null;\r |
707 | synchronized (fEntryListSyncObj) {\r | |
708 | entries = fEntryList.toArray(new ITimeGraphEntry[0]);\r | |
709 | }\r | |
2c33fc31 | 710 | Arrays.sort(entries, fControlFlowEntryComparator);\r |
04835162 PT |
711 | fTimeGraphCombo.setInput(entries);\r |
712 | fTimeGraphCombo.getTimeGraphViewer().setTimeBounds(fStartTime, fEndTime);\r | |
0137b624 | 713 | \r |
3ac6ad1a BH |
714 | long endTime = fStartTime + windowRange;\r |
715 | \r | |
716 | if (fEndTime < endTime) {\r | |
717 | endTime = fEndTime;\r | |
718 | }\r | |
719 | fTimeGraphCombo.getTimeGraphViewer().setStartFinishTime(fStartTime, endTime);\r | |
49ffadb7 PT |
720 | for (TreeColumn column : fTimeGraphCombo.getTreeViewer().getTree().getColumns()) {\r |
721 | column.pack();\r | |
722 | }\r | |
3ac6ad1a BH |
723 | \r |
724 | startZoomThread(fStartTime, endTime);\r | |
49ffadb7 PT |
725 | }\r |
726 | });\r | |
727 | }\r | |
728 | \r | |
729 | private void redraw() {\r | |
730 | Display.getDefault().asyncExec(new Runnable() {\r | |
731 | @Override\r | |
732 | public void run() {\r | |
733 | if (fTimeGraphCombo.isDisposed()) {\r | |
734 | return;\r | |
735 | }\r | |
736 | fTimeGraphCombo.redraw();\r | |
737 | fTimeGraphCombo.update();\r | |
04835162 PT |
738 | }\r |
739 | });\r | |
740 | }\r | |
741 | \r | |
3ac6ad1a BH |
742 | private void startZoomThread(long startTime, long endTime) {\r |
743 | if (fZoomThread != null) {\r | |
744 | fZoomThread.cancel();\r | |
745 | }\r | |
746 | fZoomThread = new ZoomThread(startTime, endTime);\r | |
747 | fZoomThread.start();\r | |
748 | }\r | |
0137b624 | 749 | \r |
49ffadb7 PT |
750 | private void makeActions() {\r |
751 | fPreviousResourceAction = fTimeGraphCombo.getTimeGraphViewer().getPreviousItemAction();\r | |
752 | fPreviousResourceAction.setText(Messages.ControlFlowView_previousProcessActionNameText);\r | |
753 | fPreviousResourceAction.setToolTipText(Messages.ControlFlowView_previousProcessActionToolTipText);\r | |
754 | fNextResourceAction = fTimeGraphCombo.getTimeGraphViewer().getNextItemAction();\r | |
755 | fNextResourceAction.setText(Messages.ControlFlowView_nextProcessActionNameText);\r | |
756 | fNextResourceAction.setToolTipText(Messages.ControlFlowView_nextProcessActionToolTipText);\r | |
757 | }\r | |
0137b624 | 758 | \r |
49ffadb7 PT |
759 | private void contributeToActionBars() {\r |
760 | IActionBars bars = getViewSite().getActionBars();\r | |
761 | fillLocalToolBar(bars.getToolBarManager());\r | |
762 | }\r | |
763 | \r | |
764 | private void fillLocalToolBar(IToolBarManager manager) {\r | |
765 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getShowLegendAction());\r | |
766 | manager.add(new Separator());\r | |
767 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getResetScaleAction());\r | |
768 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getPreviousEventAction());\r | |
769 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getNextEventAction());\r | |
770 | manager.add(fPreviousResourceAction);\r | |
771 | manager.add(fNextResourceAction);\r | |
772 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomInAction());\r | |
773 | manager.add(fTimeGraphCombo.getTimeGraphViewer().getZoomOutAction());\r | |
774 | manager.add(new Separator());\r | |
775 | }\r | |
04835162 | 776 | }\r |