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