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