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