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