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.resources;\r | |
14 | \r | |
15 | import java.util.ArrayList;\r | |
49ffadb7 | 16 | import java.util.Arrays;\r |
2c33fc31 | 17 | import java.util.Comparator;\r |
04835162 PT |
18 | import java.util.Iterator;\r |
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 | |
3e97fbfa | 26 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r |
49ffadb7 PT |
27 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r |
28 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;\r | |
04835162 | 29 | import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace;\r |
49ffadb7 | 30 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;\r |
04835162 PT |
31 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r |
32 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r | |
49ffadb7 PT |
33 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;\r |
34 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r | |
04835162 PT |
35 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r |
36 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r | |
37 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r | |
04835162 PT |
38 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r |
39 | import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;\r | |
49ffadb7 | 40 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;\r |
04835162 | 41 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r |
b987050f | 42 | import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;\r |
49ffadb7 | 43 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;\r |
04835162 | 44 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r |
5793c495 | 45 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier2;\r |
04835162 | 46 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r |
9e0640dc | 47 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;\r |
04835162 | 48 | import org.eclipse.linuxtools.tmf.ui.views.TmfView;\r |
49ffadb7 PT |
49 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener;\r |
50 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;\r | |
49ffadb7 PT |
51 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent;\r |
52 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;\r | |
04835162 PT |
53 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer;\r |
54 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r | |
55 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r | |
56 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;\r | |
57 | import org.eclipse.swt.SWT;\r | |
58 | import org.eclipse.swt.widgets.Composite;\r | |
59 | import org.eclipse.swt.widgets.Display;\r | |
49ffadb7 | 60 | import org.eclipse.ui.IActionBars;\r |
04835162 | 61 | \r |
27f3a03d AM |
62 | /**\r |
63 | * Main implementation for the LTTng 2.0 kernel Resource view\r | |
64 | *\r | |
65 | * @author Patrick Tasse\r | |
66 | */\r | |
04835162 PT |
67 | public class ResourcesView extends TmfView {\r |
68 | \r | |
69 | // ------------------------------------------------------------------------\r | |
70 | // Constants\r | |
71 | // ------------------------------------------------------------------------\r | |
72 | \r | |
27f3a03d | 73 | /** View ID. */\r |
04835162 PT |
74 | public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$\r |
75 | \r | |
27f3a03d | 76 | /** Initial time range */\r |
3ac6ad1a | 77 | private static final long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec\r |
0137b624 | 78 | \r |
03bcc394 PT |
79 | /**\r |
80 | * Redraw state enum\r | |
81 | */\r | |
ea21cd65 | 82 | private enum State { IDLE, BUSY, PENDING }\r |
03bcc394 | 83 | \r |
04835162 PT |
84 | // ------------------------------------------------------------------------\r |
85 | // Fields\r | |
86 | // ------------------------------------------------------------------------\r | |
87 | \r | |
88 | // The time graph viewer\r | |
89 | TimeGraphViewer fTimeGraphViewer;\r | |
90 | \r | |
91 | // The selected experiment\r | |
92 | private TmfExperiment<ITmfEvent> fSelectedExperiment;\r | |
93 | \r | |
94 | // The time graph entry list\r | |
49ffadb7 | 95 | private ArrayList<TraceEntry> fEntryList;\r |
04835162 | 96 | \r |
c19a8781 PT |
97 | // The time graph entry list synchronization object\r |
98 | final private Object fEntryListSyncObj = new Object();\r | |
99 | \r | |
04835162 PT |
100 | // The start time\r |
101 | private long fStartTime;\r | |
102 | \r | |
103 | // The end time\r | |
104 | private long fEndTime;\r | |
105 | \r | |
106 | // The display width\r | |
27f3a03d | 107 | private final int fDisplayWidth;\r |
0137b624 | 108 | \r |
49ffadb7 PT |
109 | // The next resource action\r |
110 | private Action fNextResourceAction;\r | |
0137b624 | 111 | \r |
49ffadb7 PT |
112 | // The previous resource action\r |
113 | private Action fPreviousResourceAction;\r | |
114 | \r | |
49ffadb7 PT |
115 | // The zoom thread\r |
116 | private ZoomThread fZoomThread;\r | |
04835162 | 117 | \r |
03bcc394 PT |
118 | // The redraw state used to prevent unnecessary queuing of display runnables\r |
119 | private State fRedrawState = State.IDLE;\r | |
120 | \r | |
121 | // The redraw synchronization object\r | |
122 | final private Object fSyncObj = new Object();\r | |
123 | \r | |
04835162 PT |
124 | // ------------------------------------------------------------------------\r |
125 | // Classes\r | |
126 | // ------------------------------------------------------------------------\r | |
127 | \r | |
49ffadb7 | 128 | private class TraceEntry implements ITimeGraphEntry {\r |
2c33fc31 | 129 | // The Trace\r |
27f3a03d | 130 | private final CtfKernelTrace fTrace;\r |
2c33fc31 | 131 | // The start time\r |
27f3a03d | 132 | private final long fTraceStartTime;\r |
2c33fc31 | 133 | // The end time\r |
27f3a03d | 134 | private final long fTraceEndTime;\r |
2c33fc31 | 135 | // The children of the entry\r |
27f3a03d | 136 | private final ArrayList<ResourcesEntry> fChildren;\r |
2c33fc31 | 137 | // The name of entry\r |
27f3a03d | 138 | private final String fName;\r |
2c33fc31 BH |
139 | \r |
140 | public TraceEntry(CtfKernelTrace trace, String name, long startTime, long endTime) {\r | |
49ffadb7 PT |
141 | fTrace = trace;\r |
142 | fChildren = new ArrayList<ResourcesEntry>();\r | |
04835162 | 143 | fName = name;\r |
2c33fc31 BH |
144 | fTraceStartTime = startTime;\r |
145 | fTraceEndTime = endTime;\r | |
04835162 PT |
146 | }\r |
147 | \r | |
148 | @Override\r | |
149 | public ITimeGraphEntry getParent() {\r | |
49ffadb7 | 150 | return null;\r |
04835162 PT |
151 | }\r |
152 | \r | |
153 | @Override\r | |
154 | public boolean hasChildren() {\r | |
155 | return fChildren != null && fChildren.size() > 0;\r | |
156 | }\r | |
157 | \r | |
158 | @Override\r | |
49ffadb7 PT |
159 | public ResourcesEntry[] getChildren() {\r |
160 | return fChildren.toArray(new ResourcesEntry[0]);\r | |
04835162 PT |
161 | }\r |
162 | \r | |
163 | @Override\r | |
164 | public String getName() {\r | |
165 | return fName;\r | |
166 | }\r | |
167 | \r | |
168 | @Override\r | |
169 | public long getStartTime() {\r | |
2c33fc31 | 170 | return fTraceStartTime;\r |
04835162 PT |
171 | }\r |
172 | \r | |
173 | @Override\r | |
49ffadb7 | 174 | public long getEndTime() {\r |
2c33fc31 | 175 | return fTraceEndTime;\r |
04835162 PT |
176 | }\r |
177 | \r | |
8d8cb868 PT |
178 | @Override\r |
179 | public boolean hasTimeEvents() {\r | |
180 | return false;\r | |
181 | }\r | |
182 | \r | |
04835162 PT |
183 | @Override\r |
184 | public Iterator<ITimeEvent> getTimeEventsIterator() {\r | |
185 | return null;\r | |
186 | }\r | |
187 | \r | |
188 | @Override\r | |
189 | public <T extends ITimeEvent> Iterator<T> getTimeEventsIterator(long startTime, long stopTime, long visibleDuration) {\r | |
190 | return null;\r | |
191 | }\r | |
192 | \r | |
49ffadb7 PT |
193 | public CtfKernelTrace getTrace() {\r |
194 | return fTrace;\r | |
195 | }\r | |
196 | \r | |
197 | public void addChild(ResourcesEntry entry) {\r | |
198 | int index;\r | |
199 | for (index = 0; index < fChildren.size(); index++) {\r | |
200 | ResourcesEntry other = fChildren.get(index);\r | |
201 | if (entry.getType().compareTo(other.getType()) < 0) {\r | |
202 | break;\r | |
203 | } else if (entry.getType().equals(other.getType())) {\r | |
204 | if (entry.getId() < other.getId()) {\r | |
205 | break;\r | |
206 | }\r | |
207 | }\r | |
208 | }\r | |
209 | entry.setParent(this);\r | |
210 | fChildren.add(index, entry);\r | |
211 | }\r | |
212 | }\r | |
27f3a03d | 213 | \r |
2c33fc31 BH |
214 | private static class TraceEntryComparator implements Comparator<ITimeGraphEntry> {\r |
215 | @Override\r | |
216 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {\r | |
217 | int result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;\r | |
218 | if (result == 0) {\r | |
219 | result = o1.getName().compareTo(o2.getName());\r | |
220 | }\r | |
221 | return result;\r | |
222 | }\r | |
223 | }\r | |
49ffadb7 PT |
224 | \r |
225 | private class ZoomThread extends Thread {\r | |
27f3a03d AM |
226 | private final long fZoomStartTime;\r |
227 | private final long fZoomEndTime;\r | |
228 | private final IProgressMonitor fMonitor;\r | |
49ffadb7 PT |
229 | \r |
230 | public ZoomThread(long startTime, long endTime) {\r | |
231 | super("ResourcesView zoom"); //$NON-NLS-1$\r | |
3ac6ad1a BH |
232 | fZoomStartTime = startTime;\r |
233 | fZoomEndTime = endTime;\r | |
0137b624 | 234 | fMonitor = new NullProgressMonitor();\r |
49ffadb7 PT |
235 | }\r |
236 | \r | |
237 | @Override\r | |
238 | public void run() {\r | |
c19a8781 PT |
239 | ArrayList<TraceEntry> entryList = null;\r |
240 | synchronized (fEntryListSyncObj) {\r | |
241 | entryList = fEntryList;\r | |
242 | }\r | |
8d8cb868 | 243 | if (entryList == null) {\r |
49ffadb7 PT |
244 | return;\r |
245 | }\r | |
3ac6ad1a | 246 | long resolution = Math.max(1, (fZoomEndTime - fZoomStartTime) / fDisplayWidth);\r |
8d8cb868 | 247 | for (TraceEntry traceEntry : entryList) {\r |
49ffadb7 | 248 | for (ITimeGraphEntry child : traceEntry.getChildren()) {\r |
0137b624 PT |
249 | if (fMonitor.isCanceled()) {\r |
250 | break;\r | |
251 | }\r | |
5929fada PT |
252 | ResourcesEntry entry = (ResourcesEntry) child;\r |
253 | if (fZoomStartTime <= fStartTime && fZoomEndTime >= fEndTime) {\r | |
254 | entry.setZoomedEventList(null);\r | |
255 | } else {\r | |
256 | List<ITimeEvent> zoomedEventList = getEventList(entry, fZoomStartTime, fZoomEndTime, resolution, true, fMonitor);\r | |
27f3a03d | 257 | if (zoomedEventList != null) {\r |
5929fada PT |
258 | entry.setZoomedEventList(zoomedEventList);\r |
259 | }\r | |
49ffadb7 | 260 | }\r |
03bcc394 | 261 | redraw();\r |
49ffadb7 PT |
262 | }\r |
263 | }\r | |
264 | }\r | |
265 | \r | |
266 | public void cancel() {\r | |
0137b624 | 267 | fMonitor.setCanceled(true);\r |
04835162 PT |
268 | }\r |
269 | }\r | |
270 | \r | |
271 | // ------------------------------------------------------------------------\r | |
272 | // Constructors\r | |
273 | // ------------------------------------------------------------------------\r | |
274 | \r | |
27f3a03d AM |
275 | /**\r |
276 | * Default constructor\r | |
277 | */\r | |
04835162 PT |
278 | public ResourcesView() {\r |
279 | super(ID);\r | |
280 | fDisplayWidth = Display.getDefault().getBounds().width;\r | |
281 | }\r | |
282 | \r | |
283 | // ------------------------------------------------------------------------\r | |
284 | // ViewPart\r | |
285 | // ------------------------------------------------------------------------\r | |
286 | \r | |
287 | /* (non-Javadoc)\r | |
288 | * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)\r | |
289 | */\r | |
290 | @Override\r | |
291 | public void createPartControl(Composite parent) {\r | |
292 | fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);\r | |
293 | \r | |
72b5abb1 | 294 | fTimeGraphViewer.setTimeGraphProvider(new ResourcesPresentationProvider());\r |
49ffadb7 PT |
295 | \r |
296 | fTimeGraphViewer.setTimeCalendarFormat(true);\r | |
297 | \r | |
298 | fTimeGraphViewer.addRangeListener(new ITimeGraphRangeListener() {\r | |
299 | @Override\r | |
300 | public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) {\r | |
301 | long startTime = event.getStartTime();\r | |
302 | long endTime = event.getEndTime();\r | |
303 | TmfTimeRange range = new TmfTimeRange(new CtfTmfTimestamp(startTime), new CtfTmfTimestamp(endTime));\r | |
304 | TmfTimestamp time = new CtfTmfTimestamp(fTimeGraphViewer.getSelectedTime());\r | |
305 | broadcast(new TmfRangeSynchSignal(ResourcesView.this, range, time));\r | |
3ac6ad1a | 306 | startZoomThread(startTime, endTime);\r |
04835162 PT |
307 | }\r |
308 | });\r | |
309 | \r | |
49ffadb7 PT |
310 | fTimeGraphViewer.addTimeListener(new ITimeGraphTimeListener() {\r |
311 | @Override\r | |
312 | public void timeSelected(TimeGraphTimeEvent event) {\r | |
313 | long time = event.getTime();\r | |
314 | broadcast(new TmfTimeSynchSignal(ResourcesView.this, new CtfTmfTimestamp(time)));\r | |
315 | }\r | |
316 | });\r | |
317 | \r | |
318 | final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r | |
04835162 PT |
319 | @Override\r |
320 | public void run() {\r | |
321 | if (TmfExperiment.getCurrentExperiment() != null) {\r | |
322 | selectExperiment(TmfExperiment.getCurrentExperiment());\r | |
323 | }\r | |
324 | }\r | |
325 | };\r | |
326 | thread.start();\r | |
0137b624 | 327 | \r |
49ffadb7 PT |
328 | // View Action Handling\r |
329 | makeActions();\r | |
330 | contributeToActionBars();\r | |
04835162 PT |
331 | }\r |
332 | \r | |
333 | /* (non-Javadoc)\r | |
334 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r | |
335 | */\r | |
336 | @Override\r | |
337 | public void setFocus() {\r | |
338 | fTimeGraphViewer.setFocus();\r | |
339 | }\r | |
340 | \r | |
341 | // ------------------------------------------------------------------------\r | |
342 | // Signal handlers\r | |
343 | // ------------------------------------------------------------------------\r | |
344 | \r | |
27f3a03d AM |
345 | /**\r |
346 | * Handler for the ExperimentSelected signal\r | |
347 | *\r | |
348 | * @param signal\r | |
349 | * The incoming signal\r | |
350 | */\r | |
04835162 PT |
351 | @TmfSignalHandler\r |
352 | public void experimentSelected(final TmfExperimentSelectedSignal<? extends TmfEvent> signal) {\r | |
353 | if (signal.getExperiment().equals(fSelectedExperiment)) {\r | |
354 | return;\r | |
355 | }\r | |
356 | \r | |
49ffadb7 | 357 | final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r |
04835162 PT |
358 | @Override\r |
359 | public void run() {\r | |
360 | selectExperiment(signal.getExperiment());\r | |
0137b624 PT |
361 | }\r |
362 | };\r | |
04835162 PT |
363 | thread.start();\r |
364 | }\r | |
365 | \r | |
27f3a03d AM |
366 | /**\r |
367 | * Handler for the TimeSynch signal\r | |
368 | *\r | |
369 | * @param signal\r | |
370 | * The incoming signal\r | |
371 | */\r | |
49ffadb7 PT |
372 | @TmfSignalHandler\r |
373 | public void synchToTime(final TmfTimeSynchSignal signal) {\r | |
8a74a597 | 374 | if (signal.getSource() == this || fSelectedExperiment == null) {\r |
49ffadb7 PT |
375 | return;\r |
376 | }\r | |
377 | final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r | |
378 | Display.getDefault().asyncExec(new Runnable() {\r | |
379 | @Override\r | |
380 | public void run() {\r | |
381 | if (fTimeGraphViewer.getControl().isDisposed()) {\r | |
382 | return;\r | |
383 | }\r | |
3ac6ad1a | 384 | fTimeGraphViewer.setSelectedTime(time, true);\r |
7264b6f2 | 385 | startZoomThread(fTimeGraphViewer.getTime0(), fTimeGraphViewer.getTime1());\r |
49ffadb7 PT |
386 | }\r |
387 | });\r | |
388 | }\r | |
389 | \r | |
27f3a03d AM |
390 | /**\r |
391 | * Handler for the RangeSynch signal\r | |
392 | *\r | |
393 | * @param signal\r | |
394 | * The incoming signal\r | |
395 | */\r | |
49ffadb7 PT |
396 | @TmfSignalHandler\r |
397 | public void synchToRange(final TmfRangeSynchSignal signal) {\r | |
8a74a597 | 398 | if (signal.getSource() == this || fSelectedExperiment == null) {\r |
49ffadb7 PT |
399 | return;\r |
400 | }\r | |
401 | final long startTime = signal.getCurrentRange().getStartTime().normalize(0, -9).getValue();\r | |
402 | final long endTime = signal.getCurrentRange().getEndTime().normalize(0, -9).getValue();\r | |
403 | final long time = signal.getCurrentTime().normalize(0, -9).getValue();\r | |
404 | Display.getDefault().asyncExec(new Runnable() {\r | |
405 | @Override\r | |
406 | public void run() {\r | |
407 | if (fTimeGraphViewer.getControl().isDisposed()) {\r | |
408 | return;\r | |
409 | }\r | |
410 | fTimeGraphViewer.setStartFinishTime(startTime, endTime);\r | |
8d8cb868 | 411 | fTimeGraphViewer.setSelectedTime(time, false);\r |
3ac6ad1a | 412 | startZoomThread(startTime, endTime);\r |
49ffadb7 PT |
413 | }\r |
414 | });\r | |
415 | }\r | |
416 | \r | |
27f3a03d AM |
417 | /**\r |
418 | * Handler for the StatesystemBuildCompleted signal\r | |
419 | *\r | |
420 | * @param signal\r | |
421 | * The incoming signal\r | |
422 | */\r | |
b987050f PT |
423 | @TmfSignalHandler\r |
424 | public void stateSystemBuildCompleted (final TmfStateSystemBuildCompleted signal) {\r | |
425 | final TmfExperiment<?> selectedExperiment = fSelectedExperiment;\r | |
04aafb31 | 426 | if (selectedExperiment == null || selectedExperiment.getTraces() == null) {\r |
b987050f PT |
427 | return;\r |
428 | }\r | |
429 | for (ITmfTrace<?> trace : selectedExperiment.getTraces()) {\r | |
430 | if (trace == signal.getTrace() && trace instanceof CtfKernelTrace) {\r | |
431 | final Thread thread = new Thread("ResourcesView build") { //$NON-NLS-1$\r | |
432 | @Override\r | |
433 | public void run() {\r | |
434 | // rebuild the model\r | |
435 | selectExperiment(selectedExperiment);\r | |
436 | }\r | |
437 | };\r | |
438 | thread.start();\r | |
439 | }\r | |
440 | }\r | |
441 | }\r | |
442 | \r | |
49ffadb7 PT |
443 | // ------------------------------------------------------------------------\r |
444 | // Internal\r | |
445 | // ------------------------------------------------------------------------\r | |
446 | \r | |
04835162 PT |
447 | @SuppressWarnings("unchecked")\r |
448 | private void selectExperiment(TmfExperiment<?> experiment) {\r | |
449 | fStartTime = Long.MAX_VALUE;\r | |
450 | fEndTime = Long.MIN_VALUE;\r | |
451 | fSelectedExperiment = (TmfExperiment<ITmfEvent>) experiment;\r | |
8d8cb868 | 452 | ArrayList<TraceEntry> entryList = new ArrayList<TraceEntry>();\r |
04835162 | 453 | for (ITmfTrace<?> trace : experiment.getTraces()) {\r |
04835162 PT |
454 | if (trace instanceof CtfKernelTrace) {\r |
455 | CtfKernelTrace ctfKernelTrace = (CtfKernelTrace) trace;\r | |
456 | IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r | |
49ffadb7 PT |
457 | long startTime = ssq.getStartTime();\r |
458 | long endTime = ssq.getCurrentEndTime() + 1;\r | |
2c33fc31 BH |
459 | TraceEntry groupEntry = new TraceEntry(ctfKernelTrace, trace.getName(), startTime, endTime);\r |
460 | entryList.add(groupEntry);\r | |
49ffadb7 PT |
461 | fStartTime = Math.min(fStartTime, startTime);\r |
462 | fEndTime = Math.max(fEndTime, endTime);\r | |
04835162 | 463 | List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$\r |
49ffadb7 PT |
464 | ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];\r |
465 | for (int i = 0; i < cpuQuarks.size(); i++) {\r | |
466 | int cpuQuark = cpuQuarks.get(i);\r | |
467 | int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));\r | |
468 | ResourcesEntry entry = new ResourcesEntry(cpuQuark, ctfKernelTrace, Type.CPU, cpu);\r | |
469 | groupEntry.addChild(entry);\r | |
470 | cpuEntries[i] = entry;\r | |
471 | }\r | |
472 | List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$\r | |
473 | ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];\r | |
474 | for (int i = 0; i < irqQuarks.size(); i++) {\r | |
475 | int irqQuark = irqQuarks.get(i);\r | |
476 | int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));\r | |
477 | ResourcesEntry entry = new ResourcesEntry(irqQuark, ctfKernelTrace, Type.IRQ, irq);\r | |
478 | groupEntry.addChild(entry);\r | |
479 | irqEntries[i] = entry;\r | |
480 | }\r | |
481 | List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$\r | |
482 | ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];\r | |
483 | for (int i = 0; i < softIrqQuarks.size(); i++) {\r | |
484 | int softIrqQuark = softIrqQuarks.get(i);\r | |
485 | int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));\r | |
486 | ResourcesEntry entry = new ResourcesEntry(softIrqQuark, ctfKernelTrace, Type.SOFT_IRQ, softIrq);\r | |
487 | groupEntry.addChild(entry);\r | |
488 | softIrqEntries[i] = entry;\r | |
489 | }\r | |
490 | }\r | |
491 | }\r | |
c19a8781 PT |
492 | synchronized (fEntryListSyncObj) {\r |
493 | fEntryList = (ArrayList<TraceEntry>) entryList.clone();\r | |
494 | }\r | |
3ac6ad1a | 495 | refresh(INITIAL_WINDOW_OFFSET);\r |
c19a8781 | 496 | for (TraceEntry traceEntry : entryList) {\r |
0a78d11a | 497 | CtfKernelTrace ctfKernelTrace = traceEntry.getTrace();\r |
49ffadb7 PT |
498 | IStateSystemQuerier ssq = ctfKernelTrace.getStateSystem();\r |
499 | long startTime = ssq.getStartTime();\r | |
500 | long endTime = ssq.getCurrentEndTime() + 1;\r | |
501 | long resolution = (endTime - startTime) / fDisplayWidth;\r | |
502 | for (ResourcesEntry entry : traceEntry.getChildren()) {\r | |
0137b624 | 503 | List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, false, new NullProgressMonitor());\r |
49ffadb7 PT |
504 | entry.setEventList(eventList);\r |
505 | redraw();\r | |
506 | }\r | |
507 | }\r | |
508 | }\r | |
509 | \r | |
0a78d11a AM |
510 | private static List<ITimeEvent> getEventList(ResourcesEntry entry,\r |
511 | long startTime, long endTime, long resolution, boolean includeNull,\r | |
512 | IProgressMonitor monitor) {\r | |
5793c495 | 513 | IStateSystemQuerier2 ssq = (IStateSystemQuerier2) entry.getTrace().getStateSystem();\r |
7264b6f2 PT |
514 | startTime = Math.max(startTime, ssq.getStartTime());\r |
515 | endTime = Math.min(endTime, ssq.getCurrentEndTime() + 1);\r | |
0137b624 PT |
516 | if (endTime <= startTime) {\r |
517 | return null;\r | |
518 | }\r | |
49ffadb7 PT |
519 | List<ITimeEvent> eventList = null;\r |
520 | int quark = entry.getQuark();\r | |
521 | try {\r | |
522 | if (entry.getType().equals(Type.CPU)) {\r | |
72b5abb1 | 523 | int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);\r |
03bcc394 | 524 | List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);\r |
72b5abb1 | 525 | eventList = new ArrayList<ITimeEvent>(statusIntervals.size());\r |
49ffadb7 | 526 | long lastEndTime = -1;\r |
72b5abb1 | 527 | for (ITmfStateInterval statusInterval : statusIntervals) {\r |
0137b624 PT |
528 | if (monitor.isCanceled()) {\r |
529 | return null;\r | |
530 | }\r | |
72b5abb1 PT |
531 | int status = statusInterval.getStateValue().unboxInt();\r |
532 | long time = statusInterval.getStartTime();\r | |
533 | long duration = statusInterval.getEndTime() - time + 1;\r | |
534 | if (!statusInterval.getStateValue().isNull()) {\r | |
49ffadb7 PT |
535 | if (lastEndTime != time && lastEndTime != -1) {\r |
536 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));\r | |
cf7d106f | 537 | }\r |
72b5abb1 | 538 | eventList.add(new ResourcesEvent(entry, time, duration, status));\r |
49ffadb7 | 539 | lastEndTime = time + duration;\r |
72b5abb1 PT |
540 | } else {\r |
541 | if (includeNull) {\r | |
542 | eventList.add(new ResourcesEvent(entry, time, duration));\r | |
543 | }\r | |
cf7d106f | 544 | }\r |
49ffadb7 PT |
545 | }\r |
546 | } else if (entry.getType().equals(Type.IRQ)) {\r | |
03bcc394 | 547 | List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);\r |
49ffadb7 PT |
548 | eventList = new ArrayList<ITimeEvent>(irqIntervals.size());\r |
549 | long lastEndTime = -1;\r | |
550 | boolean lastIsNull = true;\r | |
551 | for (ITmfStateInterval irqInterval : irqIntervals) {\r | |
0137b624 PT |
552 | if (monitor.isCanceled()) {\r |
553 | return null;\r | |
554 | }\r | |
49ffadb7 PT |
555 | long time = irqInterval.getStartTime();\r |
556 | long duration = irqInterval.getEndTime() - time + 1;\r | |
557 | if (!irqInterval.getStateValue().isNull()) {\r | |
558 | int cpu = irqInterval.getStateValue().unboxInt();\r | |
559 | eventList.add(new ResourcesEvent(entry, time, duration, cpu));\r | |
560 | lastIsNull = false;\r | |
561 | } else {\r | |
562 | if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {\r | |
563 | eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));\r | |
564 | }\r | |
565 | if (includeNull) {\r | |
566 | eventList.add(new ResourcesEvent(entry, time, duration));\r | |
567 | }\r | |
568 | lastIsNull = true;\r | |
569 | }\r | |
570 | lastEndTime = time + duration;\r | |
571 | }\r | |
572 | } else if (entry.getType().equals(Type.SOFT_IRQ)) {\r | |
03bcc394 | 573 | List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);\r |
49ffadb7 PT |
574 | eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());\r |
575 | long lastEndTime = -1;\r | |
576 | boolean lastIsNull = true;\r | |
577 | for (ITmfStateInterval softIrqInterval : softIrqIntervals) {\r | |
0137b624 PT |
578 | if (monitor.isCanceled()) {\r |
579 | return null;\r | |
580 | }\r | |
49ffadb7 PT |
581 | long time = softIrqInterval.getStartTime();\r |
582 | long duration = softIrqInterval.getEndTime() - time + 1;\r | |
583 | if (!softIrqInterval.getStateValue().isNull()) {\r | |
584 | int cpu = softIrqInterval.getStateValue().unboxInt();\r | |
585 | eventList.add(new ResourcesEvent(entry, time, duration, cpu));\r | |
586 | } else {\r | |
587 | if (lastEndTime != time && lastEndTime != -1 && lastIsNull) {\r | |
588 | eventList.add(new ResourcesEvent(entry, lastEndTime, time - lastEndTime, -1));\r | |
589 | }\r | |
590 | if (includeNull) {\r | |
591 | eventList.add(new ResourcesEvent(entry, time, duration));\r | |
592 | }\r | |
593 | lastIsNull = true;\r | |
594 | }\r | |
595 | lastEndTime = time + duration;\r | |
04835162 PT |
596 | }\r |
597 | }\r | |
49ffadb7 PT |
598 | } catch (AttributeNotFoundException e) {\r |
599 | e.printStackTrace();\r | |
600 | } catch (TimeRangeException e) {\r | |
601 | e.printStackTrace();\r | |
602 | } catch (StateValueTypeException e) {\r | |
603 | e.printStackTrace();\r | |
04835162 | 604 | }\r |
49ffadb7 | 605 | return eventList;\r |
04835162 PT |
606 | }\r |
607 | \r | |
3ac6ad1a | 608 | private void refresh(final long windowRange) {\r |
04835162 PT |
609 | Display.getDefault().asyncExec(new Runnable() {\r |
610 | @Override\r | |
611 | public void run() {\r | |
612 | if (fTimeGraphViewer.getControl().isDisposed()) {\r | |
613 | return;\r | |
614 | }\r | |
c19a8781 PT |
615 | ITimeGraphEntry[] entries = null;\r |
616 | synchronized (fEntryListSyncObj) {\r | |
617 | entries = fEntryList.toArray(new ITimeGraphEntry[0]);\r | |
618 | }\r | |
2c33fc31 | 619 | Arrays.sort(entries, new TraceEntryComparator());\r |
49ffadb7 | 620 | fTimeGraphViewer.setInput(entries);\r |
04835162 | 621 | fTimeGraphViewer.setTimeBounds(fStartTime, fEndTime);\r |
0137b624 | 622 | \r |
3ac6ad1a BH |
623 | long endTime = fStartTime + windowRange;\r |
624 | \r | |
625 | if (fEndTime < endTime) {\r | |
626 | endTime = fEndTime;\r | |
627 | }\r | |
628 | fTimeGraphViewer.setStartFinishTime(fStartTime, endTime);\r | |
0137b624 | 629 | \r |
3ac6ad1a | 630 | startZoomThread(fStartTime, endTime);\r |
04835162 PT |
631 | }\r |
632 | });\r | |
633 | }\r | |
634 | \r | |
49ffadb7 PT |
635 | \r |
636 | private void redraw() {\r | |
03bcc394 PT |
637 | synchronized (fSyncObj) {\r |
638 | if (fRedrawState == State.IDLE) {\r | |
639 | fRedrawState = State.BUSY;\r | |
640 | } else {\r | |
641 | fRedrawState = State.PENDING;\r | |
642 | return;\r | |
643 | }\r | |
644 | }\r | |
49ffadb7 PT |
645 | Display.getDefault().asyncExec(new Runnable() {\r |
646 | @Override\r | |
647 | public void run() {\r | |
648 | if (fTimeGraphViewer.getControl().isDisposed()) {\r | |
649 | return;\r | |
650 | }\r | |
651 | fTimeGraphViewer.getControl().redraw();\r | |
652 | fTimeGraphViewer.getControl().update();\r | |
03bcc394 PT |
653 | synchronized (fSyncObj) {\r |
654 | if (fRedrawState == State.PENDING) {\r | |
655 | fRedrawState = State.IDLE;\r | |
656 | redraw();\r | |
657 | } else {\r | |
658 | fRedrawState = State.IDLE;\r | |
659 | }\r | |
660 | }\r | |
49ffadb7 PT |
661 | }\r |
662 | });\r | |
663 | }\r | |
664 | \r | |
3ac6ad1a BH |
665 | private void startZoomThread(long startTime, long endTime) {\r |
666 | if (fZoomThread != null) {\r | |
667 | fZoomThread.cancel();\r | |
668 | }\r | |
669 | fZoomThread = new ZoomThread(startTime, endTime);\r | |
670 | fZoomThread.start();\r | |
671 | }\r | |
0137b624 | 672 | \r |
49ffadb7 PT |
673 | private void makeActions() {\r |
674 | fPreviousResourceAction = fTimeGraphViewer.getPreviousItemAction();\r | |
675 | fPreviousResourceAction.setText(Messages.ResourcesView_previousResourceActionNameText);\r | |
676 | fPreviousResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);\r | |
677 | fNextResourceAction = fTimeGraphViewer.getNextItemAction();\r | |
678 | fNextResourceAction.setText(Messages.ResourcesView_nextResourceActionNameText);\r | |
679 | fNextResourceAction.setToolTipText(Messages.ResourcesView_previousResourceActionToolTipText);\r | |
680 | }\r | |
0137b624 | 681 | \r |
49ffadb7 PT |
682 | private void contributeToActionBars() {\r |
683 | IActionBars bars = getViewSite().getActionBars();\r | |
684 | fillLocalToolBar(bars.getToolBarManager());\r | |
685 | }\r | |
0137b624 | 686 | \r |
49ffadb7 PT |
687 | private void fillLocalToolBar(IToolBarManager manager) {\r |
688 | manager.add(fTimeGraphViewer.getShowLegendAction());\r | |
689 | manager.add(new Separator());\r | |
690 | manager.add(fTimeGraphViewer.getResetScaleAction());\r | |
691 | manager.add(fTimeGraphViewer.getPreviousEventAction());\r | |
692 | manager.add(fTimeGraphViewer.getNextEventAction());\r | |
693 | manager.add(fPreviousResourceAction);\r | |
694 | manager.add(fNextResourceAction);\r | |
695 | manager.add(fTimeGraphViewer.getZoomInAction());\r | |
696 | manager.add(fTimeGraphViewer.getZoomOutAction());\r | |
697 | manager.add(new Separator());\r | |
698 | }\r | |
04835162 | 699 | }\r |