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