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